I have implemented a SOAP client in Java using Apache CXF (with wsdl2java). I have been asked to extend the soap header with a custom header block. This is how the header should look like:
The WS-Security and WS-Addressing is already in place, I have used the built-in functionality in CXF for this (e.g WSS4JOutInterceptor).
The custom block should be structured like this:
<customHeader xmlns:func="http://...." xmlns="http://....">
<customElement>
<customValue>....</customValue>
</customElement>
</customHeader>
I'm not sure how to add the custom header block. I'm looking at implementing the AbstractSoapInterceptor:
public class CustomHeaderInterceptor extends AbstractSoapInterceptor {
public CustomHeaderInterceptor() {
super(Phase.WRITE);
getAfter().add(WSS4JOutInterceptor.class.getName());
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
....
}
}
However I'm not sure exactly what to do here. I also notice that the message.getHeaders() is empty. I tried the Phase.SEND too, and the header list is still empty. The order of the headers needs to be as described above. Am I on the wrong track here? Any input on how to get this right would be appreciated!
Created the custom header using JAXB annotations and added it to the header list in the WRITE phase. Even though the header list is empty at this point, the custom header was added in the correct order.