I am using the Apache CXF Framework.
Inside my client program, I need to log CXF SOAP Requests and SOAP Responses.
When I used
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress(host);
factory.setServiceClass(MyService.class);
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
I got these SOAP Request and SOAP Responses in the console:
Nov 9, 2011 6:48:01 PM org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose
INFO: Outbound Message
---------------------------
ID: 2
Encoding: UTF-8
Content-Type: text/xml
Headers: {}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns4:MYResponse
--------------------------------------
But my actual requirement is, instead of printing them to the server console, I need to have them inside the log file.
When I used log4j directly as shown
log4j(factory.getInInterceptors().add(new LoggingInInterceptor()));
log4j(factory.getOutInterceptors().add(new LoggingOutInterceptor()));
It is only printing true and true inside the log file.
Could anybody please let me know how to configure this?
You need to create a file named
org.apache.cxf.Logger(that is:org.apache.cxffile withLoggerextension) under/META-INF/cxf/with the following contents:Reference: Using Log4j Instead of java.util.logging.
Also if you replace standard:
with much more verbose:
Apache CXF will pretty print XML messages formatting them with proper indentation and line breaks. Very useful. More about it here.