Hello, using CXF 2.2.7, I'm trying to use SAAJ and a client-side interceptor
to add two elements to the header of a SOAP request. I've already
successfully done the same with a JAX-WS handler[1] and would like to do the
same with the interceptor--although I know there are non-SAAJ ways of doing
this[2].
The client-side error message I'm getting is:
[INFO] WARNING: Interceptor for
{http://www.example.org/contract/DoubleIt}DoubleItService#{http://www.example.org/contract/DoubleIt}DoubleIt
has thrown exception, unwinding now
[INFO] org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made
to insert a node where it is not permitted.
[INFO] at
com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.java:391)
[INFO] at
com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:235)
[INFO] at
com.sun.xml.messaging.saaj.soap.SOAPPartImpl.appendChild(SOAPPartImpl.java:502)
[INFO] at
org.apache.cxf.staxutils.W3CDOMStreamWriter.setChild(W3CDOMStreamWriter.java:114)
[INFO] at
org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:104)
[INFO] at
org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:132)
[INFO] at
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:122)
[INFO] at
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:81)
[INFO] at
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:61)
[INFO] at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
No logging is happening service-side within Tomcat, indicating that the
service is not being called due to this client-side interceptor exception.
Within my Client code, I have the following:
DoubleItPortType port = service.getDoubleItPort();
Client client = ClientProxy.getClient(port);
client.getOutInterceptors().add(
new SAAJOutInterceptor());
client.getOutInterceptors().add(
new ClientInterceptors.AddSOAPHeaderOutInterceptor());
...
Within my client-side interceptor, I have the following code (note that it
is almost entirely commented-out):
public class ClientInterceptors {
/*...other interceptors...*/
public static class AddSOAPHeaderOutInterceptor extends
AbstractSoapInterceptor {
public AddSOAPHeaderOutInterceptor() {
super(Phase.PRE_PROTOCOL);
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
SOAPMessage sm = message.getContent(SOAPMessage.class);
try {
SOAPFactory sf = SOAPFactory.newInstance();
SOAPHeader sh = sm.getSOAPHeader();
/*
if (sh == null) {
sh = sm.getSOAPPart().getEnvelope().addHeader();
}
Name twoTermName = sf.createName("TwoTerms", "samp",
"http://www.example.org");
SOAPHeaderElement shElement = sh
.addHeaderElement(twoTermName);
SOAPElement firstTerm = shElement.addChildElement("term");
firstTerm.addTextNode("Apple");
shElement.addChildElement(firstTerm);
SOAPElement secondTerm = shElement.addChildElement("term");
secondTerm.addTextNode("Orange");
shElement.addChildElement(secondTerm); */
} catch (SOAPException e) {
throw new Fault(e);
}
}
}
}
It is the single-line "SOAPHeader sh = sm.getSOAPHeader();" that causes this
bug to occur, if I comment it out the interceptor happily runs through (of
course, doesn't do anything because the rest of the code is commented out.)
Any idea what I might be doing wrong?
Thanks,
Glen
[1] http://www.jroller.com/gmazza/entry/jaxws_handler_tutorial#hand3
[2]
http://old.nabble.com/Adding-SOAPHeader-using-an-Interceptor-td25818665.html#a25818665
--
View this message in context:
http://old.nabble.com/Problem-having-interceptor-work-with-SAAJ-tp28459886p28459886.html
Sent from the cxf-user mailing list archive at Nabble.com.