[英]Apache CXF LoggingInInterceptor is deprecated - what to use instead?
我在 3.2.7 版的cxf-spring-boot-starter-jaxws
插件的幫助下將 Apache CXF 與 Spring Boot 一起使用。
我的目的是自定義 LoggingInterceptors 但是當我創建以下類時:
public class CustomLoggingInInterceptor extends org.apache.cxf.interceptor.LoggingInInterceptor {}
但我的 IDE 刪除了 LoggingInInterceptor 抱怨它已被棄用,並附有解釋
改用日志模塊 rt/features/logging
那么應該如何使用這個模塊自定義日志攔截器呢?
此消息告訴您的是使用Apache CXF Advanced logging feature
模塊。
它的依賴是(最新版本)
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-features-logging</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
在里面你會發現一個類似的org.apache.cxf.ext.logging.LoggingInInterceptor
( 鏈接)
我不是 CXF 用戶,但是我想您必須與JaxWsProxyFactoryBean
進行交互。
請記住,您需要為所有 CXF 模塊使用相同的版本。
掌握它后,你可以做
factory.getInInterceptors().add(new MyCustomInterceptor());
從舊的 cxf 日志(rt/features/logging)更新到新的 cxf 日志基本上需要 4 件事。
首先,設置日志記錄功能:
final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setFeatures(Collections.singletonList(new CustomLoggingFeature()));
您不再需要攔截器(如果您使用它們,請刪除它們):
factory.getInInterceptors().add(new CustomMaskedLoggingInInterceptor());
factory.getOutInterceptors().add(new CustomMaskedLoggingOutInterceptor());
其次,創建您的 LoggingFeature:
public class CustomLoggingFeature extends org.apache.cxf.ext.logging.LoggingFeature {
public CustomLoggingFeature() {
super();
this.setSender(new CustomEventLogSender());
}
}
第三,創建您的 EventLogSender:
public class CustomEventLogSender extends Slf4jVerboseEventSender {
@Override
protected String getLogMessage(LogEvent event) {
String logMessage = super.getLogMessage(event);
return CustomMasker.mask(logMessage);
}
}
第四,創建一個 CustomMasker 類,您可以在其中擁有自己的字符串操作邏輯來屏蔽所需的信息。
讓我知道它是否有效!
當您在其他地方提到依賴項時:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-features-logging</artifactId>
<version>${org.apache.cxf.version}</version>
</dependency>
當您使用JaxWsProxyFactoryBean
,您可以像這樣配置該工廠:
LoggingFeature loggingFeature = new LoggingFeature();
loggingFeature.setPrettyLogging(true);
loggingFeature.setVerbose(true);
loggingFeature.setLogMultipart(true);
factory.getFeatures().add(loggingFeature);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.