10 Replies Latest reply on Jun 24, 2016 7:56 AM by johannes2014

    Issue excluding built in JAX-RS

      I am trying to use CXF 2.7.5 and am having some difficulty due to a version conflict on the JAX-RS libraries.

       

      I am using EAP 6.0 / AS 7.1.2

       

      I have found that the root cause is the module javax.ws.rs.api which is included by transative dependency.  In my standalone.xml I do have org.jboss.as.web and it depends on the following

       

      module="org.jboss.as.web"
                depends on
                          module name="com.sun.jsf-impl"
                               depends on
                                         module name="javaee.api"/>
                                                   depends on
                                                                  module name="javax.ws.rs.api" 
      

       

      What is the preferred way of excluding javx.ws.rs.api  ?  I have tried the following which did not work.

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
         <deployment>
             <exclusions>
                <module name="javax.ws.rs.api" />
              </exclusions>
          </deployment>
      </jboss-deployment-structure>
      

       

      which did not work.

       

      I ended up commenting out javax.ws.rs.api from the module.xml for javaee.api.  I'd rather not make a change to the module.xml, is there a way to exclude a transative dependency in standalone.xml?

        • 1. Re: Issue excluding built in JAX-RS
          rcd

          I have successfully used Jersey as my JAX-RS implementation on several projects. The trick is to prevent JBoss from trying to use the built-in RestEasy implementation, which gets added automatically when JBoss detects JAX-RS annotations in the deployment (see https://docs.jboss.org/author/display/AS71/Implicit+module+dependencies+for+deployments).

           

          The easiest way to disable RestEasy is by just removing the jaxrs subsystem and extension from standalone.xml. Alternatively, the JBoss documentation says you can also use jboss-deployment-structure.xml to exclude RestEasy on a per-deployment basis (see https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7), but I have not tried that.

          • 2. Re: Issue excluding built in JAX-RS

            I have tried disabling resteasy, but it doesn't seem to prevent the jaxrs 1.x libraries from being present on the classpath.  As I mentioned in my original post I am using a customized standalone.xml which references org.jboss.as.web which ultimately brings in javax.ws.rs.api.  I have also tried the following with no luck.

             

            <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
            <module name="deployment.javaee.api" >
                <dependencies>
                  <module name="javax.ws.rs.api" >
                    <imports>
                      <exclude path="/**" />
                    </imports>
                  </module>
                </dependencies>
              </module>
            </jboss-deployment-structure>
            

             

            This is the error I have been receiving.

             

            11:54:27,023 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/security].[CXFServlet]] (http-localhost/127.0.0.1:8085-1) Servlet.service() for servlet CXFServlet threw exception: java.lang.NoSuchMethodError: javax.ws.rs.ClientErrorException.validate(Ljavax/ws/rs/core/Response;Ljavax/ws/rs/core/Response$Status$Family;)Ljavax/ws/rs/core/Response;
                      at javax.ws.rs.ClientErrorException.<init>(ClientErrorException.java:88) [javax.ws.rs-api-2.0-m10.jar:2.0-m10]
            
            • 3. Re: Issue excluding built in JAX-RS
              rcd

              Why are you trying to prevent JBoss from depending on the JAX-RS API it ships with? You shouldn't need to do that. I didn't when using Jersey. You should make sure you're not including any EE API artifacts (including JAX-RS) in your deployment.

               

              EDIT:

              The edit with the error explains the issue better. Rather than try to bundle the JAX-RS 2.0 API with your deployment, I'd recommend replacing the JAX-RS API artifact in the JBoss modules directory. That still may not work, and even if it does, you're likely to be missing some JAX-RS 2.0 features that require integration with other EE 7 specs. Unless there's some reason you need JAX-RS 2.0, I'd stick with 1.x instead as long as you're using AS7.

              • 4. Re: Issue excluding built in JAX-RS

                CXF 2.7.5 has a transitive dependency on javax.ws.rs-api-2.0-m10.jar:2.0-m10,  i am not sure I can exclude the 2.0 dependency and still have CXF 2.7.5 work properly.

                • 5. Re: Issue excluding built in JAX-RS
                  ctomc

                  You should exclude whole subsystem to be doing anything to your deployment.

                   

                  one way would be to add

                   

                    <deployment>

                       <exclude-subsystems>

                          <subsystem name="resteasy" />

                      </exclude-subsystems>    

                    </deployment>

                   

                  one way would be to remove resteasy subsystem from standalone.xml

                   

                  --

                  tomaz

                  • 6. Re: Issue excluding built in JAX-RS

                    Tomaz Cerar wrote:

                     

                    You should exclude whole subsystem to be doing anything to your deployment.

                     

                    one way would be to add

                     

                      <deployment>

                         <exclude-subsystems>

                            <subsystem name="resteasy" />

                        </exclude-subsystems>    

                      </deployment>

                     

                    one way would be to remove resteasy subsystem from standalone.xml

                     

                    --

                    tomaz

                     

                    As I have been saying excluding the resteasy subsystem does not help, I don't have rest easy in my standalone.xml  this is because jaxrs-1.1 is a dependency on the javaee module.  I ended up getting what I needed to work by excluding the entire javaee subsystem and including all the needed dependencies of that module with the exception of jaxrs.

                    • 7. Re: Issue excluding built in JAX-RS
                      ctomc

                      No! you ware trying to exclude modules from deployment, not subsystem as whole.

                      If you exclude subsystem it wont add any server specied module dependanices (the ones you wanted to exclude)

                       

                      Also module dependanices are not transitive unless explicitly defined(marked as exported)

                      • 8. Re: Issue excluding built in JAX-RS

                        Tomaz Cerar wrote:

                         

                        No! you ware trying to exclude modules from deployment, not subsystem as whole.

                        If you exclude subsystem it wont add any server specied module dependanices (the ones you wanted to exclude)

                         

                        Also module dependanices are not transitive unless explicitly defined(marked as exported)

                        I have tried excluding the resteasy subsystem uaing your proposed configuration and it doesn't help. One thing that might be a clue based on what you just said is that javaee.api contains the following.

                         

                                <module name="javax.ws.rs.api" export="true"  services="export"/>
                        

                         

                        If I change export to false or remove the line entirely it works.  In fact it still works with no changes to the jboss deployment as I don't and never had resteasy pulled into my standalone.xml

                        • 9. Re: Issue excluding built in JAX-RS
                          abulkay

                          [replay to 6 above]

                          which subsystem did you exclude to get it to work?

                          • 10. Re: Issue excluding built in JAX-RS
                            johannes2014

                            This is the easiest solution to exclude JAX-RS API in your WAR only using jboss-deployment-structure.xml (without having to modify the Jboss standalone.xml):

                             

                            1. exclude the module javaee.api completely

                            2. re-import the module javaee.api and exclude the JAX-RS classes

                             

                            That's it!

                             

                            Verified on Jboss EAP 6.2

                             

                            jboss-deployment-structure.xml

                             

                            <?xml version="1.0" encoding="UTF-8"?>

                            <jboss-deployment-structure>

                                <deployment>

                                    <dependencies>

                                        <!-- Exclude JAX-RS: 2. re-import the javaee.api and exclude the JAX-RS classes -->

                                        <module name="javaee.api" >

                                            <imports>

                                                <exclude path="javax/ws/**" />

                                            </imports>

                                        </module>

                                    </dependencies>

                                    <exclusions>

                                        <!-- Exclude JAX-RS: 1. exclude the javaee.api completely -->

                                           <module name="javaee.api" />

                                    </exclusions>

                                </deployment>

                            </jboss-deployment-structure>

                             

                            This brings the HTTP 500 without any stacktrace/NoSuchMethodExceptions to the invoker and clean Jackson Exceptions in the Jboss log file:

                            Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of byte out of VALUE_STRING token

                            ....

                             

                            Also see CXF Working on jboss EAP 6 - Stack Overflow

                             

                            In case you still have troubles with the Jboss-supplied JAX-RS subsystem (e.g. when trying to generate CXF Swagger-API I got a java.lang.LinkageError: ClassCastException: attempting to castjar:file:/c:/jboss//modules/system/layers/base/javax/ws/rs/api/main/jboss-jaxrs-api_1.1_spec-1.0.1.Final-redhat-2.jar!/javax/ws/rs/ext/RuntimeDelegate.class to vfs:/c:/jboss/bin/content/myapp.war/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar/javax/ws/rs/ext/RuntimeDelegate.class), then you can also exclude the whole jaxrs-subsystem:

                            <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> ... <exclude-subsystems> <subsystem name="jaxrs" /> </exclude-subsystems> </deployment> </jboss-deployment-structure>