spring ws 客户端拦截器示例

发布于 2024-11-03 16:40:30 字数 849 浏览 0 评论 0原文

我需要将自定义肥皂头添加到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从此见与不见 2024-11-10 16:40:31

不,您不需要进行某种类型的提交。我或多或少做了同样的事情(尽管我从 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

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:

            SoapMessage soapMessage = (SoapMessage) message;
        SoapHeader soapHeader = soapMessage.getSoapHeader();
        QName qname = QNameUtils.createQName(...,...);
        SoapHeaderElement element = soapHeader.addHeaderElement(qname);
        element.setText(text);

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:

#log4j.logger.org.springframework.ws.client.MessageTracing.sent=TRACE
#log4j.logger.org.springframework.ws.client.MessageTracing.received=TRACE
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文