我需要在spring ws 2.0客户端中为自定的soap消息添加自定义soap标头。
我正在使用客户端拦截器如下.....
public class MyWebServiceClientInterceptor implements ClientInterceptor {
private QName qname = new QName(WEB_SERVICE_NAMESPACE, SOAP_HEADER_PART);
private String testText = "<userName>myUser</userName><role>everything</role>";
@Override
public boolean handleRequest(MessageContext context) throws WebServiceClientException {
SoapMessage soapMessage = (SoapMessage) context.getRequest();
SoapHeader soapHeader = soapMessage.getSoapHeader();
SoapHeaderElement newHeader = soapHeader.addHeaderElement(qname);
newHeader.setActorOrRole(MY_SOAP_ACTOR);
newHeader.setText(testText);
return true;
}
}
我已经确认调用了拦截器,但标题似乎没有被添加。我是打算做某种“提交”将标题应用于消息????
答案 0 :(得分:4)
不,您不需要进行某种类型的提交。我或多或少做了同样的事情(虽然我从WS模板的sendAndRecieve方法中调用它:
SoapMessage soapMessage = (SoapMessage) message;
SoapHeader soapHeader = soapMessage.getSoapHeader();
QName qname = QNameUtils.createQName(...,...);
SoapHeaderElement element = soapHeader.addHeaderElement(qname);
element.setText(text);
您是否尝试启用消息记录功能,以便在发送消息时查看该消息的外观?
您可以通过创建log4j.properties并添加以下行来完成此操作:
#log4j.logger.org.springframework.ws.client.MessageTracing.sent=TRACE
#log4j.logger.org.springframework.ws.client.MessageTracing.received=TRACE