通常它是在代码之外完成的。
在这种情况下,这可能会有所帮助
如果您想以编程方式添加,
以编程方式将 WS-Security UsernameToken 标头添加到 Axis 绑定,非标准,但对快速测试很有用。(存根/绑定:它是以 _PortType 结尾的类)
/**
* Adds WS-Security header with UsernameToken element to the Axis binding
* @param binding
* @param wsUser
* @param wsPass
* @throws SOAPException
*/
protected static void addWsSecurityHeader(org.apache.axis.client.Stub binding, String wsUser, String wsPass)
throws SOAPException {
// Create the top-level WS-Security SOAP header XML name.
QName headerName = new QName(
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");
SOAPHeaderElement header = new SOAPHeaderElement(headerName);
// no intermediate actors are involved.
header.setActor(null);
// not important, "wsse" is standard
header.setPrefix("wsse");
header.setMustUnderstand(true);
// Add the UsernameToken element to the WS-Security header
SOAPElement utElem = header.addChildElement("UsernameToken");
SOAPElement userNameElem = utElem.addChildElement("Username");
userNameElem.setValue(wsUser);
SOAPElement passwordElem = utElem.addChildElement("Password");
passwordElem.setValue(wsPass);
// Finally, attach the header to the binding.
binding.setHeader(header);
}