Wildfly 10 or higher, JavaEE7, EJBs and RESTful-services
inkimannen Nov 27, 2019 8:41 AMHello,
I have an application, maven multimodule, that has the following modules.
- module-parent
- module-ear
- module-ejb (handles the db-connection, in my '
ServiceBean'-class
) - module-web (restful-services)
I am able now to deploy the ear-file to Wildfly 10, access the Restful-services in the web-module and make use of the db-connection implemented in the 'ServiceBean'-class.
All is fine there. The configuration in the web.xml is a bit 'hairy' I guess.
I found a restful-client / restful-service at howtodoinjava (as a proof-of-concept to upload large files , up to 6GB) , those project is available in this repo.
I hope that my README.md-file is uptodate, if you would like to try this out and ask for improvements if needed.You can deploy the service in Tomcat, upload a file with the TestClient.java.
As you can see in the pom.xml the project has dependencies on org.glassfish.jersey ( making this statement, it is my hypothesis that these dependencies are giving me problem later on)
What I would like to do, is to replace the current 'module-web' with a new web-module ( the web-project in the RESTfulServerClient-repo )
I can call the '/hello'-endpoint.
Doing the following addition to the JerseyService-class (adding the EJB-bean to be injected) the 'bean' variable on line 16 is always empty.
@Path("/upload") public class JerseyService { private final static Logger logger = Logger.getLogger(Service.class); @EJB private ServiceBean bean; public Service() { } @GET @Path("/hello") public Response tst() { logger.info("@GET /hello");; logger.info("ServiceBean is "+bean); return Response.status(200).entity("service ok").build(); }
my web.xml has the following content
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>se.nrm.bio.mediaserver.rs</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
So the injections does not to work now, it works in my original module-web(4) where I am using a set of different setup.
I can see the ejb:s in the wildfly admi-interface, so the ear has been deployed but the restful services seem not to be able to fetch them.
The reason why I am not using the above setup is that I am unsure on how to write a restful-service&restful-client using the below dependencies ( any suggestions ?)
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Auto scan REST service -->
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/media/*</url-pattern>
</servlet-mapping>
<!-- Auto scan REST service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<!-- this should be the same URL pattern as the servlet-mapping property -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/media</param-value>
</context-param>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
</web-app>
I hope that you are able to give me some advice here.
and/or pinpoint me to a good book/course on JavaEE 7 or higher ( and how to deploy in Wildfly, maven ) .
best, i