How to deal with the message for a camel-cxf endpoint in PAYLOAD data format - 6.3

Talend ESB Mediation Developer Guide

Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Design and Development
Talend ESB

PAYLOAD means that you process the payload message from the SOAP envelope. You can use the Header.HEADER_LIST as the key to set or get the SOAP headers and use the List<Element> to set or get SOAP body elements.

We use the common Camel DefaultMessageImpl underlayer. Message.getBody() will return an org.apache.camel.component.cxf.CxfPayload object, which has getters for SOAP message headers and Body elements. This change enables decoupling the native CXF message from the Camel message.

protected RouteBuilder createRouteBuilder() {
   return new RouteBuilder() {
      public void configure() {
         from(SIMPLE_ENDPOINT_URI + "&dataFormat=PAYLOAD")
            .to("log:info").process(new Processor() {
            public void process(final Exchange exchange) 
            throws Exception{
               CxfPayload<SoapHeader> requestPayload = 
               List<Element> inElements = requestPayload.getBody();
               List<Element> outElements = new ArrayList<Element>();
               // You can use a customer toStringConverter to turn a 
               // CxfPayLoad message into String as you want
               String request = exchange.getIn().getBody(String.class);
               XmlConverter converter = new XmlConverter();
               String docString = ECHO_RESPONSE;
               if (inElements.get(0).getLocalName().
                  equals("echoBoolean")) {
                  docString = ECHO_BOOLEAN_RESPONSE;
                  assertEquals("Get a wrong request", 
                        ECHO_BOOLEAN_REQUEST, request);
               } else {
                  assertEquals("Get a wrong request", ECHO_REQUEST, 
               Document outDocument = converter.toDOMDocument(docString);
               // set the payload header with null
               CxfPayload<SoapHeader> responsePayload = 
                        new CxfPayload<SoapHeader>(null, outElements);