Martinus_
Martinus_

Reputation: 170

Disable CXF logging for one web service

In my application I would like to log request and response with business logic. Application does some backend logic with SOAP communication and this is what I want to log.

Unfornatly in this same application I must serve data ( avg. is 4 request/s) Let's say this service name is PlatformDataService.

How to turn off cxf logging for only one web service?

Enviorment:

I turn on login on server by:

Upvotes: 1

Views: 2746

Answers (1)

Vijendra Kumar Kulhade
Vijendra Kumar Kulhade

Reputation: 2255

You can extend LoggingInInterceptor and LoggingOutInterceptor. Based on the soapAction you can ignore only logging for one service.

Extend LoggingOutInterceptor for all the outbound requests and override method handleMessage like this.

private boolean doNotLog=false;

public void handleMessage(Message message) throws Fault {
    TreeMap<String,List> protocolHeaders =
            (TreeMap<String, List>) message.get("org.apache.cxf.message.Message.PROTOCOL_HEADERS");
    if (protocolHeaders != null) {
        List value = protocolHeaders.get("SOAPAction");
        String soapAction = value != null ? (String)value.get(0) : "";
        if (soapAction.equalIgnoreCase(YOUR_SERVICE_SOAP_ACTION)) {
            doNotLog=true;
        }
    }
    super.handleMessage(message);
}

Now there is one more method you have to override in the same class.

@Override
    protected String transform(String originalLogString) {
        if (doNotLog) {
            return null;
        }
        return originalLogString;
    } 

For all inbound responses, extend LoggingInInterceptor and only override transform method. You can just check the responseType from the originalLogString and ignore it.

Upvotes: 2

Related Questions