CXF传出侦听器获取始终为空的soap响应正文?
我编写了一个拦截器进行测试。但是我在拦截器中得到的Soap消息体总是空的 我的Cxf是Apache-Cxf-2.4.0 xml如下所示:CXF传出侦听器获取始终为空的soap响应正文?,soap,cxf,response,interceptor,Soap,Cxf,Response,Interceptor,我编写了一个拦截器进行测试。但是我在拦截器中得到的Soap消息体总是空的 我的Cxf是Apache-Cxf-2.4.0 xml如下所示: <cxf:bus> <cxf:outInterceptors> <ref bean="myOutSoapInterceptor"/> </cxf:outInterceptors> </cxf:bus> 该消息取决于您此时所处的阶段。您可以在中找到包含阶段的列表 . 如果您
<cxf:bus>
<cxf:outInterceptors>
<ref bean="myOutSoapInterceptor"/>
</cxf:outInterceptors>
</cxf:bus>
该消息取决于您此时所处的阶段。您可以在中找到包含阶段的列表 . 如果您试图获取消息内容,则需要找到消息存在的格式。看看里面。某些对象不会向您提供该消息。CXF最多使用流。因此可以刷新流对象 致以最良好的问候
Christian您的拦截器必须在SAAJOutInterceptor()之后运行;
例如,要从soap消息中获取响应xml,可以使用“CacheAndWriteOutStream”和“CacheAndOutStreamCallback”。在回调类中,您可以在关闭流之前获取消息。例如,我们的out LoggingInterceptor是“WSLoggingOutiterCeptor”,可以在上下文文件中进行如下配置:
<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="logOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<bean id="wsLoggingOutInterceptor" class="org.jinouts.webservice.logging.WSLoggingOutInterceptor"></bean>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="loggingInInterceptor"/>
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="logOutInterceptor"/>
<ref bean="wsLoggingOutInterceptor"/>
</cxf:outInterceptors>
</cxf:bus>
查看此站点以了解更多详细信息:您是将SOAP内容作为字符串还是对象进行查找?
<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="logOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<bean id="wsLoggingOutInterceptor" class="org.jinouts.webservice.logging.WSLoggingOutInterceptor"></bean>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="loggingInInterceptor"/>
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="logOutInterceptor"/>
<ref bean="wsLoggingOutInterceptor"/>
</cxf:outInterceptors>
</cxf:bus>
/**
* @author asraf
* asraf344@gmail.com
*/
public class WSLoggingOutInterceptor extends AbstractLoggingInterceptor
{
public WSLoggingOutInterceptor()
{
super(Phase.PRE_STREAM );
}
@Override
public void handleMessage ( Message message ) throws Fault
{
// TODO Auto-generated method stub
OutputStream os = message.getContent ( OutputStream.class );
CacheAndWriteOutputStream cwos = new CacheAndWriteOutputStream ( os);
message.setContent ( OutputStream.class, cwos );
cwos.registerCallback ( new LoggingOutCallBack ( ) );
}
@Override
protected Logger getLogger ( )
{
// TODO Auto-generated method stub
return null;
}
}
class LoggingOutCallBack implements CachedOutputStreamCallback
{
@Override
public void onClose ( CachedOutputStream cos )
{
try
{
if ( cos != null )
{
System.out.println ("Response XML in out Interceptor : " + IOUtils.toString ( cos.getInputStream ( ) ));
}
}
catch ( Exception e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onFlush ( CachedOutputStream arg0 )
{
}
}