9 Replies Latest reply on Oct 16, 2013 7:30 AM by akayender

    Jersey application on JBoss AS 7

    shankarm

      I created a restful webservice and  using Jersey as JAX -RS implementataion on JBoss AS 7. But I got following error during  deployment

       

      Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Only one JAX-RS Application Class allowed. com.sun.jersey.api.core.WebAppResourceConfig com.sun.jersey.api.core.ScanningResourceConfig com.sun.jersey.server.impl.application

      .DeferredResourceConfig com.sun.jersey.api.core.ResourceConfig com.sun.jersey.api.core.ClassNamesResourceConfig com.sun.jersey.api.core.ApplicationAdapter com.sun.jersey.api.core.PackagesResourceConfig com.sun.jersey.api.core.ClasspathResourceConfig

      com.sun.jersey.api.core.DefaultResourceConfig

              at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:208)

              at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:104)

              at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115)

              ... 5 more

      a

      While googling on the net , found that JBoss comes with its own implementation  for JAX RS (Resteasy). Also, found that JIRA is already opened for JBoss AS6 (https://issues.jboss.org/browse/JBAS-8830)

       

      Is that issue resolved in AS7? Is there any way to make Jersey application work on JBoss AS7?

       

      Thanks in advance.

        • 1. Re: Jersey application on JBoss AS 7
          smtrax

          You can remove :

           

          <extension module="org.jboss.as.jaxrs"/>

           

          <subsystem xmlns="urn:jboss:domain:jaxrs:1.0"/>   in standalone.xml

           

          but you would get another error:

          3:00:14,695 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/sdpweb]] (MSC service thread 1-1) StandardWrapper.Throwable: com.sun.jersey.core.spi.scanning.ScannerException: The URI scheme vfs of the URI vfs:/D:/jboss-as-7.0.0.Final/bin/content/SDP.ear/sdpweb.war/WEB-INF/classes/si/***/sdp/rest/ is not supported. Package scanning deployment is not supported for such URIs.

          Try using a different deployment mechanism such as explicitly declaring root resource and provider classes using an extension of javax.ws.rs.core.Application

              at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:225) [jersey-core-1.4.jar:]

              at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139) [jersey-core-1.4.jar:]

              at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:78) [jersey-server-1.4.jar:]

              at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:116) [jersey-server-1.4.jar:]

              at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:81) [jersey-server-1.4.jar:]

              at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:92) [jersey-server-1.4.jar:]

              at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:677) [jersey-server-1.4.jar:]

              at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:655) [jersey-server-1.4.jar:]

              at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:206) [jersey-server-1.4.jar:]

              at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:342) [jersey-server-1.4.jar:]

              at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:516) [jersey-server-1.4.jar:]

              at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

              at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

              at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

              at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3631) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

              at org.apache.catalina.core.StandardContext.start(StandardContext.java:3844) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

              at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.0.Final.jar:7.0.0.Final]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

              at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_20]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_20]

              at java.lang.Thread.run(Thread.java:619) [:1.6.0_20]

          • 2. Re: Jersey application on JBoss AS 7
            shankarm

            Thanks for your response. I tried removing RestEasy module and get it deployed successfully. While accessing the Get URL , I got some linkage error (see stacktrace below). I also checked that class com/sun/jersey/api/json/JSONWithPadding for which linkage error is displayed is bundled inside  jersey-bundle-1.4.jar

             

            web.xml snippet is as :

             

            <servlet-name>jersey</servlet-name>

            <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

             

            StackTrace:

             

            javax.servlet.ServletException: Servlet.init() for servlet com.avaya.rts.ui.HelloRS threw exception

            org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139)

            org.jboss.as.web.NamingValve.invoke(NamingValve.java:57)

            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)

            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667)

            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952)

            java.lang.Thread.run(Thread.java:662)

            root cause

            java.lang.LinkageError: Failed to link com/sun/jersey/api/json/JSONWithPadding (Module "deployment.HelloService.ear.hello.war:main" from Service Module Loader)
                 org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:401)
                 org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:261)
                 org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:76)
                 org.jboss.modules.Module.loadModuleClass(Module.java:588)
                 org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:183)
                 org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:358)
                 org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:330)
                 org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:307)
                 org.jboss.modules.ConcurrentClassLoader.loadClas
            • 3. Re: Jersey application on JBoss AS 7
              smtrax

              Try to coment parameter :

               

               

               

                   <servlet>

                      <servlet-name>Jersey REST Service</servlet-name>

                      <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

              <!--         <init-param> -->

              <!--             <param-name>com.sun.jersey.config.property.packages</param-name> -->

              <!--             <param-value>si.xxx.sdp.rest</param-value> -->

              <!--         </init-param> -->

                      <init-param>

                          <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>

                          <param-value>true</param-value>

                      </init-param>

                      <load-on-startup>2</load-on-startup>

                  </servlet>

              • 4. Re: Jersey application on JBoss AS 7
                shankarm

                Worked for me.

                I had to bundle jackson-all-1.8.5.jar in lib

                • 5. Re: Jersey application on JBoss AS 7
                  smtrax

                  I can deploy it with warnings. When i call it get this error:

                  08:41:36,301 SEVERE [com.sun.jersey.server.impl.application.WebApplicationImpl] (http--127.0.0.1-8080-1) The RuntimeException could not be mapped to a response, re-throwing to the HTTP container: java.lang.NullPointerException

                      at org.jboss.resteasy.util.PathHelper.replaceEnclosedCurlyBraces(PathHelper.java:53)

                      at org.jboss.resteasy.util.Encode.savePathParams(Encode.java:266)

                      at org.jboss.resteasy.util.Encode.encodeValue(Encode.java:292)

                      at org.jboss.resteasy.util.Encode.encodeFragment(Encode.java:182)

                      at org.jboss.resteasy.specimpl.UriBuilderImpl.fragment(UriBuilderImpl.java:329)

                      at com.sun.jersey.spi.container.ContainerResponse.setHeaders(ContainerResponse.java:664) [jersey-server-1.9.jar:]

                      at com.sun.jersey.spi.container.ContainerResponse.setResponse(ContainerResponse.java:544) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:207) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) [jersey-server-1.9.jar:]

                      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) [jersey-server-1.9.jar:]

                      at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) [jersey-server-1.9.jar:]

                      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) [jersey-server-1.9.jar:]

                      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) [jersey-server-1.9.jar:]

                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:480) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) [jboss-as-web-7.0.0.Final.jar:7.0.0.Final]

                      at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:49) [jboss-as-jpa-7.0.0.Final.jar:7.0.0.Final]

                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]

                      at java.lang.Thread.run(Thread.java:619) [:1.6.0_20]

                  • 6. Re: Jersey application on JBoss AS 7
                    mr.bee

                    I m successfully able to deploy the application by removing these

                     

                    <extension module="org.jboss.as.jaxrs"/>

                    <subsystem xmlns="urn:jboss:domain:jaxrs:1.0"/>

                     

                    from standalone.xml

                    But this is not acceptable, i mean there may some applications deployed on the server which might be using these,

                    so is there any other way?

                    BTW i have treid to exclude this using jboss-deployment-structure.xml but it didn't worked, still got the same error.

                    • 7. Re: Jersey application on JBoss AS 7
                      darrenjones

                      I know it's a while since the thread was opened, but as I am posting as I struggled and eventually found something that worked.

                       

                      What worked for me (in JBoss 7.1.1.Final) was to add the following context-params to the web.xml:

                       

                      <context-param>

                              <param-name>resteasy.scan</param-name>

                              <param-value>false</param-value>

                      </context-param>

                      <context-param>

                              <param-name>resteasy.scan.resources</param-name>

                              <param-value>false</param-value>

                      </context-param>

                      <context-param>

                              <param-name>resteasy.scan.providers</param-name>

                              <param-value>false</param-value>

                      </context-param>

                       

                      All three are necessary, and then JBoss's scanner skips the WAR file, allowing Jersey to do its stuff.

                       

                      FYI - this workaround was gleaned by looking in the JBoss source for org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor. Who knows if this will continue to work in future releases?

                       

                      It would be nice if there was a way to skip scanning that didn't involve modifying the original web.xml - perhaps in one of the other deployment descriptor files. Would this be a valid enhancement to raise?

                      • 8. Re: Jersey application on JBoss AS 7
                        sebrevel

                        Hi,

                         

                        I have the same problem, and your code fix it but I have another problem :

                         

                        java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only

                                  at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:126)

                                  at org.jboss.as.naming.WritableServiceBasedNamingStore.createSubcontext(WritableServiceBasedNamingStore.java:116)

                                  at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:338)

                                  at org.jboss.as.naming.InitialContext.createSubcontext(InitialContext.java:229)

                                  at org.jboss.as.naming.NamingContext.createSubcontext(NamingContext.java:346)

                         

                        And I don't understand this error.

                        Do you have this error when you use jersey with AS 7 in your case ?

                         

                        Thks

                        • 9. Re: Jersey application on JBoss AS 7
                          akayender

                          I have tested the following solution with JBoss6.0 ant it worked, this is the combination of Mitja and Darren's solutions

                           

                          add the following context-params

                          <context-param>

                                  <param-name>resteasy.scan</param-name>

                                  <param-value>false</param-value>

                          </context-param>

                          <context-param>

                                  <param-name>resteasy.scan.resources</param-name>

                                  <param-value>false</param-value>

                          </context-param>

                          <context-param>

                                  <param-name>resteasy.scan.providers</param-name>

                                  <param-value>false</param-value>

                          </context-param>

                           

                          and comment out the following init param

                          <!--

                          <init-param>
                          <param-name>com.sun.jersey.config.property.packages</param-name>
                          <param-value>org.abcd.abcd.</param-value>
                          </init-param>

                          -->