简体   繁体   中英

Axis2 “No WS-Security header found”

I'm trying to use axis2, but there must be Security headers in message.

I tried to add PEWSClientHeaderHandler class from this example , but it doesn't work (it works with default sun implementation, but not with axis2). The formed SOAP message looks like this:

...
<soapenv:Header>
  <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"></wsse:Security>
</soapenv:Header>
...

UsernameToken, Username and Password tags are missing (but again, they are set in code and no exception when using sun).

Can anyone provide the simplest example of how such a header can be set in axis2?

Axis2 implementation has 1 little difference:

Standard Sun implementation:

SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope();
SOAPFactory soapFactory = SOAPFactory.newInstance();

SOAPHeader sh = envelope.addHeader();
SOAPElement wsSecHeaderElm = soapFactory.createElement("Security", AUTH_PREFIX, AUTH_NS);
SOAPElement userNameTokenElm = soapFactory.createElement("UsernameToken", AUTH_PREFIX, AUTH_NS);
SOAPElement userNameElm = soapFactory.createElement("Username", AUTH_PREFIX, AUTH_NS);
SOAPElement passwdElm = soapFactory.createElement("Password", AUTH_PREFIX, AUTH_NS);

userNameElm.addTextNode("username");
passwdElm.addTextNode("password");

userNameTokenElm.addChildElement(userNameElm);
userNameTokenElm.addChildElement(passwdElm);
wsSecHeaderElm.addChildElement(userNameTokenElm);
sh.addChildElement(wsSecHeaderElm);

Axis2 implementation:

// the same as above

userNameTokenElm.addChildElement(userNameElm);
userNameTokenElm.addChildElement(passwdElm);
SOAPElement el = sh.addChildElement(wsSecHeaderElm); // addChildElement returns new SOAPElement!
el.addChildElement(userNameTokenElm);    

That's all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM