0 Replies Latest reply on Oct 31, 2014 10:50 AM by soltzu

    JBoss 6.1 EAP CXF modules, why are there two of them?

    soltzu

      I have two web applications communicating with each other and using basic HTTP authentication. The incoming messages to one of them are intercepted and an HTTP error code (401 or 403) is sent back if there are no user credentials or there are, but they are invalid.

       

      When one of the errors is sent back, the client application handles it in this way:

       

          ...

              } catch(WebServiceException ex) {

                  String message = null;

                  if(ex.getCause() instanceof HTTPException) {

                      HTTPException httpEx = (HTTPException)ex.getCause();

                      switch(httpEx.getResponseCode()) {

                          case 401:

                              message = "No username/password found in exposure switch to try to access thw server.";

                              break;

                            

                          case 403:

                              message = "Invalid username or password for user : " + username;

                              break;

                            

                          default:

                              message = "Unknown HTTP error when trying to access server.";

                      }

                  } else {

                      message = "Unknown WebSercieException when trying to access server.";

                  }

                  throw new Failure(message, null);

              }

          ...

       

      Now, this code compiles and, before it was cleaned up, I could print the cause of "ex" (i.e. HTTPException), its class name with the getClass() method and its class loader.

       

      At run time, however, I would get a NoClassFoundException and this is what has driven me mad for the last couple of days (I'm relatively new to the web services/jboss world).

       

      The page that guided me to the solution is this https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.3/html/Migration_Guide/Debug_and_Resolve_Seam_22_Booking_Archive_Deployment_Errors_and_Exceptions.html . Following its directions I found out that under:

       

          ${JBOSS_HOME}/modules/system/layers/base/org/apache/cxf

       

      There are two directories, "./impl" and "./main". And HTTPException was under ./impl/main, which was not picked up by JBoss. I found it using:

       

          grep 'org.apache.cxf.transport.http.HTTPException' `find . -name '*.jar'`

       

      Which returned:

       

          Binary file ./impl/main/cxf-rt-transports-http-2.6.8.redhat-7.jar matches

       

      I finally fixed it by adding the following jboss-deployment-structure.xml file under the WEB-INF directory of my WAR:

       

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

       

          <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

          <deployment>

              <dependencies>

                  <module name="org.apache.cxf.impl" slot="main" export="true"/>

              </dependencies>

          </deployment>

      </jboss-deployment-structure>

       

      I also added this in my pom.xml, but I don't know if it is needed:

       

          <dependency>

              <groupId>org.apache.cxf</groupId>

              <artifactId>cxf-rt-transports-http</artifactId>

              <version>${version.cxf}</version>

              <scope>provided</scope>        

          </dependency>

       

      Now, my questions are:

       

      1. Why did my code compile and I could get the class name, the class loader and whatnot of the WebServiceException cause (i.e. HTTPException) but at runtime I got a NoClassFoundException in this line?

       

              if(ex.getCause() instanceof HTTPException)

       

      2. Why are there two CXF modules in JBoss and why is the one under ./main selected by default? Are we supposed to use the one under ./impl/main?

       

      3. From your experience, do you see any drawback from using my jboss-deployment-structure.xml file? Am I exposing too much to the application?

       

      Thanks!

       

      Edit:

       

      I've just verified that this:

       

          <dependency>    

              <groupId>org.apache.cxf</groupId>

              <artifactId>cxf-rt-transports-http</artifactId>

              <version>${version.cxf}</version>

              <scope>provided</scope>         

          </dependency>

       

      is not needed, I already had this in my pom.xml:

       

                   <dependency>

                      <groupId>org.apache.cxf</groupId>

                      <artifactId>cxf-rt-frontend-jaxws</artifactId>

                      <version>${version.cxf}</version> 

                      <scope>provided</scope>         

                  </dependency>

                  <dependency>

                      <groupId>org.apache.cxf</groupId>

                      <artifactId>cxf-api</artifactId>

                      <version>${version.cxf}</version> 

                      <scope>provided</scope>         

                  </dependency>

       

      Message was edited by: Agusti Tomas