How to propagate a camel-cxf endpoint's request and response context - 6.3

Talend ESB Mediation Developer Guide

EnrichVersion
6.3
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
EnrichPlatform
Talend ESB

CXF client API provides a way to invoke the operation with request and response context. If you are using a camel-cxf endpoint producer to invoke the outside web service, you can set the request context and get response context with the following code:

CxfExchange exchange = 
   (CxfExchange)template.send(getJaxwsEndpointUri(), new Processor() {
   public void process(final Exchange exchange) {
      final List<String> params = new ArrayList<String>();
      params.add(TEST_MESSAGE);
      // Set the request context to the inMessage
      Map<String, Object> requestContext = 
         new HashMap<String, Object>();
      requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
         JAXWS_SERVER_ADDRESS);
      exchange.getIn().setBody(params);
      exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext);
      exchange.getIn().setHeader(
         CxfConstants.OPERATION_NAME, GREET_ME_OPERATION);
   }
});

org.apache.camel.Message out = exchange.getOut();
// The output is an object array, 
// the first element of the array is the return value
Object\[\] output = out.getBody(Object\[\].class);
LOG.info("Received output text: " + output\[0\]);
// Get the response context form outMessage
Map<String, Object> responseContext = 
   CastUtils.cast((Map)out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
assertEquals("Get the wrong wsdl opertion name", 
   "{http://apache.org/hello_world_soap_http}greetMe",
   responseContext.get("javax.xml.ws.wsdl.operation").toString());