Search code examples
xmlcxfwebservice-client

Logging request/response with Apache CXF as XML


Is it possible to log the request/response as XML using CXF, ideally to a separate file so I can monitor what an application is doing?


Solution

  • Add the following to your endpoints and clients:

    <jaxws:features>
        <bean class="org.apache.cxf.feature.LoggingFeature" />
    </jaxws:features>
    

    This will log everything to the server log.

    If you want to log them elsewhere, then look at the source code of the built-in CXF LoggingInInterceptor and LoggingOutInterceptor. You can follow the pattern they use to grab the messages on their way in/out and do with them what you like.

    Add your own interceptors to the chain with something like this:

    <jaxws:inInterceptors>
        <ref bean="myLoggingInInterceptor" />
    </jaxws:inInterceptors>