通过Camel cxf组件连接SOAP端点时,无法在WrapperClassOutInterceptor上将其强制转换为java.lang.String错误

时间:2019-10-02 01:19:12

标签: java soap apache-camel camel-cxf

我正在做一个实现来调用SOAP Web服务并处理响应。

我从帖子的下面开始,当它连接到Web服务端点时出现了以下错误

错误:WrapperClassOutInterceptor上的“ com.cleverbuilder.bookservice.GetBook无法转换为java.lang.String”。

这可能是什么原因?

请注意,http://localhost:8423/test/BookService正常运行。我在SOAP路由器外部进行了测试,并且在那里工作正常。

就像在日志中突出显示以下内容

  • BodyType:com.cleverbuilder.bookservice.GetBook,
  • 正文:

    <?xml
       version="1.0" encoding="UTF-8" standalone="yes"?><ns2:GetBook
       xmlns:ns2="http://www.cleverbuilder.com/BookService/">   
       <ID>12345</ID></ns2:GetBook>,
    
  • 输出:空

日志:

06:28:32,381 INFO  [output >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 5] (default task-1) Exchange[Id: ID-namal-pc-1569977860461-1-1, ExchangePattern: InOut, Properties: {CamelCreatedTimestamp=Wed Oct 02 06:28:32 IST 2019, CamelExternalRedelivered=false, CamelFilterMatched=true, CamelMessageHistory=[DefaultMessageHistory[routeId=route7, node=choice8], DefaultMessageHistory[routeId=route7, node=to23], DefaultMessageHistory[routeId=route5, node=to11], DefaultMessageHistory[routeId=route5, node=setBody1], DefaultMessageHistory[routeId=route5, node=to12], DefaultMessageHistory[routeId=route5, node=bean1], DefaultMessageHistory[routeId=route5, node=to13], DefaultMessageHistory[routeId=route5, node=setHeader1], DefaultMessageHistory[routeId=route5, node=to14], DefaultMessageHistory[routeId=route5, node=setHeader2], DefaultMessageHistory[routeId=route5, node=to15]], CamelToEndpoint=log://output%20%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%3E%205?showAll=true}, Headers: {breadcrumbId=ID-namal-pc-1569977860461-1-1, clientId=magnify, doLogFiles=false, dontLogErrorFiles=false, messageId=soapExecutor, messageName=SOAPExecutor, operationName=GetBook, operationNamespace=http://www.cleverbuilder.com/BookService/, routeId=direct-soap, specialRq=true, uber-trace-id=, uberctx-user-name=null, useCommonService=false}, BodyType: com.cleverbuilder.bookservice.GetBook, Body: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:GetBook xmlns:ns2="http://www.cleverbuilder.com/BookService/">    <ID>12345</ID></ns2:GetBook>, Out: null: ]
06:28:32,424 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (default task-1) Interceptor for {http://www.cleverbuilder.com/BookService/}BookServicePortImplService#{http://www.cleverbuilder.com/BookService/}GetBook has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: com.cleverbuilder.bookservice.GetBook cannot be cast to java.lang.String
    at org.apache.cxf.jaxws.interceptors.WrapperClassOutInterceptor.handleMessage(WrapperClassOutInterceptor.java:107)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:537)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:439)
    at org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:133)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:138)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
    at org.apache.camel.component.direct.DirectBlockingProducer.process(DirectBlockingProducer.java:53)
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
    at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
    at org.apache.camel.component.direct.DirectBlockingProducer.process(DirectBlockingProducer.java:53)
    at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:186)
    at org.apache.camel.processor.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:86)
    at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:541)
    at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:506)
    at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:369)
    at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:506)
    at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:264)
    at org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeaders(DefaultProducerTemplate.java:355)

SoapRouter.java @ApplicationScoped @ContextName(“ camel_cdi_context”) 公共类SoapRouter扩展了RouteBuilder {

@Override
public void configure() throws Exception {

    from("direct:soap")

        .to("log:output >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 1?showAll=true")
            .setBody(constant("12345"))

        .to("log:output >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2?showAll=true")
            .bean(GetBookRequestBuilder.class)

        .to("log:output >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3?showAll=true")
            .setHeader(CxfConstants.OPERATION_NAME, constant("GetBook"))

        .to("log:output >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 4?showAll=true")
            .setHeader(CxfConstants.OPERATION_NAMESPACE, constant("http://www.cleverbuilder.com/BookService/"))

        .to("log:output >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 5?showAll=true")

        .to("cxf://http://localhost:8423/test/BookService?serviceClass=com.cleverbuilder.bookservice.BookService&wsdlURL=/wsdl/BookService.wsdl")

        .to("log:output >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 6?showAll=true");

}

}

GetBookRequestBuilder.java 公共类GetBookRequestBuilder {

public GetBook getBook(String id) {
    GetBook request = new GetBook();
    request.setID(id);

    return request;
}

}

1 个答案:

答案 0 :(得分:0)

我找到了一个dataDATA = PAYLOAD的选项,如下所述。无论如何都可以打开以获得更多选项。

对于SoapJaxbDataFormat,您将需要导入骆驼肥皂依赖性。

例如:

String WS_URI = "cxf://http://myserver/customerservice?serviceClass=com.example.customerservice&dataFormat=MESSAGE";
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:customerServiceClient")
  .onException(Exception.class)
    .handled(true)
    .unmarshal(soapDF)
  .end()
  .marshal(soapDF)
  .to(WS_URI)
  .unmarshal(soapDF);