views:

965

answers:

1

I have some SOAP webservices build with JAX-RPC. These work fine. But as soon as I add a handler, I get an exception. When the binding is removed from the webservices.xml, everything works fine again.

The weird thing is, the handler itself isn't included in the stacktrace of the exception. I also noticed, the init and getHeaders methods of the handler are called, before the exception is raised.

The handler is added to webservices.xml with the following xml:

<handler>
  <handler-name>My Message Handler</handler-name>
  <handler-class>kpn.MyMessageHandler</handler-class>
</handler>

The handler itself is just a stub, generated by the IDE from the interface, so I won't include the whole implementation:

public class MyMessageHandler implements javax.xml.rpc.handler.Handler {
  @Override
  public boolean handleRequest(MessageContext context) {
    System.out.println("handel-Request");
    return true;
  }
  ...
}

This actually generates three exceptions in my logging (with the exact same timestamp). Because of the length, I only include a portion.

Log Level  WARNING 
Logger  javax.enterprise.system.container.web 
Message ID  preWebHandlerError java.lang.ClassCastException 
Complete Message  com.sun.xml.messaging.saaj.soap.impl.TextImpl cannot be cast to javax.xml.soap.SOAPElement at
    com.sun.xml.rpc.server.StreamingHandler.getOpcodeForRequestMessage(StreamingHandler.java:657) at
    com.sun.enterprise.webservice.WsUtil.getInvMethod(WsUtil.java:1277) at
    com.sun.enterprise.webservice.ServletPreHandler.handleRequest(ServletPreHandler.java:86) at
    com.sun.xml.rpc.client.HandlerChainImpl.handleRequest(HandlerChainImpl.java:103) at
    com.sun.xml.rpc.server.StreamingHandler.callRequestHandlers(StreamingHandler.java:962) at
    com.sun.xml.rpc.server.StreamingHandler.preHandlingHook(StreamingHandler.java:868) at
    kpn.kpc.SOAPKPCReadCustomerClassification_v01PortType_Tie.preHandlingHook(SOAPKPCReadCustomerClassification_v01PortType_Tie.java:242) at
    com.sun.xml.rpc.server.StreamingHandler.handle(StreamingHandler.java:127) at
    com.sun.xml.rpc.server.http.JAXRPCServletDelegate.doPost(JAXRPCServletDelegate.java:467) at
    com.sun.enterprise.webservice.JAXRPCServlet.doPost(JAXRPCServlet.java:119) at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:738) at
    ...

Log Level  SEVERE 
Logger  com.sun.xml.rpc.server 
Message ID  com.sun.xml.messaging.saaj.soap.impl.TextImpl cannot be cast to javax.xml.soap.SOAPBodyElement java.lang.ClassCastException 
Complete Message  com.sun.xml.messaging.saaj.soap.impl.TextImpl cannot be cast to javax.xml.soap.SOAPBodyElement at
    com.sun.enterprise.webservice.WsUtil.throwSOAPFaultException(WsUtil.java:1312) at
    com.sun.enterprise.webservice.WsUtil.throwSOAPFaultException(WsUtil.java:1288) at
    com.sun.enterprise.webservice.ServletPreHandler.handleRequest(ServletPreHandler.java:99) at
    ...

Log Level  SEVERE 
Logger  com.sun.xml.rpc.server 
Message ID  JAXRPCTIE01 
Complete Message  caught exception while handling request: java.lang.ClassCastException: com.sun.xml.messaging.saaj.soap.impl.TextImpl cannot be cast to javax.xml.soap.SOAPBodyElement java.lang.ClassCastException: com.sun.xml.messaging.saaj.soap.impl.TextImpl cannot be cast to javax.xml.soap.SOAPBodyElement at
    com.sun.enterprise.webservice.WsUtil.throwSOAPFaultException(WsUtil.java:1312) at
    com.sun.enterprise.webservice.WsUtil.throwSOAPFaultException(WsUtil.java:1288) at
    com.sun.enterprise.webservice.ServletPreHandler.handleRequest(ServletPreHandler.java:99) at
    ...

Anyone got some ideas to solve this?

+1  A: 

Your libraries are in an incompatible state.

The important part is: java.lang.ClassCastException: com.sun.xml.messaging.saaj.soap.impl.TextImpl cannot be cast to javax.xml.soap.SOAPBodyElement

This means that either the jre contains an implementation for javax.xml (ie jre 6.0), or the glassfish contains a runtime with a newer implementation or you include a library that is not compatible.

Someone broke the xml implementation between 1.4 -> 1.5. I suggest a search in all the jars for javax.xml.soap.SOAPBodyElement. You'll find duplicates which are not compatible (eg xml-beans stax or something).

This makes some sence. When the SOAP request body doesn't include whitespace between the elements, everything works fine...
doekman