我是SOAP的新手,我想学习如何自定义SOAP头 . 更具体地说,我试图配置我的出站消息SOAP标头以符合预期的格式 . 标头将用于身份验证 .
这就是我到目前为止所拥有的 .
我已经设置了一个方法来添加安全deader,我试图按照规范格式化标头 .
private void addSecurityHeader(SOAPMessageContext messageContext) throws SOAPException {
public static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
public static final String WSSE_SECURITY_NAME = "Security";
public static final String WSSE_NS_PREFIX = "wsse";
public static final String SOAPENV_NS_PREFIX = "soapenv";
SOAPEnvelope envelope = messageContext.getMessage().getSOAPPart().getEnvelope();
SOAPHeader header = messageContext.getMessage().getSOAPPart().getEnvelope().getHeader();
SOAPBody body = messageContext.getMessage().getSOAPPart().getEnvelope().getBody();
// changing prefix to soapenv
envelope.setPrefix(SOAPENV_NS_PREFIX);
header.setPrefix(SOAPENV_NS_PREFIX);
body.setPrefix(SOAPENV_NS_PREFIX);
// adding security Element
Name securityName = soapFactory.createName(WSSE_SECURITY_NAME, WSSE_NS_PREFIX, WSSE_NS);
SOAPHeaderElement securityElement = header.addHeaderElement(securityName);
当我在Eclipse控制台中打印出消息时,Security元素采用以下格式:
<wsse:Security xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">
但这是安全格式的理想格式:
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
总结一下我需要解决的问题:
1)我需要将SOAP-ENV更改为soapenv .
SOAP-ENV:mustUnderstand =“1”
应该
soapenv:mustUnderstand =“1”
2)我需要删除
xmlns:SOAP-ENV =“http://schemas.xmlsoap.org/soap/envelope/”
因为在这个元素中不需要它 .
任何提示如何完成它将不胜感激 .
1 回答
我最近以下列方式解决了这个问题: -
发送TimeStamp时要小心 . 客户端和服务器时钟应该处于同步状态,因此请注意客户端和服务器计算机的时区
应该正确编码Nonce字符串 . 我接受了以下方面的帮助:
Java Webservice Client UsernameToken equivalent to PHP
以下是模板XML文件的外观: -