CXF 传出拦截器获取始终为空的肥皂响应正文?
我写了一个拦截器来测试。但我在拦截器中得到 Soap 消息体始终为空。
我的Cxf是Apache-CXF-2.4.0
bean.xml是这样的:
<cxf:bus>
<cxf:outInterceptors>
<ref bean="myOutSoapInterceptor"/>
</cxf:outInterceptors>
</cxf:bus>
拦截器文件:
public class MySoapInterceptorImpl extends AbstractSoapInterceptor implements IMySoapInterceptor {
public MySoapInterceptorImpl()
{
super(Phase.WRITE );
addAfter(SoapOutInterceptor.class.getName());
}
public void handleMessage(SoapMessage msg) throws Fault {
// TODO Auto-generated method stub
String soapContent ;
SOAPMessage sm = msg.getContent(SOAPMessage.class);
/*sm is always null!*/
}
}
I write a Interceptor for test. But I get Soap message body in the Interceptor is always null.
My Cxf is Apache-CXF-2.4.0
bean.xml is like this:
<cxf:bus>
<cxf:outInterceptors>
<ref bean="myOutSoapInterceptor"/>
</cxf:outInterceptors>
</cxf:bus>
Interceptor file :
public class MySoapInterceptorImpl extends AbstractSoapInterceptor implements IMySoapInterceptor {
public MySoapInterceptorImpl()
{
super(Phase.WRITE );
addAfter(SoapOutInterceptor.class.getName());
}
public void handleMessage(SoapMessage msg) throws Fault {
// TODO Auto-generated method stub
String soapContent ;
SOAPMessage sm = msg.getContent(SOAPMessage.class);
/*sm is always null!*/
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要从soap消息中获取响应xml,您可以使用“CacheAndWriteOutputStream”和“CachedOutputStreamCallback”。在回调类中,您可以在关闭流之前获取消息。比如说,我们的 LoggingInterceptor 是“wsLoggingOutInterceptor”,可以在上下文文件中进行如下配置:
请注意,这里我们还有一些可在 CXF jar 中使用的默认拦截器。
现在,在我们自己的拦截器中,我们可以按以下方式编写来记录输出响应消息,或者您也可以在此处进行编辑:
查看此站点以获取更多详细信息:http://cxf.apache.org/docs/interceptors.html
To get the response xml from the soap message, you can use the "CacheAndWriteOutputStream" and "CachedOutputStreamCallback". In the callback class you can get the message before closing the stream. Say, our out LoggingInterceptor is "wsLoggingOutInterceptor" which can be configured in the context file as follows :
Note that, here we have also some default interceptor which is available with the CXF jars.
Now in our own interceptor we can write in the following way to log the output response message or you can also edit here :
Have a look at this site for more details : http://cxf.apache.org/docs/interceptors.html
该消息取决于您此时所处的阶段。您可以找到包含以下阶段的列表
拦截器 doku。如果您尝试获取消息内容,您需要找到消息存在的格式。看看 getContentFormats。有些对象不会给您该消息。 CXF 大多数时候都与流一起工作。所以流对象可以被刷新。
最诚挚的问候
基督教
The message depends on the phase you are at this moment. You can find a list with phases in
Interceptor doku. If you try to get the message content you need to find our in which format the message exists. Have a look in getContentFormats. Some of the objects will not give you the message. The most time CXF works with streams. So the stream object could be flushed.
With best regards
Christian
您的拦截器必须在 SAAJOutInterceptor() 之后运行;
例如Glen Mazza 的博客
Your intercepter must be run after SAAJOutInterceptor();
For example Glen Mazza's Weblog