CXF web service ClassCastException on assignment of return type when using WS-Reliable Messaging

1.2k Views Asked by At

I have a WSDL-first web service that is using CXF 2.7.6, using Wrapped-style. The getState web service interface method returns an int value. However, when I call the web service from my CXF client code, I usually get a ClassCastException with the message 'can't cast a GetStateResponse object to an Integer'. I say usually because the ClassCastException does not occur every time I make the web service call. I also intermittently get a similar ClassCastException on calls to other methods in the web service interface. Interestingly, this exception only occurs with WS-Reliable Messaging configured. We are deploying on a JBoss EAP 6 server but are using the CXF libraries directly (rather than using JBoss' built-in webservices subsystem)

I'm able to work-around the issue by assigning the return value to an Object and then determining its type and handling it accordingly, but this is a definite hack and I'd like to find the root cause of the issue. Below are excerpts from the WSDL, schema and interface class.

WSDL excerpts:

<wsdl:definitions>
    <wsdl:message name="getState">
        <wsdl:part name="parameters" element="msgs:getState"/>
    </wsdl:message>

    <wsdl:portType>
        <wsdl:operation name="getState">
            <wsdl:input name="getState" message="tns:getState"/>
            <wsdl:output name="getStateResponse" message="tns:getStateResponse"/>
            <wsdl:fault name="SOAPFaultException" message="tns:SOAPFaultException"/>
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding>
        <wsdl:operation name="getState">
            <soap:operation soapAction="" style="document"/>
            <wsdl:input name="getState">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="getStateResponse">
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="SOAPFaultException">
                <soap:fault name="SOAPFaultException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
</wsdl:definitions>

SCHEMA referenced with 'msgs:' prefix above:

<xs:element name="getState" type="tns:getState"/>

<xs:complexType name="getState">
    <xs:sequence>
        <xs:element minOccurs="0" name="param1" type="xs:string" />
        <xs:element minOccurs="0" name="param2" type="xs:string" />
    </xs:sequence>
</xs:complexType>

INTERFACE CLASS:

@WebResult(name = "return", targetNamespace = "")
@RequestWrapper(localName = "getState", targetNamespace = "http://messages.space.my.name", className = "my.name.space.GetState")
@WebMethod
@ResponseWrapper(localName = "getStateResponse", targetNamespace = "http://messages.space.my.name", className = "my.name.space.GetStateResponse")
public int getState(
@WebParam(name = "param1", targetNamespace = "")
java.lang.String param1,
@WebParam(name = "param2", targetNamespace = "")
java.lang.String param2) throws SOAPFaultException;

Spring jaxws client configuration:

<jaxws:client id="wsProxy" serviceClass="my.name.space.IWebServiceInterface">
    <jaxws:inInterceptors>
        <bean id="loggingInInterceptor" 
              class="org.apache.cxf.interceptor.LoggingInInterceptor" >
            <property name="prettyLogging" value="true" />
        </bean>
        <ref bean="rmLogicalIn"/>
        <ref bean="rmCodec"/>
    </jaxws:inInterceptors>
    <jaxws:outInterceptors>
        <bean id="loggingOutInterceptor" 
              class="org.apache.cxf.interceptor.LoggingOutInterceptor" >
            <property name="prettyLogging" value="true" />
        </bean>
        <ref bean="rmLogicalOut"/>
        <ref bean="rmCodec"/>
    </jaxws:outInterceptors>
</jaxws:client>

Stack trace:

[33m [0m [31m00:39:20,589 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/TEST_GUI].[jsp]] (ajp-/0.0.0.0:8009-9) JBWEB000236: 
Servlet.service() for servlet jsp threw exception: java.lang.ClassCastException: my.name.space.messages.GetStateResponse cannot be cast to java.lang.Integer [0m
[31m    at $Proxy139.getState(Unknown Source)   at org.apache.jsp.client.framework.MWS_005fTEST_jsp.waitForState(MWS_005fTEST_jsp.java:166) [0m
[31m    at org.apache.jsp.client.framework.MWS_005fTEST_jsp._jspService(MWS_005fTEST_jsp.java:508) [0m
[31m    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1] [0m
[31m    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:365) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1] [0m
[31m    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at mil.jpmis.cbrnis.client.framework.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:148) [TESTGUI.jar:] [0m
[31m    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.event(JBossWebContext.java:91) [0m
[31m    at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.invoke(JBossWebContext.java:72) [0m
[31m    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:512) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.4.3.Final-redhat-2.jar:7.4.3.Final-redhat-2] [0m
[31m    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:490) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:420) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926) [jbossweb-7.4.10.Final-redhat-1.jar:7.4.10.Final-redhat-1] [0m
[31m    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0]

I also posted this on the cxf-users Nabble list, but no response yet. Any help would be appreciated!

1

There are 1 best solutions below

0
On

Update, and to respond to @gnzlrm in the comment above, if I recall correctly (this was over 2 years ago) we never did isolate the cause of this issue, but we did find when we updated to a later version of CXF we no longer saw the issue (I believe 2.7.13 and up worked but we ended up updating to 3.1.7).