JAX-RS Support in EJB Jar Project
jasonglass May 22, 2017 11:00 AMHi All! I know this may be a silly question however I am adding functionality to an existing project so I was trying to leave things as simple and similar as possible, e.g. it's a EJB Module project with EAR and I was trying to avoid adding in a Dynamic Web Project/WAR but it looks as if I may have to.
What I was trying to accomplish:
The project already has an EJB Web Service
The project needed to support a new web context that was either a servlet or JAX-RS Rest endpoint. I ended up trying to go with adding JAX-RS support since a servlet doesnt really belong in an EJB project but since there was already a Web Service annotated bean I figured adding another stateless session EJB would be the way to go!
Unfortunately, it appears (tried JBoss EAP 5 and 7) that while JBoss doesnt complain in anyway and actually does bind and start the EJB's - the new one is not being exposed as a JAX-RS endpoint (or I cannot find the exact path though I did look everywhere for it in the JMX console)
Heres the code (again, just a simple helloworld)
PS: is there a "code" tag that can be used, I looked and I'm not seeing it though I've see others use it!
package net.mycompany.service; import javax.ejb.Stateless; import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.Path; /** * Session Bean implementation class IPAuthJaxRsService */ @Stateless(mappedName = "IPAuthJaxRsService") //The Java class will be hosted at the URI path "/helloworld" @Path("/helloworld") public class IPAuthJaxRsService implements IPAuthJaxRsServiceLocal { /** * Default constructor. */ public IPAuthJaxRsService() { // TODO Auto-generated constructor stub } // The Java method will process HTTP GET requests @GET // The Java method will produce content identified by the MIME Media // type "text/plain" @Produces("text/plain") public String getClichedMessage() { // Return some cliched textual content return "Hello World"; } }
And while it may not have been needed, here's the jboss.xml entry
<?xml version="1.0"?> <jboss xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss_5_0.xsd" version="3.0"> <enterprise-beans> <session> <ejb-name>IPAuthJaxRsService</ejb-name> </session> </enterprise-beans> </jboss>
I did try and turn on javax.ws.rs debug but that didnt offer up any information (or anything at all) - It looks like its just being regarded as an EJB and not a Rest enabled EJB. I'm thinking this may be because theres no servlet container? But doesnt the ejb web service annotation and functionality somehow get by without having a servlet container?
I can move to a Dynamic Web Project/WAR - just curious as to why this may not have been working
Thank you! Have a great weekend!
Oh, the URL I tried was http://localhost:8080/myAppName/helloworld - it returns a 404
Oh, trace on deploy:
Note: WSService is the original bean. IPAuthJaxRsService is the new one
13:33:59,407 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) WFLYDS0004: Found C1Authentication.ear in deployment directory. To trigger deployment create a file called C1Authentication.ear.dodeploy 13:33:59,415 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "C1Authentication.ear" (runtime-name: "C1Authentication.ear") 13:33:59,486 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0207: Starting subdeployment (runtime-name: "C1AuthService.jar") 13:33:59,554 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment C1Authentication.ear 13:33:59,573 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment C1AuthService.jar 13:33:59,575 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-3) WFLYEJB0473: JNDI bindings for session bean named 'IPAuthJaxRsService' in deployment unit 'subdeployment "C1AuthService.jar" of deployment "C1Authentication.ear"' are as follows: java:global/C1Authentication/C1AuthService/IPAuthJaxRsService!net.mycompany.service.IPAuthJaxRsServiceLocal java:app/C1AuthService/IPAuthJaxRsService!net.mycompany.service.IPAuthJaxRsServiceLocal java:module/IPAuthJaxRsService!net.mycompany.service.IPAuthJaxRsServiceLocal java:global/C1Authentication/C1AuthService/IPAuthJaxRsService java:app/C1AuthService/IPAuthJaxRsService java:module/IPAuthJaxRsService 13:33:59,575 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-3) WFLYEJB0473: JNDI bindings for session bean named 'WSService' in deployment unit 'subdeployment "C1AuthService.jar" of deployment "C1Authentication.ear"' are as follows: java:global/C1Authentication/C1AuthService/WSService!net.mycompany.service.IService java:app/C1AuthService/WSService!net.mycompany.service.IService java:module/WSService!net.mycompany.service.IService 13:33:59,576 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0006: Starting Services for CDI deployment: C1Authentication.ear 13:33:59,579 INFO [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0009: Starting weld service for deployment C1Authentication.ear 13:33:59,601 INFO [org.jboss.ws.cxf.metadata] (MSC service thread 1-2) JBWS024061: Adding service endpoint metadata: id=WSService address=http://localhost:8080/C1AuthService/WSService implementor=net.mycompany.service.WSService serviceName={http://service.mycompany.net/}WSServiceService portName={http://service.mycompany.net/}WSServicePort annotationWsdlLocation=null wsdlLocationOverride=null mtomEnabled=false 13:33:59,632 INFO [org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-2) Creating Service {http://service.mycompany.net/}WSServiceService from class net.mycompany.service.WSService 13:33:59,889 INFO [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-2) Setting the server's publish address to be http://localhost:8080/C1AuthService/WSService 13:33:59,962 INFO [org.jboss.ws.cxf.deployment] (MSC service thread 1-2) JBWS024074: WSDL published to: file:/C:/jboss-eap-7.0/standalone/data/wsdl/C1Authentication.ear/C1AuthService.jar/WSServiceService.wsdl 13:34:00,013 INFO [org.jboss.as.webservices] (MSC service thread 1-3) WFLYWS0003: Starting service jboss.ws.endpoint."C1Authentication.ear"."C1AuthService.jar".WSService 13:34:00,194 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 207) WFLYUT0021: Registered web context: /C1AuthService 13:34:00,247 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0010: Deployed "C1Authentication.ear" (runtime-name : "C1Authentication.ear")
Message was edited by: Jason Glass - wanted to properly format the jav, xml and trace sections for readability.