简体   繁体   English

禁用一项Web服务的CXF日志记录

[英]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. 应用程序通过SOAP通信执行一些后端逻辑,这就是我要记录的内容。

Unfornatly in this same application I must serve data ( avg. is 4 request/s) Let's say this service name is PlatformDataService. 不幸的是,在同一应用程序中,我必须提供数据(平均为4个请求/秒)。假设此服务名称为PlatformDataService。

How to turn off cxf logging for only one web service? 如何仅关闭一个Web服务的CXF日志记录?

Enviorment: Enviorment:

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

I turn on login on server by: 我通过以下方式打开服务器上的登录:

  • add logger org.apache.cxf INFO 添加记录器org.apache.cxf信息
  • and system property org.apache.cxf.logging.enabled=true 和系统属性org.apache.cxf.logging.enabled = true

You can extend LoggingInInterceptor and LoggingOutInterceptor . 您可以扩展LoggingInInterceptorLoggingOutInterceptor Based on the soapAction you can ignore only logging for one service. 基于soapAction您可以仅忽略一项服务的日志记录。

Extend LoggingOutInterceptor for all the outbound requests and override method handleMessage like this. LoggingOutInterceptor扩展为所有出站请求,并像这样覆盖方法handleMessage

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. 对于所有入站响应,请扩展LoggingInInterceptor并仅重写转换方法。 You can just check the responseType from the originalLogString and ignore it. 您可以只检查originalLogString的responseType并忽略它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM