[ 
https://issues.apache.org/jira/browse/WSCOMMONS-197?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491634
 ] 

Ruchith Udayanga Fernando commented on WSCOMMONS-197:
-----------------------------------------------------

here you go :-)

public class SerializerTest extends TestCase {

    public SerializerTest(String arg0) {
        super(arg0);
    }
    
    public void test1() throws Exception {
        SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope env = fac.createSOAPEnvelope();
        
        fac.createSOAPBody(env);
        
        SOAPFactory domFac = new SOAP11Factory();
        
        StAXSOAPModelBuilder builder = new 
StAXSOAPModelBuilder(env.getXMLStreamReader(), domFac, null);
        SOAPEnvelope domEnv = builder.getSOAPEnvelope();
        
        Element elem = (Element)domEnv;
        Document doc = elem.getOwnerDocument();
        
        Element headerElem = doc.createElementNS(env.getNamespace()
                        .getNamespaceURI(), env.getNamespace().getPrefix() + ":"
                        + SOAPConstants.HEADER_LOCAL_NAME);
        headerElem.appendChild(doc.createElement("foo"));
        elem.insertBefore(headerElem, elem.getFirstChild());
        
        String s = domEnv.toString();
        assertTrue("Header missing", s.indexOf("Header") > 0);
    }
}

The issue is that when WSS4J will create the missing SOAP Header element when 
it tries to create the wsse:Security header block.

Thanks,
Ruchith

> SOAP headers added using DOOM are lost during serialization
> -----------------------------------------------------------
>
>                 Key: WSCOMMONS-197
>                 URL: https://issues.apache.org/jira/browse/WSCOMMONS-197
>             Project: WS-Commons
>          Issue Type: Bug
>          Components: AXIOM
>            Reporter: Asankha C. Perera
>         Assigned To: Glen Daniels
>            Priority: Critical
>
> Rampart is unable to add security headers to a SOAP message that does not 
> have an existing SOAP header. 
> The actual root cause of this issue is that headers added using DOOM to a 
> SOAP envelope that does not already have a header, are lost during 
> serialization. 
> The following code sample provided by Ruchith explains and is able to 
> recreate this issue. The header is lost unless the "        
> //fac.createSOAPHeader(env);" line is uncommeted
> -----------------------------------------------------------------------------------------------------
> import org.apache.axiom.om.OMAbstractFactory;
> import org.apache.axiom.om.OMText;
> import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
> import org.apache.axiom.soap.SOAPEnvelope;
> import org.apache.axiom.soap.SOAPFactory;
> import org.apache.axiom.soap.SOAPHeader;
> import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
> import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
> import org.apache.ws.security.util.WSSecurityUtil;
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
>  
> import javax.xml.namespace.QName;
>  
> import junit.framework.TestCase;
>  
> /**
>  *
>  * @author Ruchith Fernando ([EMAIL PROTECTED])
>  */
> public class SerializerTest extends TestCase {
>  
>     public SerializerTest() {
>     }
>  
>     public SerializerTest(String arg0) {
>         super(arg0);
>     }
>  
>     public void test1() throws Exception {
>         SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
>         SOAPEnvelope env = fac.createSOAPEnvelope(); 
>         fac.createSOAPBody(env);
>         //fac.createSOAPHeader(env);
>  
>         fac = new SOAP11Factory();
>         StAXSOAPModelBuilder builder = new 
> StAXSOAPModelBuilder(env.getXMLStreamReader(), fac, null);
>         SOAPEnvelope domEnv = builder.getSOAPEnvelope();
>  
>         Element elem = (Element)domEnv;
>         Document doc = elem.getOwnerDocument();
>  
>         WSSecurityUtil.findWsseSecurityHeaderBlock(doc, elem, true);
>  
>         String s = domEnv.toString();
>  
>         System.out.println(s);
>     }
>  
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to