3 Replies Latest reply on Oct 27, 2008 12:11 AM by Rishabh Chandra

    ClassCastException in HandlerResolverImpl.addHandler

    Johannes Testori Newbie

      i have a simple webservice on jboss-4.2.0.GA with jbossws-2.0.1

      my webservice:

      package my.ws;
      
      import javax.jws.HandlerChain;
      import javax.jws.WebMethod;
      import javax.jws.WebService;
      
      @WebService
      @HandlerChain(file = "WEB-INF/jaxws-handlers.xml")
      public class MyWS {
      
       @WebMethod
       public String hello(String input) {
       return input;
       }
      
      }
      


      my handler:
      package my.ws;
      
      import javax.xml.namespace.QName;
      import javax.xml.rpc.handler.GenericHandler;
      import javax.xml.rpc.handler.MessageContext;
      
      public class MyWSHandler extends GenericHandler {
      
       public MyWSHandler() {
       super();
       }
      
       public QName[] getHeaders() {
       return new QName[] {};
       }
      
       public boolean handleRequest(MessageContext msgContext) {
       return true;
       }
      
       public boolean handleResponse(MessageContext msgContext) {
       return true;
       }
      }
      


      jaxws-handlers.xml:
      <handler-chains
       xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee javaee_web_services_1_2.xsd">
      
       <handler-chain>
       <protocol-bindings>##SOAP11_HTTP</protocol-bindings>
       <handler>
       <handler-name>Application Server Handler</handler-name>
       <handler-class>my.ws.MyWSHandler</handler-class>
       </handler>
       </handler-chain>
      
      </handler-chains>
      
      


      the exception:
      17:39:43,296 ERROR [SOAPFaultHelperJAXWS] SOAP request exception
      java.lang.ClassCastException: my.ws.MyWSHandler
       at org.jboss.ws.core.jaxws.handler.HandlerResolverImpl.addHandler(HandlerResolverImpl.java:148)
       at org.jboss.ws.core.jaxws.handler.HandlerResolverImpl.initHandlerChain(HandlerResolverImpl.java:134)
       at org.jboss.ws.core.jaxws.handler.HandlerDelegateJAXWS.callRequestHandlerChain(HandlerDelegateJAXWS.java:80)
       at org.jboss.ws.core.server.ServiceEndpointInvoker.callRequestHandlerChain(ServiceEndpointInvoker.java:126)
       at org.jboss.ws.core.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:170)
       at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:408)
       at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:272)
       at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:189)
       at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:122)
       at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java:84)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:595)
      


        • 1. Re: ClassCastException in HandlerResolverImpl.addHandler
          Alessio Soldano Master

          Your service is implemented using JAX-WS while your handler is extending the JAX-RPC handler, that could be the cause of your class cast exception. Try extending the jaxws generic handler.

          • 2. Re: ClassCastException in HandlerResolverImpl.addHandler
            Johannes Testori Newbie

            thank you. extending org.jboss.ws.core.jaxws.handler.GenericHandler works :)

            • 3. Re: ClassCastException in HandlerResolverImpl.addHandler
              Rishabh Chandra Newbie

              I am getting this problem as well when implementing jaxws on jboss421 and 423.
              As per the java spec the handler class should either implement the javax.xml.ws.handler.LogicalHandler OR javax.xml.ws.handler.SOAPHandler.

              I have a handler class that does this.

              
              package handlertest.server;
              
              import java.util.Set;
              
              import javax.xml.namespace.QName;
              import javax.xml.ws.handler.MessageContext;
              import javax.xml.ws.handler.soap.SOAPHandler;
              import javax.xml.ws.handler.soap.SOAPMessageContext;
              
              public class ServerSOAPHandler implements SOAPHandler<SOAPMessageContext> {
               private final String HANDLERNAME = "ServerSOAPHandler";
              
               public ServerSOAPHandler() {
               super();
               System.out.println(HANDLERNAME + " ServerSOAPHandler():");
               }
              
               public Set<QName> getHeaders() {
               System.out.println(HANDLERNAME + " getHeaders():");
               return null;
               }
              
               public boolean handleFault(SOAPMessageContext arg0) {
               System.out.println(HANDLERNAME + " handleFault():");
               return false;
               }
              
               public boolean handleMessage(SOAPMessageContext arg0) {
               System.out.println(HANDLERNAME + " handleMessage():");
               return false;
               }
              
               public void close(MessageContext arg0) {
               System.out.println(HANDLERNAME + " close():");
               }
              }
              


              I get the same exception when this handler is loaded. This is the stacktrace.

              java.lang.ClassCastException: handlertest.server.ServerSOAPHandler
               at org.jboss.ws.core.jaxws.handler.HandlerResolverImpl.addHandler(HandlerResolverImpl.java:148)
               at org.jboss.ws.core.jaxws.handler.HandlerResolverImpl.initHandlerChain(HandlerResolverImpl.java:134)
               at org.jboss.ws.core.jaxws.handler.HandlerDelegateJAXWS.callRequestHandlerChain(HandlerDelegateJAXWS.java:80)
               at org.jboss.ws.core.server.AbstractServiceEndpointInvoker.callRequestHandlerChain(AbstractServiceEndpointInvok
               at org.jboss.ws.core.server.AbstractServiceEndpointInvoker.invoke(AbstractServiceEndpointInvoker.java:162)
               at org.jboss.ws.core.server.ServiceEndpoint.processRequest(ServiceEndpoint.java:212)
               at org.jboss.ws.core.server.ServiceEndpointManager.processRequest(ServiceEndpointManager.java:448)
               at org.jboss.ws.core.server.AbstractServiceEndpointServlet.doPost(AbstractServiceEndpointServlet.java:114)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
               at org.jboss.ws.core.server.AbstractServiceEndpointServlet.service(AbstractServiceEndpointServlet.java:75)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              


              The proposed solution of using Generic handler from Jboss works but this is not a proper solution. To be able to work with JAXws 2 spec I need to implement the javax.xml.ws.handler.LogicalHandler. Can you please suggest what can i do here ???

              Also below are some links to jaxws 2 tutorials
              http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.wsfep.multiplatform.doc/info/ae/ae/twbs_jaxwshandler.html

              http://java.sun.com/mailers/techtips/enterprise/2006/TechTips_June06.html#1
              http://blogs.sun.com/sdimilla/entry/implementing_handlers_using_jaxws_2