cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glen Mazza <glen.ma...@gmail.com>
Subject Re: Problem having interceptor work with SAAJ
Date Thu, 06 May 2010 17:48:16 GMT

Thanks, that fixed it.

Glen


dkulp wrote:
> 
> 
> Most likely, you need to move your interceptor down in the chain a little,
> at 
> least beyond the SoapOutInterceptor.   The SoapOutInterceptor would be 
> responsible for setting up and creating the SOAP:Envelope and Body and
> such, 
> but with your interceptor running before it, the call to
> sm.getSOAPHeader() 
> already creates those and they kind of blow up trying to add additional
> nodes.
> 
> Dan
> 
> 
> On Wednesday 05 May 2010 7:59:24 am Glen Mazza wrote:
>> 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.examp
>> le.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(CoreDo
>> cumentImpl.java:391) [INFO] 	at
>> com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:2
>> 35) [INFO] 	at
>> com.sun.xml.messaging.saaj.soap.SOAPPartImpl.appendChild(SOAPPartImpl.java:
>> 502) [INFO] 	at
>> org.apache.cxf.staxutils.W3CDOMStreamWriter.setChild(W3CDOMStreamWriter.jav
>> a:114) [INFO] 	at
>> org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.jav
>> a:104) [INFO] 	at
>> org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamW
>> riter.java:132) [INFO] 	at
>> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelop
>> eStart(SoapOutInterceptor.java:122) [INFO] 	at
>> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(So
>> apOutInterceptor.java:81) [INFO] 	at
>> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(So
>> apOutInterceptor.java:61) [INFO] 	at
>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
>> n.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.htm
>> l#a25818665
> 
> -- 
> Daniel Kulp
> dkulp@apache.org
> http://dankulp.com/blog
> 
> 

-- 
View this message in context: http://old.nabble.com/Problem-having-interceptor-work-with-SAAJ-tp28459886p28477337.html
Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message