Apache CXF-based Java Web Services: How to log/print the payload XML of incoming SOAP request using LoggingInInterceptor?
I’ve had a requirement to print the exact SOAP XML of incoming requests to one of our web services written using Apache CXF Framework and here’s what I did.
For doing this quickly, I’m taking the code from http://singztechmusings.wordpress.com/2010/12/10/java-web-services-soap-over-ssl-cxf-framework/ for CalculationServerIfc that basically does addition/subtraction based on web service requests.
Here’s it:
package test.calculationserver;
import javax.jws.WebService;
@WebService
public interface CalculationServerIfc {
public int add(int a, int b);
public int subtract(int a, int b);
}
and I’m assuming it’s up with this WSDL url – https://localhost:8443/calculationserver/CalculationServerImpl?wsdl
Now, I’m trying to hit this using SoapUI v2.5.1.
Here’s the SOAP request XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://calculatorws.test.singz/"> <soapenv:Header/> <soapenv:Body> <cal:add> <arg0>3</arg0> <arg1>3</arg1> </cal:add> </soapenv:Body> </soapenv:Envelope>
and the SOAP response,
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns2:addResponse xmlns:ns2="http://calculatorws.test.singz/"> <return>6</return> </ns2:addResponse> </soap:Body> </soap:Envelope>
My requirement is to log this SOAP XML at server side. So, I’m just rewriting the CalculationService code like this:
import javax.jws.WebService;
import org.apache.cxf.interceptor.InInterceptors;
@WebService
@InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor")
public interface CalculationServerIfc {
public int add(int a, int b);
public int subtract(int a, int b);
}
Now, when I hit it using SoapUI, here’s the log message I get in standard output:
Aug 26, 2011 2:14:31 PM org.apache.cxf.interceptor.AbstractLoggingInterceptor log
INFO: Inbound Message
—————————-
ID: 1
Address: /cxf/calculator-service
Encoding: UTF-8
Content-Type: text/xml;charset=UTF-8
Headers: {content-type=[text/xml;charset=UTF-8], host=[localhost:9999], Content-Length=[279], SOAPAction=[""], user-agent=[Jakarta Commons-HttpClient/3.1], Content-Type=[text/xml;charset=UTF-8]}
Payload: <soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:cal=”http://calculatorws.test.singz/”>
<soapenv:Header/>
<soapenv:Body>
<cal:add>
<arg0>3</arg0>
<arg1>3</arg1>
</cal:add>
</soapenv:Body>
</soapenv:Envelope>
————————————–
It, by default, uses Java’s logging mechanism. You can use log4j/slf4j instead. If you like to know more about this, visit http://cxf.apache.org/docs/debugging-and-logging.html.
About this entry
You’re currently reading “Apache CXF-based Java Web Services: How to log/print the payload XML of incoming SOAP request using LoggingInInterceptor?,” an entry on Singaram's Tech Musings
- Published:
- August 26, 2011 / 2:26 PM
- Category:
- Apache CXF, Coding tips, Java, Web Services

7 Comments
Jump to comment form | comment rss [?] | trackback uri [?]