I have a Problem with cxf soap-headers. I set up an cxf-project with the Contract-firs-development method. I want to call a web-service with an cxf-component, which looks like this.
<cxf:cxfEndpoint id="ICCSCustomerService"
address="http://localhost:8080/iccs-xsoap/CustomerService/updateCustomer"
serviceClass="de.iccs.xsoap.customer.v1.CustomerServiceImpl" >
</cxf:cxfEndpoint>
I want to send an pojo-message throw an direct-component as an request for the ws. My route looks like this:
<route id="CustomerServiceUpdateCustomerTest">
<camel:from uri="direct:iccsUpdateCustomerRequest"/>
<camel:process ref="addCredentials"/>
<to uri="cxf:bean:ICCSCustomerService"/>
<camel:to uri="stream:out"/>
</route>
I need to implement a soap header like this one:
<ns2:Header>
<simpleAuth xmlns="http://xsoap.iccs.de/v1" password="abc" username="xxx"/>
</ns2:Header>
To archive this I wrote an processor like this one (see also example at http://camel.apache.org/cxf.html):
@Override
public void process(Exchange exchange) throws Exception {
List<SoapHeader> soapHeaders = CastUtils.cast((List<?)exchange.getOut().getHeader(Header.HEADER_LIST));
// Insert a new header
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><outofbandHeader "
+ "xmlns=\"http://cxf.apache.org/outofband/Header\" hdrAttribute=\"testHdrAttribute\" "
+ "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" soap:mustUnderstand=\"1\">"
+ "<name>simpleAuth username=\"xxx\" password=\"abc\" xmlns=\"http://xsoap.iccs.de/v1\"</name></outofbandHeader>";
SoapHeader newHeader = new SoapHeader(new QName("http://xsoap.iccs.de/v1", "simpleAuth"),
DOMUtils.readXml(new StringReader(xml)).getDocumentElement());
// make sure direction is OUT since it is a response message.
newHeader.setDirection(Direction.DIRECTION_OUT);
//newHeader.setMustUnderstand(false);
soapHeaders.add(newHeader);
}
Unfortunately I get an null-pointer Exception in this statement: List soapHeaders = CastUtils.cast((List
Obviously there are no soap-headers in this message. And it seems not to be an soap message at all. Marschaling like this
<camel:marshal>
<soapjaxb contextPath="de.iccs.xsoap.customer.v1" />
</camel:marshal>
<camel:process ref="addCredentials"/>
does not work, as it produces only an soap-envelope without an soap-header. (and of corse this dosen't work as cxf-endpoint works in pogo-mode) Could you provide me an example how to set an soap message (with soap-header) from an pojo-message.
Thank you Gabriel