3 Replies Latest reply on Jun 25, 2010 3:41 AM by Alessio Soldano

    ClassCastException: MyImpl cannot be cast to javax.servlet.Servlet

    Chet Vora Newbie

      Hi all,


      I'm trying to get the sample application from http://www.ibm.com/developerworks/java/library/j-jws13.html to work on JBoss Enterprise 5.0.0RC1 with Apache CXF integration (jbossws-cxf-3.2.2.GA). 

       

      I could get it to work using CXF servlet (after a few tweaks which took me some time to figure out).

       

      But when I try to use the CXF integration using jbossws-cxf.xml, I am running into this error:

       

      2010-06-14 14:09:35,595 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/cxf-library-username-jboss].[CXFLibrary]] (http-127.0.0.1-8080-1) Allocate exception for servlet CXFLibrary

      java.lang.ClassCastException: com.sosnoski.ws.library.cxf.CXFLibraryImpl cannot be cast to javax.servlet.Servlet
          at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1006)
          at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:777)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
          at java.lang.Thread.run(Thread.java:619)

       

      These are the changes I made to use the JBoss-CXF integration.

       

      * removed cxf-servlet.xml from war WEB-INF and replaced with jbossws-cxf.xml

       

      * changed web.xml to this based on the testcases inside of jbossws-cxf-src-dist

       

         <servlet>
            <servlet-name>CXFLibrary</servlet-name>
            <servlet-class>com.sosnoski.ws.library.cxf.CFXLibraryImpl</servlet-class>
         </servlet>
         <servlet-mapping>
            <servlet-name>CXFLibrary</servlet-name>
            <url-pattern>/*</url-pattern>
         </servlet-mapping>

      * commented out all references to CxfServlet from web.xml

       

      This is what my jbossws-cxf.xml looks like:

       

      <beans
        xmlns='http://www.springframework.org/schema/beans'
        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
        xmlns:beans='http://www.springframework.org/schema/beans'
        xmlns:jaxws='http://cxf.apache.org/jaxws'
        xsi:schemaLocation='http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxws
        http://cxf.apache.org/schemas/jaxws.xsd'>

       

        <!-- one or more jaxws:endpoint POJO declarations -->
        <jaxws:endpoint
          id='Processor'
          address='http://localhost:8080/cxf-library-username'
          wsdlLocation="WEB-INF/wsdl/library-username.wsdl"
          implementor='com.sosnoski.ws.library.cxf.CXFLibraryImpl'>
            <jaxws:properties>
              <entry key="ws-security.callback-handler"
                  value="com.sosnoski.ws.library.cxf.ServerCallback"/>
            </jaxws:properties>

       

          <jaxws:invoker>
            <bean class='org.jboss.wsf.stack.cxf.InvokerJSE'/>
          </jaxws:invoker>
        </jaxws:endpoint>

       

      </beans>

       

       

      My impl POJO is annotated as such (this works with cxf-servlet.xml and i didn't change it for Jbossws-cxf ):

       

      @javax.jws.WebService(endpointInterface="com.sosnoski.ws.library.cxf.Library",
          portName="library", targetNamespace="http://ws.sosnoski.com/library/wsdl",
              wsdlLocation = "WEB-INF/wsdl/library-username.wsdl",
          serviceName="CXFLibrary")

       

      and this is how the wsdl references it.

       

      <wsdl:service name="CXFLibrary">

       

          <wsdl:port binding="wns:LibrarySoapBinding" name="library">
            <wsdlsoap:address location="http://localhost:8080/cxf-library-username"/>
          </wsdl:port>

       

        </wsdl:service>

       

      Let me know if I can provide any more details. I'm really bummed as to why it doesn't work.

       

      Thanks in advance for your help.

      CV

        • 1. Re: ClassCastException: MyImpl cannot be cast to javax.servlet.Servlet
          Alessio Soldano Master

          I believe there might be something wrong in the way the JBossWS-CXF is installed there, as I don't see anything special in your application that would cause jbossweb to try deploying it a common webapp instead of a ws endpoint. Basically, what's happening is that the jbossws deployer does not seem to have been run.

          So, first of all, what do you mean with JBoss Enterprise 5.0.RC1 ? Is that JBoss Enterpise Application Platform 5 (EAP5)? If it's that, I'm wondering why you're not using the final release. Moreover, there's a EAP 5.0 version with CXF already installed (currently tech preview), if you're a customer with valid support you should have access to that too.

          How did you install the jbossws-cxf 3.2.2 ? Did you run the installer from the binary distribution? Please note that, even if afaik you should actually not be allowed to change the ws stack in EAP without invalidating the support, the target to provide for trying using the community version of jbossws there is "jboss510".

          You might want to do a couple of quick checks:

          - try building the testsuite from the src dist ("mvn -Ptestsuite,jbossXYZ test", see http://community.jboss.org/wiki/JBossWS-BuildingFromSource in any case) and deploy one of the samples that are similar to your usecase (for instance the jaxws-samples-wsse-sign.war); those are meant to work and tested against the supported target container before release, so you can use them a) for verifying the installation is ok, b) as a starting point for developing your apps

          - try downloading a vanilla JBoss AS 6 M3 (community version), install JBossWS-CXF 3.3.1.GA on top of that, and try both your app and the samples mentioned above

          • 2. Re: ClassCastException: MyImpl cannot be cast to javax.servlet.Servlet
            Chet Vora Newbie

            Alessio

             

            On the RHN site, 5 EAP is what seems to be the latest official version, as far as I could tell. Also, I couldn't locate the CXF bundled version. Again, its possible I'm looking in the wrong place. Do you happen to know where this bundled version is?

             

            I installed CXF by running the ant install from the binary distribution. I picked 500 as the choice of version.

             

            I'll try out the few changes you suggested to see if I can get things to work.

             

            Thanks!

            • 3. Re: ClassCastException: MyImpl cannot be cast to javax.servlet.Servlet
              Alessio Soldano Master

              Chet Vora wrote:

               

              Alessio

               

              On the RHN site, 5 EAP is what seems to be the latest official version, as far as I could tell. Also, I couldn't locate the CXF bundled version. Again, its possible I'm looking in the wrong place. Do you happen to know where this bundled version is?

              Honestly, I don't know exactly. Try asking for the EAP 5 CXF Tech preview to the support / your Red Hat product contact.

               

              I installed CXF by running the ant install from the binary distribution. I picked 500 as the choice of version.

              Technically speaking, the version that would probably work is 510, as the number refers to the community AS versions. I said "probably", because -again- you're trying to install a community version on top of the product, which is not a supported procedure.

               

              I'll try out the few changes you suggested to see if I can get things to work.

              Any news here?