All Articles

Getting SOAP Headers using Camel CXF component

Getting SOAP headers using Camel CXF component.

Camel Route :

import org.apache.camel.builder.RouteBuilder;
 
public class SampleRoute extends RouteBuilder {
 
    @Override
    public void configure() throws Exception {
        from("cxf:bean:sampleService")
                .to("bean:sampleProcessor?method=processData")
                .log("${body}");
    }
}

Processor :

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
 
import org.w3c.dom.Element;
 
import org.apache.camel.Exchange;
import org.apache.camel.Header;
import org.apache.cxf.binding.soap.SoapHeader;
 
 
public class CustomProcessor {
 
    public void processData(
            @Header("org.apache.cxf.headers.Header.list") List<SoapHeader> soapHeaders,
            Exchange exchange) {       
 
        // Print SOAP Headers
        for (SoapHeader soapHeader : soapHeaders) {
            System.out.println(soapHeader.getName().getLocalPart() + "  : "
                             + ((Element)soapHeader.getObject()).getTextContent());
        }
 
    }
}