Q:

How to add child nodes to childNode in SOAP HEader?

I am trying to create children nodes inside  and it should look like the following 
   <soapenv:Header>
       <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-21" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
           <wsse:Username>USER</wsse:Username>
           <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PAASS</wsse:Password>
           <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">==</wsse:Nonce>
           <wsu:Created>2012-02-22T16:27:29.088Z</wsu:Created>
         </wsse:UsernameToken>
       </wsse:Security>
     </soapenv:Header>

with the following 
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPElement userNameToken = envelope.getHeader().addChildElement("Usernametoken", WSSE_NS_PREFIX, WSSE_NS);
    SOAPElement user = userNameToken.addChildElement("UserName", WSSE_NS, WSSE_NS_PREFIX);

i get the following error when attemping to do so:
    NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

A:

It seems that you mixed order of arguments (WSSE_NS vs WSSE_NS_PREFIX)
It should be
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPElement userNameToken = envelope.getHeader().addChildElement("Usernametoken", WSSE_NS_PREFIX, WSSE_NS);
SOAPElement user = userNameToken.addChildElement("UserName", WSSE_NS_PREFIX, WSSE_NS);

