spring ws 客户端拦截器示例
我需要将自定义肥皂头添加到 Spring ws 2.0 客户端中的传出肥皂消息中。
我正在使用客户端拦截器,如下......
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;
}
}
我已经确认拦截器被调用,但标头似乎没有添加。我是否打算进行某种“提交”以将标头应用到消息???
I need to add a custom soap header to an out going soap message in a spring ws 2.0 client.
I am using a client interceptor as follows.....
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;
}
}
I have confirmed the interceptor is called, but the header doesn't seem to get added. Am I meant to be doing some sort of "commit" to apply the header to the message ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您不需要进行某种类型的提交。我或多或少做了同样的事情(尽管我从 WS 模板的 sendAndRecieve 方法内部调用它:
您是否尝试过打开消息日志记录以查看消息发送出去时的实际情况?
您可以通过创建一个log4j.properties 并添加以下行:
No, you don't need to do some type of commit. I do more or less the same thing (although I call it from inside the sendAndRecieve method of WS Template:
Have you tried turning on message logging to see what the message acutally looks likes when it is sent out?
You can do this by creating a log4j.properties and adding these lines: