按照 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/