我需要将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 :(得分:1)
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");