简体   繁体   中英

Apache CXF LoggingInInterceptor is deprecated - what to use instead?

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 ?

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());

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!

When you have this elsewhere mentioned dependency:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-features-logging</artifactId>
    <version>${org.apache.cxf.version}</version>
</dependency>

and when you work with a JaxWsProxyFactoryBean , you can configure that factory eg like this:

LoggingFeature loggingFeature = new LoggingFeature();
loggingFeature.setPrettyLogging(true);
loggingFeature.setVerbose(true);
loggingFeature.setLogMultipart(true);
factory.getFeatures().add(loggingFeature);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM