1
我想從Netbeans使用gSoap生成的wsdl。 WebService的要求的UserNameToken被傳入。當我使用了SoapUI(工作)的WSDL,它發出這樣的:來自Java的肥皂UserNameToken
<wsse:Username>myname</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mypass</wsse:Password>
然而,當我使用一個處理程序(嘗試通過NetBeans通過How do I add a SOAP Header using Java JAX-WS簡稱)是這樣的:
String prefix = "wsse";
String uri = "http://...wsssecurity...";
SOAPElement securityElem = factory.createElement("Security",prefix,uri);
SOAPElement UserNametokenElem = factory.createElement("UserNameToken",prefix,uri);
SOAPElement UsernameElem = factory.createElement("wsse:Username");
UsernameElem.addTextNode("myname");
SOAPElement PasswordElem = factory.createElement("Password");
PasswordElem.addTextNode("mypass");
UserNametokenElem.addChildElement(UsernameElem);
UserNametokenElem.addChildElement(PasswordElem);
securityElem.addChildElement(UserNametokenElem);
SOAPHeader header = envelope.addHeader();
header.addChildElement(securityElem);
它生成的SOAP標頭是這樣的:
<wsse:Security xmlns:wsse="http://...wsssecurity...">
<wsse:UserNameToken xmlns:wsse="http://...wsssecurity...">
<Username xmlns="">myname</Username>
<Password xmlns="">mypass</Password>
</wsse:UserNameToken>
</wsse:Security>
這會導致webservice回覆認證錯誤。因此
我的問題是:
- 如何生成正確的方式UsernameToken中(如SOAPUI呢)?
- 是更好地利用處理器,或外部WSSE庫,如Apache WSS4J做到這一點(可有人告訴我,這一些示例代碼)
很好的例子。謝謝你爲我節省了很多時間! – 2015-02-02 15:40:10