Print XML content of SOAP message
Solution 1
Check this out and search for INBOUND INTERCEPTOR. Will place it here for reference...
public class InterceptorMensajeSOAPIn extends AbstractSoapInterceptor {
private static Logger log =
Logger.getLogger(InterceptorMensajeSOAPIn.class);
private SAAJInInterceptor saajIn = new SAAJInInterceptor();
public InterceptorMensajeSOAPIn(){
super(Phase.PRE_PROTOCOL);
getAfter().add(SAAJInInterceptor.class.getName());
}
public void handleMessage(SoapMessage message) throws Fault {
SOAPMessage soapMessage = getSOAPMessage(message);
try {
soapMessage.writeTo(System.out);
} catch (Exception e) {
e.printStackTrace();
}
}
private SOAPMessage getSOAPMessage(SoapMessage smsg){
SOAPMessage soapMessage = smsg.getContent(SOAPMessage.class);
if (soapMessage == null) {
saajIn.handleMessage(smsg);
soapMessage = smsg.getContent(SOAPMessage.class);
}
return soapMessage;
}
}
Solution 2
Any reason you cannot just use the LoggingInInterceptor
that is shipped with CXF? You could just grab the code for that and use that as a basis, but in 2.3, the LoggingInInterceptor
was enhanced to allow specifying a printstream and such to use, so it might "just work".
Solution 3
You can also use a feature for this: org.apache.cxf.feature.LoggingFeature
:
<jaxws:endpoint ...>
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature"/>
</jaxws:features>
</jaxws:endpoint>
Related videos on Youtube
tobiasbayer
My name is Tobias Bayer and I am a software developer and architect from Germany with over ten years of professional experience. My main topics include Java, Clojure, Kotlin and Microservices as well as software architecture in general.
Updated on May 06, 2022Comments
-
tobiasbayer about 2 years
I am using Apache CXF for my webservices. I've created an instance of
AbstractSoapInterceptor
. In itspublic void handleMessage(SoapMessage message) throws Fault
method I would like to print the XML content of the intercepted message to the console. How can I achieve that?