cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <dk...@apache.org>
Subject Re: Add SOAP header element using an interceptor
Date Wed, 21 Mar 2012 14:54:56 GMT
On Wednesday, March 21, 2012 03:22:11 PM Jose Noheda wrote:
> Hi,
> 
> Thx, that was it. Unfortunately I can't use your preferred solution
> because I'm porting a legacy JAX-RPC handler and I need to reuse an
> abstract class. The class in question generates a SOAPElement and then in
> JAX-RPC, it was appended using
> 
> *header.addChildElement(soapElement);*
> 
> I'm replicating the exact behavior in CXF/JAX-WS but SOAPOutInterceptor is
> throwing an exception in the *writeSoapEnvelopeStart(message);* method
> (same problem I was facing when using the jaxws handler):
> 
> *Caused by: org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt
> was made to insert a node where it is not permitted*
> 
> Is there any problem I'm not aware of here? How should I add an element to
> the header tag?

You're likely using an old version of SAAJ.   Can you check your SAAJ 
implementation?   Update to the latest saaj-impl if at all possible.

You can also TRY with the latest CXF 2.6.0-SNAPSHOT code.   I made a bunch 
of changes for 2.6.0 to allow it to better tolerate older SAAJ 
implementations.   That may help.

Alternatively, if you have the soapElement, just do:

 message.getHeaders().add(
     new Header(soapElement.getQName(), soapElement));

and don't deal with the SAAJ stuff at all.


Dan



> 
> Regards
> 
> On Wed, Mar 21, 2012 at 2:53 PM, Daniel Kulp <dkulp@apache.org> wrote:
> > On Wednesday, March 21, 2012 02:09:56 PM Jose Noheda wrote:
> > > Hi,
> > > 
> > > Looking at
> > > http://www.jroller.com/gmazza/entry/jaxwshandlers_to_cxfinterceptors
> > > it
> > > should be very simple to add a new header to a SOAP message.
> > > Unfortunately, my CXF message always return null when I ask for the
> > > SOAPMessage. Here's the code:
> > > 
> > > *    public SecurityOutInterceptor() {
> > > 
> > >         super(Phase.PRE_PROTOCOL); // Tried other Phases as well
> > >     
> > >     }
> > >     
> > >     protected SOAPHeader getSOAPHeader(SoapMessage message) throws
> > > 
> > > SOAPException {
> > > 
> > >         SOAPMessage soapMessage =
> > >         message.getContent(SOAPMessage.class);
> > >         return soapMessage.getSOAPHeader();
> > >     
> > >     }*
> > > 
> > > It always throws a NullPointerException. I've tried using a Handler
> > > instead of an interceptor to no avail (*SoapOutInterceptor* throws an
> > > exception when wirting the envelope for some unkown reason). Can
> > > someone
> > > spot the problem?
> > 
> > This would only work if you also configure in the SAAJOutInterceptors. 
> > By default, we don't create the SOAPMessage unless asked for.
> > 
> > The best option is  to just do:
> > 
> > message.getHeaders().add(
> > 
> >   new Header(qname, domElement));
> > 
> > if you do that fairly early in the interceptor chain, the domElement
> > would be streamed out at the appropriate time.
> > 
> > Dan
> > 
> > > Any help is appreciatted, thanks in advance.
> > > 
> > > Regards
> > > 
> > > PS: The client is created
> > > 
> > >     <jaxws:client id="fooClientProxy" serviceClass="foo.Bar"
> > > 
> > > address="..."> <jaxws:outInterceptors>
> > > 
> > >             <bean class="foo.BarOutInterceptor" />
> > >         
> > >         </jaxws:outInterceptors>
> > >     
> > >     </jaxws:client>
> > 
> > --
> > Daniel Kulp
> > dkulp@apache.org - http://dankulp.com/blog
> > Talend Community Coder - http://coders.talend.com
-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Mime
View raw message