Using a CXF Interceptor I'd like to append some Node to the xml being sent out to the server. I've created a interceptor (see below) that picks up the message as DOM Node, modifies it and writes it back to the message object.
Unfortunately the code does not work as expected - the XML sent to the server does not contain the 'magicWord'. IMHO I'm using the wrong phase for this.
So the question is: how can I modify an outgoing webservice request using the org.w3c.dom.Node syntax?
package dummy;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
class DummyInterceptor extends AbstractPhaseInterceptor {
String magicWord = "abc";
public DummyInterceptor() {
super(Phase.PRE_PROTOCOL);
}
public void handleMessage(Message message) {
Document document = (Document) message.getContent(Node.class);
NodeList nodes = document.getElementsByTagName("wsse:Security");
if (nodes.getLength() == 1) {
Node wsseSecurityNode = nodes.item(0);
wsseSecurityNode.appendChild(document.createTextNode(magicWord));
}
message.setContent(Node.class, document);
}
}