当前位置: 首页 > 知识库问答 >
问题:

通过Camel cxf组件连接SOAPendpoint时,无法强制转换为WrapperClassOutInterceptor上的java.lang.字符串错误

李洋
2023-03-14

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

我从下面的帖子开始,当它连接到web服务endpoint时,我遇到了下面的错误

  • https://tomd.xyz/articles/camel-soap-service/

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

这可能是什么原因?

请注意http://localhost:8423/test/BookService已经启动,工作正常。我在SOAP路由器外面进行了测试,它在那里工作得很好。

喜欢在下面的日志中突出显示

>

<?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\u cdi\u 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");

}

}

GetBookRequest estBuilder.java公共类GetBookRequest estBuilder{

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

    return request;
}

}

共有1个答案

艾璞瑜
2023-03-14

我想出了一个选项与dataFormat=PAYLOAD如下所述。无论如何,打开更多选项。

对于SoapJaxbDataFormat,需要导入camel-soap依赖项。

如:

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);
 类似资料:
  • 问题内容: 我正在编写一些代码,并且我需要它来捕获参数并将它们传递给 我(我想要它的默认行为,编写由空格分隔并后跟换行符的参数)。但是它需要而返回。 这是代码示例: 这将返回以下错误: 这是一个错误吗?不应该接受 任何 数组吗?顺便说一句,我也尝试这样做: 但出现以下错误: 有“解决方案”解决方法吗? 问题答案: 这不是错误。需要一个类型。这意味着它必须是值的切片,而不是“任何切片”。为了转换切片

  • 当我运行这个程序时,我得到了这个错误。我不知道怎么解决。请帮我找到它。 代码:

  • 我试图反序列化从Web API接收的JSON字符串 然而,它给出了一个错误:无法强制转换或转换系统。字符串到App1。ApiResult

  • 大家好,我的问题是我为android开发了一个应用程序,它使用json解析器从我的php Web服务中获取数据并将其显示在listview中,但当我运行该应用程序时,它显示了以下内容: 日志: 我的代码: 具有列表视图的活动并调用json解析器: Json解析器在这个我只改变了这一行BufferedReader=new BufferedReader(new InputStreamReader(is

  • 我在尝试使用nokogiri运行rake任务时遇到这个错误。 编辑:顶部表架构

  • 我正在尝试加入一个名单: 这不编译说: 然而,这并不抱怨: 有人能给我解释一下原因吗?对于和之间的区别,我也很感激一些说教性的解释,因为我认为我没有理解对。