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

标签 java web-services soap apache-camel cxf

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

相关文章:

asp.net - Web 服务问题 Asp.Net

java - 对于生产者-消费者模式哪种实现更好 : ArrayBlockingQueue or Arraylists with Exchangers

java - 更改和改进了从 Web Servlet 到 Web 服务的数据传递

c# - 无法从网络服务访问公共(public)类(class)

c# - 不知道如何创建 SOAP <wsse :Security> header

python-2.7 - 添加 CustomTransport 时忽略 SUDS header

c# - 使用 SOAP Web 引用将 C# 类编译为 .dll 错误 CS0234

java - 使用配置单元出现异常 java.lang.NoClassDefFoundError : org/apache/tez/dag/api/SessionNotRunning

java - 连接到 z/OS 上的 WebSphere MQ 的应用程序名称

java - 如何按日期和时间仅选择今天和明天的 jsonarray 数据并放入 ListView 适配器