How to secure RESTful interface in JBoss AS 7 - ejb

After successfully migrating my RESTful application to JBoss AS7, I would like to re-enable authentication (I used BASIC auth over SSL). It seems that this is now possible without writing XML configuration, just by using annotations.
Unfortunately, I cannot find which maven dependency I need to use to import the #WebService and #SecurityContext annotations.
Or is this completely going the wrong way? Is there a working example somewhere?
Thanks for your help!

#javax.jws.WebService is part of JDK
you might also need:
org.jboss.ws.api.annotation.WebContext;
that has option to configure authMethod #WebContext(authMethod=AuthMethod.BASIC) and is part of
<dependency>
<groupId>org.jboss.ws</groupId>
<artifactId>jbossws-api</artifactId>
<version>1.0.0.GA</version>
</dependency>

Related

I want to use CDI with Java SE 12, but start up failes (Main Class, JBoss or Payara, all the same error)

I got completely stuck. I want to use CDI2 with Servlets to write a simple web app. However, the beans not get loaded.
I get the following error in JBoss or Payara or Weld (if running as Main Application):
WELD-001524: Unable to load proxy class for bean Managed Bean [class MyBean] with qualifiers [#Any #Default]
Does anyone still use CDI2 or has a running modern example?
I compile with maven.
warm regards,
Alex
I found it out myself. I had the wrong dependencies. I got confused because of Jakarta. I used the CDI-2 maven dependency. So I updated to Jakarta. Right? This is the way to go, right?
I can deploy. Payara-Micro works. JBoss (WildFly should do the same)
However, Payara Micro does not get track of the URL patterns of simple Servlets, although still, one can call it over the client. (Intellij has a CDI tab, gives a nice overview itself)
...
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>

can we deploy wiremock code in jboss server

I am trying to mock the objects returning from the server to the client. So I need to deploy my Wiremock Code in Server. So is this possible or is there any other way to achieve this scenario?
And I am completely new to Wiremock. So How can I run this on JBoss?
I followed the method of running wiremock-standalone jar and I am able to capture my request and response.
But my main question is, can I able to get mock responses from #Test methods?
You could use Arquillian to test JBoss. You can test microservices using this approach and use Jboss Forge ~ another tool, to speed up the testing/dev. The start guide with Forge is here.
You will just need to add on the pom.xml the dependency for Arquillian:
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR9</version>
<scope>test</scope>
</dependency>
To avoid any library clash you can use the standalone version of WireMock. I used it with wildly (JBoss AS) adding the following dependency:
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<version>2.27.2</version>
<scope>test</scope>
</dependency>
For further information see http://wiremock.org/docs/download-and-installation/
What you've done with wiremock-standalone is very similar to what arquillian does in an integration test. You write your server code then you test it inside a container using a client extension.
Try reading the documentation at http://arquillian.org/arquillian-core/

Spark UI appears with wrong format (broken CSS)

I am using Apache Spark for the first time. I run my application and when I access localhost:4040 I get what is shown in the picture.
I found that maybe setting
spark.ui.enabled true
could help but I don't know how to do that.
Thanks in advance.
I have faced the same issue while using Spark on Google Cloud Dataproc.
If you will access Spark Job UI not through 4040 port directly, but through YARN Web UI (8088 port) you will see correctly rendered web pages.
To workaround this issue when accessing Spark UI directly through 4040 port you need to reset spark.ui.proxyBase property inside your Spark job (not in CLI/job submission command), because it gets overridden by Spark UI proxy:
sys.props.update("spark.ui.proxyBase", "")
Here is detailed description of this issue.
I Had the same problem.
Also the calls to http://localhost:4040/api/v1/applications failed returning with no response.
This happened due to a collision between 2 versions of Jersey in my classpath.
Mainly conflict between 1.x and 2.x.
What worked for me was to exclude in my Maven build the Jersey library that came from other dependencies that are not from Spark.
For example:
<dependency>
<groupId>org.apache.parquet</groupId>
<artifactId>parquet-avro</artifactId>
<version>1.9.0</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Excluding version Jersey 1.x (My Spark distro used 2.x) solved the problem.
Edit:
Also -> happened when servlet api 2.5 JAR was in classpath instead or together with 3.x
In case you are using WildFly, see if https://issues.apache.org/jira/browse/SPARK-27795 can help (there you find also (a quite ugly) workaround).
I was also facing the same problem and tried with sys.props.update("spark.ui.proxyBase", ""). Spark UI was fixed but it was still triggering errors in logs for wrong CSS related to javax.
I added below dependency and it fixed all errors:
libraryDependencies += "javax.servlet" % "servlet-api" % "2.5" % "provided"

Managed VM JDO Datastore

I am trying to migrate an AppEngine project to MVM, custom runtime environment.
I faced an issue with Memcache, which was solved by replacing:
CacheManager.getInstance().getCacheFactory().createCache ...
...
with:
new XMemcachedClient(
System.getenv.get("MEMCACHE_PORT_11211_TCP_ADDR"),
Integer.parseInt(System.getenv.get("MEMCACHE_PORT_11211_TCP_PORT")))
...
(BTW, if anyone is having same issues, then maven for XMemcached is:)
<dependency>
<groupId>com.googlecode.xmemcached</groupId>
<artifactId>xmemcached</artifactId>
<version>2.0.0</version>
</dependency>
I am now facing an issue with DataStore JDO and PersistenceManager (using DataNucleus in the project).
Basically, I am looking to replace this:
JDOHelper.getPersistenceManagerFactory("xxx").getPersistenceManager() ...
...
with ?...
Are there any "magic" environment variables I can use for composing the address (like the MEMCACHE_PORT_11211_TCP_ADDR and MEMCACHE_PORT_11211_TCP_PORT is the case of Memcache)? Any other means I can communicate the datasource with (from a MVM project)?
Thanks in advance,
Ohad
You may want to consider using the gcloud-java project for accessing datastore. The big advantage here is that you can use the same code/client from App Engine, Container Engine, and Compute Engine:
https://github.com/GoogleCloudPlatform/gcloud-java
Hope this helps!

When Spring Boot application running by Intelij Idea views can`t be resolved

I have encountered a strange situation, the decision which I cant find.
I`m runnig simple demo application using Spring Boot 1.3.0 and Intelij Idea 14.1.3
The problem is that Spring MVC cant resolve the view:
javax.servlet.ServletException: Could not resolve view with name 'home' in servlet with name 'dispatcherServlet'
Oddity is that when I run application by Maven Spring Boot-plugin
mvn clean spring-boot:run
everythig works fine.
Both views ("home.jsp" - returning from Controller and "start.jsp" - described in Configuration class) resolve correctly.
Full source code you can see here
I`ve downloaded another demo project - the same situation.
So, I think that something wrong with my IDE configuration.
But what is going wrong - I don`t know.
In File->Project Structure
I have added Spring and web module in "Modules" tab, the same I`ve made in "Facets" tab.
What is possible to do to make application run correctly using IDE?
Problem was in dependecies configuration in pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
I have change <scope>provided</scope> to <scope>compile</scope> and it works well.

Resources