我正处于创建输出拦截器并从 SOAP 消息中获取 OuputStream 的阶段。但是,如何在将 SOAP 信封发送到端点之前对其进行修改呢?我想删除一些 xml 元素。
一种方法是获取文档并通过 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
}
但请注意,如果您具有必须对肥皂内容执行 XML 签名之类的安全性,则必须确保拦截器在应用签名之前发生,否则将使它们无效。
要调整拦截器的时间,您可以指定它将运行的阶段。如果它们在同一阶段执行,CXF 还应该遵循您配置它们的顺序。
但不要相信我的话...检查这些以获取更多信息
- http://cxf.apache.org/docs/interceptors.html http://cxf.apache.org/docs/interceptors.html
- http://fusesource.com/docs/esb/4.2/cxf_interceptors/CXFInterceptorIntro.html http://fusesource.com/docs/esb/4.2/cxf_interceptors/CXFInterceptorIntro.html
通过 CXF 源代码进行调试也对我理解它的工作原理有很大帮助
- - 编辑 - -
(谢谢丹尼尔:-)
为此,您需要在堆栈中配置 SAAJOutInterceptor。您可以手动添加它,也可以简单地将其作为拦截器的一部分。Here is http://permalink.gmane.org/gmane.comp.apache.cxf.user/11247拦截器的示例,几乎可以满足您的要求。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)