2017-03-08 57 views
0

在我的應用程序中,我想用業務邏輯記錄請求和響應。應用程序通過SOAP通信執行一些後端邏輯,這就是我想要記錄的內容。爲一個Web服務禁用CXF日誌記錄

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

如何關閉只有一個Web服務的cxf日誌記錄?

Enviorment:

  • JDK 8
  • CXF 2.7.14
  • AS:Jboss的EAP 6.4

我通過打開登錄服務器上:

  • 加logger org.apache.cxf INFO
  • 和系統屬性org.apache.cxf.logging.enabled =真

回答

0

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

針對所有出站請求和覆蓋方法handleMessage擴展LoggingOutInterceptor這樣。

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並忽略它。

+0

非常感謝,我會試試這個解決方案 –