簡體   English   中英

禁用一項Web服務的CXF日志記錄

[英]Disable CXF logging for one web service

在我的應用程序中,我想使用業務邏輯記錄請求和響應。 應用程序通過SOAP通信執行一些后端邏輯,這就是我要記錄的內容。

不幸的是,在同一應用程序中,我必須提供數據(平均為4個請求/秒)。假設此服務名稱為PlatformDataService。

如何僅關閉一個Web服務的CXF日志記錄?

Enviorment:

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

我通過以下方式打開服務器上的登錄:

  • 添加記錄器org.apache.cxf信息
  • 和系統屬性org.apache.cxf.logging.enabled = true

您可以擴展LoggingInInterceptorLoggingOutInterceptor 基於soapAction您可以僅忽略一項服務的日志記錄。

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);
}

現在,您必須在同一類中重寫另一種方法。

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

對於所有入站響應,請擴展LoggingInInterceptor並僅重寫轉換方法。 您可以只檢查originalLogString的responseType並忽略它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM