How to set header and body for a cxf endpoint in PAYLOAD mode

Employee

How to set header and body for a cxf endpoint in PAYLOAD mode

I want to send a header body to a cxf endpoint in payload mode . Is there a code snippet or example that I can use on cProcessor in my route?
I have referred and tried below , but i am looking for sending a request to endpoint in cCXF  , instead of consuming 
https://help.talend.com/search/all?query=How+to+get+and+set+SOAP+headers+in+PAYLOAD+mode&content-lan...
One Star

Re: How to set header and body for a cxf endpoint in PAYLOAD mode

This is an example code to set a Security header (you can use any of yours). The class is generated from the WSDL schema

            Security securityHeader = new Security();
            UsernameTokenType login = new UsernameTokenType();
            login.setUsername(getUsername());
            login.setPassword(getPassword());
            securityHeader.setUsernameToken(login);
            QName headerQname = new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "sec");
            JAXBDataBinding binding = new JAXBDataBinding(Security.class);
            org.apache.cxf.binding.soap.SoapHeader soapHeader = new org.apache.cxf.binding.soap.SoapHeader(headerQname, securityHeader, binding);
            soapHeader.setDirection(Header.Direction.DIRECTION_OUT);
            CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);
            payload.getHeaders().add(soapHeader);
            exchange.getIn().setBody(payload, CxfPayload.class);

I hope this is what you've been looking after. This example assumes the route has access to the generated web service classes. If not, I believe you may use the DOM Elements as well.