Question

In Android programming, I am trying to generate the following soap Header (WSSE Security with Password Digest Header) using ksoap2.

  <soap:Header>
    <wsse:Security soap:mustUnderstand="1">  
      <wsse:UsernameToken>
         <wsse:Username>user</wsse:Username>
         <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">DbIekaN2kkkEHsC2dHVrWYj0Lj0=</wsse:Password>
         <wsse:Nonce>KCkqLywtiK8wMTIzND9N2e==</wsse:Nonce>
         <wsu:Created>2013-06-18T21:18:11Z</wsu:Created>
     </wsse:UsernameToken>
   </wsse:Security>
  </soap:Header>

My code for generating the above header is

    Element headers[] = new Element[1];
    headers[0]= new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
    headers[0].setAttribute(null, "soap:mustUnderstand", "1");

    Element to = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken");


    Element action1 = new Element().createElement(null, "n0:Username");
    action1.addChild(Node.TEXT, "user");
    to.addChild(Node.ELEMENT,action1);

    Element action2 = new Element().createElement(null, "n0:Password");
    action2.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
    action2.addChild(Node.TEXT, "DbIekaN2kkkEHsC2dHVrWYj0Lj0=");
    to.addChild(Node.ELEMENT,action2);


    Element action3 = new Element().createElement(null, "n0:Nonce");
    action3.addChild(Node.TEXT, "KCkqLywtiK8wMTIzND9N2e==");
    to.addChild(Node.ELEMENT,action3);

    Element action4 = new Element().createElement(null, "wsu:Created");
    action4.addChild(Node.TEXT, "2013-06-18T13:18:11Z");
    to.addChild(Node.ELEMENT,action4);


    headers[0].addChild(Node.ELEMENT, to);

    soapEnvelope.headerOut = headers[0];
    // soapEnvelop is created using the following code
    // SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

However, the above code gives HTTP 400 (Bad Request).

Can any one help me please?

Was it helpful?

Solution

Did you try having a look at the requestdump by making httpTransport.debug = true

I think wsu is not related to the proper namespace. Instead of writing this, Element action4 = new Element().createElement(null, "wsu:Created");

please try Element action4 = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Created");

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top