gpt4 book ai didi

java - 通过 Camel cxf 组件连接 SOAP 端点时,无法在 WrapperClassOutInterceptor 处转换为 java.lang.String 错误

转载 作者:行者123 更新时间:2023-12-01 23:58:09 25 4
gpt4 key购买 nike

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

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

错误:“com.cleverbuilder.bookservice.GetBook 无法在 WrapperClassOutInterceptor 处转换为 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”)公共(public)类 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公共(public)类 GetBookRequestBuilder {

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

return request;
}

}

最佳答案

我找到了一个使用 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);

关于java - 通过 Camel cxf 组件连接 SOAP 端点时,无法在 WrapperClassOutInterceptor 处转换为 java.lang.String 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58194093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com