>       @Override
>       public void handleMessage(SoapMessage message) throws Fault {
> 
>               System.out.println(message.getInterceptorChain());
>               message.getInterceptorChain().add(new EndingInterceptor());
> 
>       }

You need to make sure the getSOAPMessage(message) call is made there to setup 
the SAAJ stuff.

Dan



On Wednesday 16 February 2011 11:25:40 PM swastb wrote:
> Hi Daniel,
> 
> Thanks a lot for the reply. Its working really fine with DOM. But I tried
> the following as well but still getting error as
> 
> Feb 17, 2011 9:46:27 AM
> org.apache.cxf.binding.soap.interceptor.Soap11FaultOutIn
> terceptor$Soap11FaultOutInterceptorInternal handleMessage
> WARNING: Error writing to XMLStreamWriter.
> org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to
> insert a
>  node where it is not permitted.
>         at
> com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.insertBefore(
> CoreDocumentImpl.java:381)
> 
> I tried the following code
> private static SAAJOutInterceptor  saajOut = new SAAJOutInterceptor ();
>       public HelloOutboundInterceptor(){
>               super(Phase.PRE_PROTOCOL);
>               addAfter(SoapOutInterceptor.class.getName());
> 
>       }
> 
>       @Override
>       public void handleMessage(SoapMessage message) throws Fault {
> 
>               System.out.println(message.getInterceptorChain());
>               message.getInterceptorChain().add(new EndingInterceptor());
> 
>       }
> 
>       static class EndingInterceptor extends AbstractSoapInterceptor {
> 
>         public EndingInterceptor() {
>              super(Phase.PRE_PROTOCOL_ENDING);
>              addBefore(SAAJOutEndingInterceptor.class.getName());
>          }
> 
>         public void handleMessage(SoapMessage message) throws Fault {
> 
>               try {
>                       SOAPMessage soapMessage = getSOAPMessage(message);
>                               SOAPPart sp = soapMessage.getSOAPPart();
>                               SOAPEnvelope envelope = sp.getEnvelope();
>                               envelope.getHeader().detachNode();
>                               SOAPHeader header = envelope.addHeader();
>                               SOAPFactory soapFactory = 
> SOAPFactory.newInstance();
>                               Name headerName = 
> soapFactory.createName("Authentication",
>                                               "auth", 
> "http://sample.cxf.com/";);
>                               SOAPElement headerElement = 
header.addHeaderElement(headerName)
>                                               .addChildElement("TokenID");
>                               headerElement.addTextNode("token1234");
>                               System.out.println("Header is added 
> successfully");
>                               try {
>                                       soapMessage.writeTo(System.out);
>                               } catch (Exception e) {
>                                       System.out.println(e);
>                               }
>                       } catch (SOAPException e) {
>                               System.out.println(e);
>                       }
>         }
>     }

-- 
Daniel Kulp
[email protected]
http://dankulp.com/blog
Talend - http://www.talend.com

Reply via email to