2016-09-27 85 views
0

我需要將Type添加到密碼子元素。如何在SOAP請求中將Type屬性設置爲子元素?

電流SOAP請求 -

<wsse:Security> 
    <wsse:UsernameToken> 
    <wsse:Username>user123</wsse:Username> 
    <wsse:Password>xxxxx</wsse:Password>       
    </wsse:UsernameToken> 
</wsse:Security> 

碼生成此 -

String prefix = "wsse"; 
SOAPElement security = header.addChildElement("Security", prefix); 
SOAPElement token = security.addChildElement("UsernameToken", prefix); 
token.addChildElement("Username", prefix).addTextNode("user123"); 
token.addChildElement("Password", prefix).addTextNode("xxxxx"); 

我需要生成像SOAP請求 -

<wsse:Security> 
    <wsse:UsernameToken> 
    <wsse:Username>user123</wsse:Username> 
    <wsse:Password Type="http://abc.def-ghi.org/wss/2016/09/xyz-wss-username-token-profile-1.0#PasswordText">xxxxx</wsse:Password>       
    </wsse:UsernameToken> 
</wsse:Security> 

回答

0
String prefix = "wsse"; 
SOAPElement security = header.addChildElement("Security", prefix); 
SOAPElement token = security.addChildElement("UsernameToken", prefix); 
token.addChildElement("Username", prefix).addTextNode("user123"); 
SOAPElement passwordElement = token.addChildElement("Password",prefix).addTextNode('xxxxx'); 
passwordElement.setAttribute("Type", "http://abc.def-ghi.org/wss/2016/09/xyz-wss-username-token-profile-1.0#PasswordText"); 
相關問題