9 Replies Latest reply on May 24, 2017 12:17 PM by jasonglass

    JAX-RS Support in EJB Jar Project

    jasonglass

      Hi 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.

        • 1. Re: JAX-RS Support in EJB Jar Project
          jaikiran

          Jason Glass wrote:

           

          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!


          When starting a new thread, the editor window has a ">>" symbol in the toolbar. Clicking on that shows many options including Syntax highlighting which you can use for code.

           

          When you are replying to a thread, the mini windows that shows up has a "Use advanced editor" option at the top right of the message editor window. Selecting that takes you to a advanced editor and then again you select the ">>" symbol in there. Having said that, I don't see the "Use advanced editor" option right now in the window I'm typing. I think it's very specific to this EAP forum and I am not sure why!!!

          1 of 1 people found this helpful
          • 2. Re: JAX-RS Support in EJB Jar Project
            jaikiran

            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>

             

            jboss.xml files are no longer relevant in JBoss EAP7 and are completely ignored. The issue you are running into though, isn't related to this.

            1 of 1 people found this helpful
            • 3. Re: JAX-RS Support in EJB Jar Project
              jaikiran

              If your application has an application.xml and a ejb-jar.xml, can you paste me the contents of those 2 files please? I'm mostly interested in the xsd declarations in those files, but would be good to see them in the entirety. You can change any application specific class/package names from in those files while posting.

              • 4. Re: JAX-RS Support in EJB Jar Project
                jasonglass

                Thank you Jaikiran on the thorough explanation as to the ">>" and the advanced editor!

                • 5. Re: JAX-RS Support in EJB Jar Project
                  jasonglass

                  On the jboss.xml, thats understood.  I just already had the jboss.xml as the app currently runs in JBoss EAP 5 and is being ported to JBoss EAP 7 in which case I'll be using the ejb-jar.xml.  I'm currently not using it (ejb-jar.xml) as I do a lot of resource injection (strings, ints and booleans) and I dont have much luck getting that to work in JBoss 5 unless I'm using the jboss.xml.  Probably a good point though that when I did try it in JBoss 7 - the file was ignored but the EJB's were still found because of the annotations.

                   

                  Here's a copy of the application.xml.  Pretty much just the default:

                  (dang it the ">>" insert has disappeared - maybe when its a "reply" it doesnt show up, lame ;-( update: interesting the ">>" shows up on editing a post however!)

                  <?xml version="1.0" encoding="UTF-8"?>
                  <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
                    <display-name>C1Authentication</display-name>
                    <module>
                      <ejb>C1AuthService.jar</ejb>
                    </module>
                    <module>
                      <web>
                        <web-uri>C1AuthWeb.war</web-uri>
                        <context-root>C1AuthWeb</context-root>
                      </web>
                    </module>
                  </application>
                  

                   

                  Thanks again Jaikiran

                   

                  PS:  Edit Jaikiran, not sure why bu the XML editor is adding commas in the XML, theyre not there in the real files, also ignore the WAR listing above as I was just starting to try adding a web project though again I didnt want to unless I had to

                  • 6. Re: JAX-RS Support in EJB Jar Project
                    jaikiran

                    Jason Glass wrote:

                     

                     

                    Here's a copy of the application.xml. Pretty much just the default:

                    (dang it the ">>" insert has disappeared - maybe when its a "reply" it doesnt show up, lame ;-( update: interesting the ">>" shows up on editing a post however!)

                     

                     

                    Can you change that XSD declaration of the application element to:

                    <application 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/application_6.xsd"

                      version="6">

                     

                    see if it works fine?

                    • 7. Re: JAX-RS Support in EJB Jar Project
                      jasonglass

                      Hi Jaikiran!

                       

                      So I did get things working with a WAR being included, not sure if you'd like to drop this or not but it would be nice if an EJB annotated with JAX-RS worked, e.g. we wouldnt need a WAR and instead just an EJB Jar!  But everything I've been looking at shows JAX-RS as requiring a servlet container so I'm not exactly sure what type of web container is exposed for JAX-WS EJB's then?  BTW: the "syntax highlighting/code or ">>" functionality definitely only appears now when editing a reply post, not on a reply post - bug ;-(

                       

                      So with this (note the last lines are commented out as I added yours to the top):

                      <?xml version="1.0" encoding="UTF-8"?>
                      <application 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/application_6.xsd"
                        version="6">
                        <display-name>C1Authentication</display-name>
                        <module>
                          <ejb>C1AuthService.jar</ejb>
                        </module>
                        <module>
                          <web>
                            <web-uri>C1IPAuthService.war</web-uri>
                            <context-root>C1IPAuthService</context-root>
                          </web>
                        </module>
                      </application>
                      <!--application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                      xmlns="http://java.sun.com/xml/ns/javaee" 
                      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                      http://java.sun.com/xml/ns/javaee/application_5.xsd" 
                      version="5" -->
                      

                       

                      This is the stack trace, its not happy about something ;-(

                      10:58:44,489 WARN  [HDScanner] Failed to add deployment: vfsfile:/C:/JBoss-ES_5.1.0_Orig/jboss-eap-5.1/jboss-as/server/default/deploy/C1Authentication.ear/
                      org.jboss.deployers.spi.DeploymentException: Exception determining structure: AbstractVFSDeployment(C1Authentication.ear)
                        at org.jboss.deployers.spi.DeploymentException.rethrowAsDeploymentException(DeploymentException.java:49)
                        at org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers.determineStructure(AbstractStructuralDeployers.java:85)
                        at org.jboss.deployers.plugins.main.MainDeployerImpl.determineStructure(MainDeployerImpl.java:1001)
                        at org.jboss.deployers.plugins.main.MainDeployerImpl.determineDeploymentContext(MainDeployerImpl.java:437)
                        at org.jboss.deployers.plugins.main.MainDeployerImpl.addDeployment(MainDeployerImpl.java:387)
                        at org.jboss.deployers.plugins.main.MainDeployerImpl.addDeployment(MainDeployerImpl.java:297)
                        at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.addDeployment(MainDeployerAdapter.java:86)
                        at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:385)
                        at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:294)
                        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
                        at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
                        at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
                        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                        at java.lang.Thread.run(Unknown Source)
                      Caused by: java.lang.RuntimeException: Error determining structure: C1Authentication.ear
                        at org.jboss.deployment.EARStructure.determineStructure(EARStructure.java:307)
                        at org.jboss.deployers.vfs.plugins.structure.StructureDeployerWrapper.determineStructure(StructureDeployerWrapper.java:73)
                        at org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl.doDetermineStructure(VFSStructuralDeployersImpl.java:196)
                        at org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl.determineStructure(VFSStructuralDeployersImpl.java:221)
                        at org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers.determineStructure(AbstractStructuralDeployers.java:77)
                        ... 16 more
                      Caused by: org.jboss.xb.binding.JBossXBException: Failed to parse source: Failed to parse schema for nsURI=http://java.sun.com/xml/ns/javaee, baseURI=null, schemaLocation=http://java.sun.com/xml/ns/javaee/application_6.xsd
                        at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:203)
                        at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:183)
                        at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:161)
                        at org.jboss.deployment.EARStructure.determineStructure(EARStructure.java:162)
                        ... 20 more
                      Caused by: org.jboss.xb.binding.JBossXBRuntimeException: Failed to parse schema for nsURI=http://java.sun.com/xml/ns/javaee, baseURI=null, schemaLocation=http://java.sun.com/xml/ns/javaee/application_6.xsd
                        at org.jboss.xb.binding.resolver.AbstractMutableSchemaResolver.resolve(AbstractMutableSchemaResolver.java:293)
                        at org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startElement(SundayContentHandler.java:274)
                        at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.startElement(SaxJBossXBParser.java:401)
                        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
                        at org.apache.xerces.xinclude.XIncludeHandler.startElement(Unknown Source)
                        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
                        at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
                        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
                        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
                        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
                        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
                        at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
                        at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:199)
                        ... 23 more
                      Caused by: org.jboss.xb.binding.JBossXBRuntimeException: -1:-1 31:3 The declaration for the entity "HTML.Version" must end with '>'.
                        at org.jboss.xb.binding.sunday.unmarshalling.XsdBinderTerminatingErrorHandler.handleError(XsdBinderTerminatingErrorHandler.java:40)
                        at org.apache.xerces.impl.xs.XMLSchemaLoader.reportDOMFatalError(Unknown Source)
                        at org.apache.xerces.impl.xs.XSLoaderImpl.load(Unknown Source)
                        at org.jboss.xb.binding.Util.loadSchema(Util.java:395)
                        at org.jboss.xb.binding.sunday.unmarshalling.XsdBinder.bind(XsdBinder.java:176)
                        at org.jboss.xb.binding.sunday.unmarshalling.XsdBinder.bind(XsdBinder.java:147)
                        at org.jboss.xb.binding.resolver.AbstractMutableSchemaResolver.resolve(AbstractMutableSchemaResolver.java:285)
                        ... 37 more
                      
                      • 8. Re: JAX-RS Support in EJB Jar Project
                        ctomc

                        ??

                        last stack trace is not from EAP7 or anything from this decade, that is AS5

                        which is completely different in every aspect.

                        1 of 1 people found this helpful
                        • 9. Re: JAX-RS Support in EJB Jar Project
                          jasonglass

                          Hi Tomaz - very true.  The goal is the JAX-RS working in JBoss EAP 5 not EAP 7.  I shall try it in JBoss AS 7 and see what happens, thanks for pointing it out.  Is everything fairly moot however in that an EJB project, even with web service annotations has no servlet container to handle the JAX-RS?