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);
                        } 
        } 
    } 
-- 
View this message in context: 
http://cxf.547215.n5.nabble.com/Problem-with-outbound-soap-message-tp3384130p3388875.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to