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!*/
}
}
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
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
Your intercepter must be run after SAAJOutInterceptor(); For example Glen Mazza's Weblog