Proxy Throw Exception org.apache.cxf.binding.soap.SoapFault: [B cannot be cast to [Ljava.lang.Object;

随声附和 提交于 2019-12-11 18:20:05

问题


I tried to proxy with POJO mode in JBOSS FUSE and the real web service is getting executed.

But the client gets following exception

Caused by: org.apache.cxf.binding.soap.SoapFault: [B cannot be cast to [Ljava.lang.Object;
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:84)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:51)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:40)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:835)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1612)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1503)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1310)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:628)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:565)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:377)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:330)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
    ... 2 more

My Blueprint.xml

I am able to invoke the real webservice using the proxy and processor.

But, the response is returned to client.

Do I need to do anything in Processor or in blueprint to handle this situation.

<cxf:cxfEndpoint xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf" id="webserviceProxy"
                     address="http://localhost:8383/service_sample_proxy/services_proxy/proxyport"
                     endpointName="tns:ComplexServiceImplPort"
                     serviceName="tns:ComplexServiceImplService"
                     serviceClass="webservice.ComplexServiceImpl"
                     wsdlURL="wsdl/complexserviceimpl.wsdl"
                   xmlns:tns="http://webservice/" />

<camelContext id="blueprintContext"
                trace="false"
                xmlns="http://camel.apache.org/schema/blueprint">

    <endpoint id="callRealWebService" uri="jetty:http://localhost:8080/service_sample/services/ComplexServiceImplPort?throwExceptionOnFailure=false"/>

        <route id="httpBridge">
        <from uri="cxf:bean:webserviceProxy?dataFormat=POJO"/>
        <process ref="requestDataProcessor"/>
        <to ref="callRealWebService"/>
    </route>
</camelContext>  

<bean id="requestDataProcessor" class="org.fusesource.example.RequestDataProcessor"/>  

My Processor.java

public class RequestDataProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {

        String temp = exchange.getIn().getBody(String.class);

    RequestData temp = exchange.getIn().getBody(RequestData.class);

    String SOAPContent = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
    "<soap:Body>"+
    "<ns2:sampleMethod xmlns:ns2=\"http://webservice/\">"+
    "<arg0>"+
    "<name>" +temp.getName()+" PROXY CONTENT</name>"+
    "<no>"+temp.getNo()+"</no>"+
    "<salary>"+temp.getSalary()+" PROXY CONTENT</salary>"+
    "</arg0>"+
    "</ns2:sampleMethod>"+
    "</soap:Body>"+
    "</soap:Envelope>";


        exchange.getOut().setBody(SOAPContent);

        exchange.getOut().setHeaders(exchange.getIn().getHeaders());

    }
}

Resonse in SOAPUI

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Server</faultcode>
         <faultstring>[B cannot be cast to [Ljava.lang.Object;</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

I got the problem, the format what the proxy receives is different. But, I dont know how to fix this.


回答1:


Instead of : String temp = exchange.getIn().getBody(String.class);

Try the following:

MessageContentsList list = exchange.getIn().getBody(MessageContentsList.class);
String temp = list.get(0);


来源:https://stackoverflow.com/questions/22702946/proxy-throw-exception-org-apache-cxf-binding-soap-soapfault-b-cannot-be-cast-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!