namalfernandolk
namalfernandolk

Reputation: 9134

Send multiple parameters as the requestBody using Apache Camel ProdcerTemplate with CxfComponent

As per the instructions mentioned in here and with the help of some other sources, I have created a SoapClient to send a SOAP request and get a response using Apahe Camel.

Code :

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);

Adjuscent JAX-WS invocation :

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

This is working fine for the Web Services expecting only one parameters as the request body. I want to know how I can send multiple parameters as the request body? (I tired requestBodyAndHeader, assyncRequestBodyAndHeader etc).

Adjuscent JAX-WS invocation :

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.

In this case, it always looks for the messageHeader as the request body I don't know how to send the other parameters using Producertemplate with CXFContext. In JAX-WS it is perfectly working when sending all parameters in above way.

Upvotes: 1

Views: 1675

Answers (1)

namalfernandolk
namalfernandolk

Reputation: 9134

Oh I had a dumb answer.. I simply added them to a list and sent. It worked!

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

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

Please share any better answer.

Upvotes: 1

Related Questions