根据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中,以上述方式发送所有参数时,它非常有效。
答案 0 :(得分:1)
哦,我有一个愚蠢的答案.. 我只是将它们添加到列表中并发送。它奏效了!
ArrayList requestBody = new ArrayList();
requestBody.add(messageHeader);
requestBody.add(security);
requestBody.add(sessionCreateRQ);
SessionCreateRS sessionCreateRS = template.requestBody(serviceEndpoint, requestBody, SessionCreateRS.class);
请分享任何更好的答案。