'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 ?
Solution 1:[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());
Solution 2:[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!
Solution 3:[3]
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 e.g. like this:
LoggingFeature loggingFeature = new LoggingFeature();
loggingFeature.setPrettyLogging(true);
loggingFeature.setVerbose(true);
loggingFeature.setLogMultipart(true);
factory.getFeatures().add(loggingFeature);
Solution 4:[4]
The new imports for this class are :
import org.apache.cxf.ext.logging.LoggingInInterceptor;
import org.apache.cxf.ext.logging.LoggingOutInterceptor;
which could be found in the org.apache.cxf:cxf-rt-features-logging dependency.
Please refer to this question for code snippets.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | |
| Solution 3 | |
| Solution 4 | Pierre C |
