簡體   English   中英

對Web服務的一種方法禁用CXF日志記錄

[英]Disable CXF logging for one method on web service

如何禁用在cxf攔截器中登錄的一種方法?

我可以禁用所有In請求所有Out請求

<logger name="org.apache.cxf.services.MyService.REQ_OUT" level="ERROR"/>
<logger name="org.apache.cxf.services.MyService.RESP_IN" level="ERROR"/>

但是我無法禁用MyService中一種方法的日志

我找到了一個與我想要的答案相似的答案: 鏈接

但這還不是很清楚。 我不知道應該在哪里覆蓋該方法:

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

而且我不知道這是否是一個可行的例子。

我已經閱讀了許多文章和網站,但沒有找到答案。 但是通過搜索代碼,我找到了原因並找到了解決方案。 我真的不知道它有多有效。

在我在問題中編寫的示例中,使用了舊版本的logger(已描述)。 在新版本中, org.apache.cxf.ext.logging.LoggingInInterceptor方法transform不存在

它是新記錄器的解決方案:

import org.apache.cxf.ext.logging.LoggingInInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;

import java.util.List;
import java.util.TreeMap;

public class UnpLoggingInInterceptor extends LoggingInInterceptor {

    private static final String GET_RESPONSE = "urn:GetResponse";

    @Override
    public void handleMessage(Message message) throws Fault {
        TreeMap<String, List> headers = (TreeMap<String, List>) message.get("org.apache.cxf.message.Message.PROTOCOL_HEADERS");

        if (headers != null) {
            List value = headers.get("SOAPAction");
            String soapAction = value != null ? (String) value.get(0) : "";
            if (soapAction.replace("\"", "").equalsIgnoreCase(GET_RESPONSE)) {
                isLoggingDisabledNow(message);
                return;
            }
        }
        super.handleMessage(message);
    }
}

暫無
暫無

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

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