7 Replies Latest reply on Feb 26, 2013 2:50 AM by stephen b

    JBossWS + CXF + Spring + Maven triggers "java.lang.NoClassDefFoundError: javax/servlet/ServletException"

    stephen b Newbie

      Hi,

       

      I am newbie in JBossWS and I am currently learning how to use JBossWS + CXF + Spring + Maven. I saw a quickstart project which uses JBossWS and Maven (http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/helloworld-ws/) and used that as a starting point. In order to support CXF, I did the following changes (see attached files for details).

       

      1. Modified this project by adding CXF and Spring as dependencies

      2. Created applicationContext.xml under src/main/webapp/WEB-INF/

      3. Created jbossws-cxf.xml under src/main/webapp/WEB-INF/

      4. Modified web.xml to load applicationContext.xml and changes url of helloworld servlet

      5. Modified HelloWorldServiceImpl.java and added one java class called Connection.java (this is to test if autowiring works)

       

      My JBoss server is version 7.1.1.FINAL using CXF 4.1.1.

       

      Unfortunately, given this very simple change, this combination of libraries causes JBoss to throw an exception (example logs below). Any ideas as to what configuration / dependencies I have to add in my POM file to make this work. I did a bit of experimentation and renaming jbossws-cxf.xml to a temporary file name resolves the problem but this is not what i want to achieve. I want to enable JBossWS + CXF since I am planning to use Autowiring / injection feature of Spring with JBossWS-CXF. 

       

      17:52:01,872 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/jboss-as-helloworld-ws].[HelloWorldService]] (http--127.0.0.1-8083-1) Servlet.service() for servlet HelloWorldService threw exception: java.lang.NoClassDefFoundError: javax/servlet/ServletException

                at org.jboss.wsf.stack.cxf.Messages_$bundle.cannotObtainDestinationFor(Messages_$bundle.java:357)

                at org.jboss.wsf.stack.cxf.RequestHandlerImpl.findDestination(RequestHandlerImpl.java:168)

                at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:85)

                at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:156)

                at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87)

                at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:225)

                at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:150)

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

                at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135)

                at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi.jar:2.1.1.Final]

                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.13.Final.jar:]

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

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

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

                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

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

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

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

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

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

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

                at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_37]

       

       

      Thanks,

      Stephen

        • 1. Re: JBossWS + CXF + Spring + Maven triggers "java.lang.NoClassDefFoundError: javax/servlet/ServletException"
          Jim Ma Apprentice

          JBossWS-CXF can install the spring as modules in AS7, you don't need to include them in maven dependency. Can you try to install the spring module to  AS7 under jbossws-cxf-bin-dist with:

          ant -Djboss.bind.address=your-address -Djbossws-integration.target=jboss711 -Djboss711.home=$AS7_HOME -Dspring=true deploy-jboss711
          

          to see if that helps ?

          • 2. Re: JBossWS + CXF + Spring + Maven triggers "java.lang.NoClassDefFoundError: javax/servlet/ServletException"
            stephen b Newbie

            I  tried re-installing jboss by deleting old jboss directory and copying new one and re-installed the CXF using your command but the problem still persist.The problem only happens if I install JBossWS-CXF and create a jbossws-cxf.xml file under WEB-INF directory.

             

            I set log level to TRACE and I saw that these lines may have caused the issue:

             

            08:22:38,986 TRACE [org.jboss.modules] (http--127.0.0.1-8083-1) Finding class javax.servlet.ServletException from Module "org.jboss.ws.jaxws-client:main" from local module loader @13f7281 (roots: /Users/stephen/Programs/jboss-as-7.1.1.Final/modules)

            08:22:38,987 TRACE [org.jboss.modules] (http--127.0.0.1-8083-1) Class javax.servlet.ServletException not found from Module "org.jboss.ws.jaxws-client:main" from local module loader @13f7281 (roots: /Users/stephen/Programs/jboss-as-7.1.1.Final/modules)

             

            Any clues as to what is the issue? I attached the logs of the incomming request  (jbossws-cxf-request-trace.log). My test is simply hitting http://localhost:<port>/jboss-as-helloworld-ws/hello-world?wsdl

            • 3. Re: JBossWS + CXF + Spring + Maven triggers "java.lang.NoClassDefFoundError: javax/servlet/ServletException"
              stephen b Newbie

              I finally figured out the issue. It looks like JBossWS-CXF jax-ws-client module have some issues in its dependencies thus causing the stack to throw a "javax.servlet.ServletException" due to some missing dependency to "javax.servlet.api" module. I did  the following steps to diagnose and fix the issue:

               

              1. I fixed the module dependency issue of "org.jboss.ws.jaxws-client" module in JBoss. I modified file JBOSS_HOME/modules/org/jboss/ws/jaxws-client/main/module.xml and added line <module name="javax.servlet.api" /> under <dependencies/> section.

               

                  After this fix, JBossWS-CXF is now throwing the correct error. Example stack trace below:

               

                   15:54:14,958 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/jboss-as-helloworld-ws].[HelloWorldService]] (http--127.0.0.1-8083-1) Servlet.service() for servlet                HelloWorldService threw exception: javax.servlet.ServletException: JBWS024029: Cannot obtain destination for /jboss-as-helloworld-ws/hello-world

                                at org.jboss.wsf.stack.cxf.RequestHandlerImpl.findDestination(RequestHandlerImpl.java:168)

                                at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:85)

                                at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:156)

                                at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87)

               

              2. I changed my  jbossws-cxf.xml and fixed the jaxws endpoint address

               

                From:

               

                  <jaxws:endpoint implementor="#HelloWorldService"

                      address="/hello-world">

                  </jaxws:endpoint>

               

                To:

               

                 <jaxws:endpoint implementor="#HelloWorldService"

                      address="/jboss-as-helloworld-ws/hello-world">

                  </jaxws:endpoint>

               

               

              I am able to process requests from client now, but still I don't understand why org.jboss.ws.jaxws-client module doesn't have a dependency on javax.servlet.api dependency if it is throwing a ServletException.

               

              Now I am facing another issue, it looks like autowiring is not working. Any ideas reason why this is so?

               

              Thanks

              Stephen

              • 4. Re: JBossWS + CXF + Spring + Maven triggers "java.lang.NoClassDefFoundError: javax/servlet/ServletException"
                Alessio Soldano Master

                mmh... weird, do you perhaps have the servlet api jar included in your deployment?

                • 5. Re: JBossWS + CXF + Spring + Maven triggers "java.lang.NoClassDefFoundError: javax/servlet/ServletException"
                  stephen b Newbie

                  Here are the files in my war file. Does Spring library affect CXF? The code depends on both context and web spring libraries due to context loader configured in applicationContext.xml. Is there any way to find out if some servlet jar somewhere in my file system which may affect this? I also attached my pom file. Thanks.

                   

                       0 Mon Feb 25 19:37:24 EST 2013 META-INF/

                     126 Mon Feb 25 19:37:22 EST 2013 META-INF/MANIFEST.MF

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/jboss/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/jboss/as/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/jboss/as/quickstarts/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/jboss/as/quickstarts/wshelloworld/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/myapp/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/myapp/service/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/myapp/service/connection/

                       0 Mon Feb 25 19:37:22 EST 2013 WEB-INF/lib/

                    1481 Sun Feb 24 18:35:56 EST 2013 WEB-INF/applicationContext.xml

                    2777 Mon Feb 25 19:37:20 EST 2013 WEB-INF/classes/HelloService.wsdl

                     620 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/jboss/as/quickstarts/wshelloworld/HelloWorldService.class

                    2682 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/jboss/as/quickstarts/wshelloworld/HelloWorldServiceImpl.class

                     762 Mon Feb 25 19:37:22 EST 2013 WEB-INF/classes/org/myapp/service/connection/Connection.class

                     311 Sat Feb 23 13:24:38 EST 2013 WEB-INF/faces-config.xml

                    2253 Sun Feb 24 20:41:06 EST 2013 WEB-INF/jbossws-cxf.xml

                    4467 Sun Feb 26 01:15:56 EST 2012 WEB-INF/lib/aopalliance-1.0.jar

                  60686 Thu Dec 30 22:16:34 EST 2010 WEB-INF/lib/commons-logging-1.1.1.jar

                  321190 Sat Feb 16 14:38:12 EST 2013 WEB-INF/lib/spring-aop-3.0.5.RELEASE.jar

                  53082 Sat Feb 16 14:38:10 EST 2013 WEB-INF/lib/spring-asm-3.0.5.RELEASE.jar

                  555410 Sat Feb 16 14:38:20 EST 2013 WEB-INF/lib/spring-beans-3.0.5.RELEASE.jar

                  668861 Sat Feb 16 14:38:24 EST 2013 WEB-INF/lib/spring-context-3.0.5.RELEASE.jar

                  382442 Sat Feb 16 14:38:12 EST 2013 WEB-INF/lib/spring-core-3.0.5.RELEASE.jar

                  169752 Sat Feb 16 14:38:14 EST 2013 WEB-INF/lib/spring-expression-3.0.5.RELEASE.jar

                  395587 Sat Feb 16 14:38:24 EST 2013 WEB-INF/lib/spring-web-3.0.5.RELEASE.jar

                    1673 Sun Feb 24 17:50:20 EST 2013 WEB-INF/web.xml

                       0 Mon Feb 25 19:37:24 EST 2013 META-INF/maven/

                       0 Mon Feb 25 19:37:24 EST 2013 META-INF/maven/org.jboss.as.quickstarts/

                       0 Mon Feb 25 19:37:24 EST 2013 META-INF/maven/org.jboss.as.quickstarts/jboss-as-helloworld-ws/

                  13464 Mon Feb 25 19:36:52 EST 2013 META-INF/maven/org.jboss.as.quickstarts/jboss-as-helloworld-ws/pom.xml

                     140 Mon Feb 25 19:37:24 EST 2013 META-INF/maven/org.jboss.as.quickstarts/jboss-as-helloworld-ws/pom.properties