Apache CXF LoggingInInterceptor is deprecated - what to use instead?

天涯浪子 提交于 2019-12-10 10:35:17

问题


I am using Apache CXF with Spring Boot with the help of cxf-spring-boot-starter-jaxws plugin of version 3.2.7.

My intention is to customize the LoggingInterceptors but when I created the below class:

public class CustomLoggingInInterceptor extends org.apache.cxf.interceptor.LoggingInInterceptor {}

but my IDE strikes out the LoggingInInterceptor complaining it's deprecated with the explanation

use logging module rt/features/logging instead

So how should one go about customizing the logging interceptor using this module ?


回答1:


What this message is telling you, is to use the Apache CXF Advanced logging feature module.

Its dependency is (latest version)

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-features-logging</artifactId>
    <version>3.3.0</version>
    <scope>test</scope>
</dependency>

Inside you'll find a comparable org.apache.cxf.ext.logging.LoggingInInterceptor (link)


I'm not a CXF user, however I suppose you'll have to interact with a JaxWsProxyFactoryBean.
Remember you need to use the same version for all the CXF modules.

After getting an hold on it, you can do

factory.getInInterceptors().add(new MyCustomInterceptor());



回答2:


Basically 4 things are needed to update from the old to the new cxf logging (rt/features/logging).

First, Set the logging feature:

final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setFeatures(Collections.singletonList(new CustomLoggingFeature()));

You don't need anymore the interceptors (in case you used them, delete them):

factory.getInInterceptors().add(new CustomMaskedLoggingInInterceptor()); factory.getOutInterceptors().add(new CustomMaskedLoggingOutInterceptor());

Second, create your LoggingFeature:

public class CustomLoggingFeature extends org.apache.cxf.ext.logging.LoggingFeature {
    public CustomLoggingFeature() {
        super();
        this.setSender(new CustomEventLogSender());
    }
}

Third, create your EventLogSender:

public class CustomEventLogSender extends Slf4jVerboseEventSender {
    @Override
    protected String getLogMessage(LogEvent event) {
        String logMessage = super.getLogMessage(event);
        return CustomMasker.mask(logMessage);
    }
}

Fourth, create a CustomMasker class where you have your own string manipulation logic to mask the desired information.

Let me know if it worked!



来源:https://stackoverflow.com/questions/54989929/apache-cxf-loggingininterceptor-is-deprecated-what-to-use-instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!