如何修改生成的SOAP请求?

发布于 2024-11-27 19:13:11 字数 92 浏览 0 评论 0 原文

我正处于创建输出拦截器并从 SOAP 消息中获取 OuputStream 的阶段。但是,如何在将 SOAP 信封发送到端点之前对其进行修改呢?我想删除一些 xml 元素。

I'm at the stage where I created an output interceptor and I get an OuputStream out of the SOAP message. But how could I modify the SOAP envelope right before sending it to the endpoint? I would like to delete some xml elements.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

染火枫林 2024-12-04 19:13:11

一种方法是获取文档并通过 XSLT 转换运行它。

您可以通过调用仔细来获取拦截器的handleMessage中的文档,

@Override
public void handleMessage(SoapMessage message) throws Fault{
    SOAPMessage saaj = message.getContent(SOAPMessage.class);
    Document doc = saaj.getSOAPPart(); // This actually returns a SOAPPart instance but it does implement the w3c Document interface

    //play around with the document, doc is a reference so any changes made to that instance
    //will be forwarded to the rest of the chain
}

但如果您有安全性,例如必须对soap内容执行XML签名,则必须确保您的拦截器在应用签名之前发生,否则您将使它们无效。

要调整拦截器的时间,您可以指定它将运行的阶段。如果它们在同一阶段执行,CXF 还应该遵循您配置它们的顺序。

但不要相信我的话...检查这些以获取更多信息

通过CXF源代码进行调试也帮助我理解了它的工作原理

----编辑 ----

(感谢 Daniel :-)

要实现此功能,您需要在堆栈中配置 SAAJOutInterceptor。您可以手动添加它,也可以简单地将其作为拦截器的一部分。 这是一个拦截器的示例,它几乎可以完成您的任务想。

one way could be to get the document and run it through XSLT transform.

You can get at the document in the handleMessage of your interceptor by calling

@Override
public void handleMessage(SoapMessage message) throws Fault{
    SOAPMessage saaj = message.getContent(SOAPMessage.class);
    Document doc = saaj.getSOAPPart(); // This actually returns a SOAPPart instance but it does implement the w3c Document interface

    //play around with the document, doc is a reference so any changes made to that instance
    //will be forwarded to the rest of the chain
}

careful though that if you have security such as XML signature that must be performed on the soap content you must ensure that your interceptor occurs BEFORE the signature are applied otherwise you will invalidate them.

To play around with the timing of the interceptor you can specify the phase at which it will run. CXF should also honor the order in which you will configure them should they be performed at the same phase.

but don't take my word for it... check these for more info

debugging through the CXF source code also helped me a great deal in understanding how it worked

---- EDIT ----

(thanks Daniel :-)

For this to work you need to have SAAJOutInterceptor configured in your stack. You can either add it manually or simply make it part of your interceptor. Here is an example of an interceptor that pretty much does what you want.

甜是你 2024-12-04 19:13:11

我在这里发布了答案 https://stackoverflow.com/a/12948702/792313
它基于全身替代。

I posted an answer here https://stackoverflow.com/a/12948702/792313
It is based on the whole body substitution.

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