如何修改生成的SOAP请求? [英] How to modify the generated SOAP request?

查看:177
本文介绍了如何修改生成的SOAP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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

您可以通过调用

 <$ c $来获取拦截器handleMessage中的文档c> @Override 
public void handleMessage(SoapMessage message)throws Fault {
SOAPMessage saaj = message.getContent(SOAPMessage.class);
Document doc = saaj.getSOAPPart(); //这实际上返回了一个SOAPPart实例,但它确实实现了w3c Document接口

//使用文档,doc是一个引用,因此对该实例所做的任何更改都是
//被转发到链的其余部分
}

小心但如果你有安全性这样的话作为必须在soap内容上执行的XML签名,您必须确保在应用签名之前发生拦截器,否则您将使它们无效。



要解决时间问题您可以指定拦截器运行的阶段。如果在同一阶段执行,CXF还应该遵守您配置它们的顺序。



但是不要相信我的话...检查这些了解更多信息





通过CXF源代码调试也帮助我了解它是如何工作的



----编辑----



(感谢Daniel: - )



为此,您需要在堆栈中配置SAAJOutInterceptor。您可以手动添加它,也可以将其作为拦截器的一部分。 这是拦截器的一个例子,它几乎可以为你做什么想要。


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.

解决方案

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.

这篇关于如何修改生成的SOAP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆