das*_*ard 3 java logging cxf interceptor
我在cxf-spring-boot-starter-jaxws版本3.2.7 的插件的帮助下将Apache CXF与Spring Boot一起使用。
我的意图是自定义LoggingInterceptors,但是当我创建以下类时:
public class CustomLoggingInInterceptor extends org.apache.cxf.interceptor.LoggingInInterceptor {}
Run Code Online (Sandbox Code Playgroud)
但是我的IDE删除了LoggingInInterceptor并抱怨说它已被弃用
使用日志模块rt / features / logging代替
那么如何使用该模块自定义日志记录拦截器呢?
Ric*_*Art 12
从旧的 cxf 日志记录(rt/features/logging)更新到新的 cxf 日志记录基本上需要 4 件事。
首先,设置日志记录功能:
final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setFeatures(Collections.singletonList(new CustomLoggingFeature()));
Run Code Online (Sandbox Code Playgroud)
您不再需要拦截器(如果您使用它们,请删除它们):
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());
}
}
Run Code Online (Sandbox Code Playgroud)
第三,创建您的 EventLogSender:
public class CustomEventLogSender extends Slf4jVerboseEventSender {
@Override
protected String getLogMessage(LogEvent event) {
String logMessage = super.getLogMessage(event);
return CustomMasker.mask(logMessage);
}
}
Run Code Online (Sandbox Code Playgroud)
第四,创建一个 CustomMasker 类,您可以在其中拥有自己的字符串操作逻辑来屏蔽所需的信息。
让我知道它是否有效!
此消息告诉您的是使用该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>
Run Code Online (Sandbox Code Playgroud)
在内部您可以找到可比的org.apache.cxf.ext.logging.LoggingInInterceptor(链接)
我不是CXF用户,但是我想您必须与进行交互JaxWsProxyFactoryBean。
请记住,所有CXF模块都需要使用相同的版本。
抓住它之后,您就可以
factory.getInInterceptors().add(new MyCustomInterceptor());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3407 次 |
| 最近记录: |