How to get and set SOAP headers in PAYLOAD mode - 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

We've already shown how to access SOAP message (CxfPayload object) in PAYLOAD mode (See "How to deal with the message for a camel-cxf endpoint in PAYLOAD data format").

In 2.x Once you obtain a CxfPayload object, you can invoke the CxfPayload.getHeaders() method that returns a List of DOM Elements (SOAP headers).

from(getRouterEndpointURI()).process(new Processor() {
   @SuppressWarnings("unchecked")
   public void process(Exchange exchange) throws Exception {
      CxfPayload<SoapHeader> payload = 
         exchange.getIn().getBody(CxfPayload.class);
      List<Element> elements = payload.getBody();
      assertNotNull("We should get the elements here", elements);
      assertEquals("Get the wrong elements size", 1, elements.size());
      assertEquals("Get the wrong namespace URI", 
         "http://camel.apache.org/pizza/types", 
         elements.get(0).getNamespaceURI());
            
      List<SoapHeader> headers = payload.getHeaders();
      assertNotNull("We should get the headers here", headers);
      assertEquals("Get the wrong headers size", headers.size(), 1);
      assertEquals("Get the wrong namespace URI", 
         ((Element)(headers.get(0).getObject())).getNamespaceURI(), 
         "http://camel.apache.org/pizza/types");         
   }  
})
.to(getServiceEndpointURI());