gpt4 book ai didi

java - 使用 Apache Camel ProdcerTemplate 和 CxfComponent 发送多个参数作为 requestBody

转载 作者:行者123 更新时间:2023-11-30 07:14:26 28 4
gpt4 key购买 nike

按照 here 中提到的说明在其他一些来源的帮助下,我创建了一个 SoapClient 来发送 SOAP 请求并使用 Apahe Camel 获取响应。

代码:

CamelContext context = new DefaultCamelContext();

CxfComponent cxfComponent = new CxfComponent(context);
CxfEndpoint serviceEndpoint =
new CxfEndpoint("http://www.webservicex.net/stockquote.asmx", cxfComponent);

serviceEndpoint.setServiceClass(StockQuoteSoap.class);

ProducerTemplate template = context.createProducerTemplate();

String getQuoteResponse = template.requestBody(serviceEndpoint, "test123", String.class);

System.out.println(getQuoteResponse);

调整 JAX-WS 调用:

String response = stockQuoteSoap.getQuote("test123")    // stockQuoteSoap is created with JaxWsProxyFactoryBean using the ServiceClass StockQuoteSoap

这对于只需要一个参数作为请求正文的 Web 服务来说工作得很好。我想知道如何发送多个参数作为请求正文? (我厌倦了 requestBodyAndHeader、assyncRequestBodyAndHeader 等)。

调整 JAX-WS 调用:

SessionCreateRS sessionCreateRS = sessionCreatePortType.sessionCreateRQ(messageHeader, securityHeader, sessionCreateRQ);  // sessionCreatePortType is created with JaxWsProxyFactoryBean using the ServiceClass SessionCreatePortType. messageHeader, securityHeader, sessionCreateRQ are in the type of WS generated with cxf-codegen-plugging.

在这种情况下,它总是查找 messageHeader 作为请求正文,我不知道如何使用 Producertemplate 和 CXFContext 发送其他参数。在 JAX-WS 中,以上述方式发送所有参数时,它可以完美工作。

最佳答案

哦,我有一个愚蠢的答案..我只是将它们添加到列表中并发送。成功了!

ArrayList requestBody = new ArrayList();
requestBody.add(messageHeader);
requestBody.add(security);
requestBody.add(sessionCreateRQ);

SessionCreateRS sessionCreateRS = template.requestBody(serviceEndpoint, requestBody, SessionCreateRS.class);

请分享更好的答案。

关于java - 使用 Apache Camel ProdcerTemplate 和 CxfComponent 发送多个参数作为 requestBody,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38689329/

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