Disable CXF logging for one web service

五迷三道 提交于 2019-12-24 09:25:12

问题


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:

  • JDK 8
  • cxf 2.7.14
  • AS : Jboss EAP 6.4

I turn on login on server by:

  • add logger org.apache.cxf INFO
  • and system property org.apache.cxf.logging.enabled=true

回答1:


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.



来源:https://stackoverflow.com/questions/42678054/disable-cxf-logging-for-one-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!