Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonashackt/2479061ddcd24b1403fc to your computer and use it in GitHub Desktop.
Save jonashackt/2479061ddcd24b1403fc to your computer and use it in GitHub Desktop.
Extended Configuration of SOAP-Message-Logging with Apache CXF with Spring Profiles for real Prettyprinting
import javax.annotation.PostConstruct;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.interceptor.AbstractLoggingInterceptor;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
@Configuration
@Profile("logsoapmessages")
public class WebServiceMessageLoggerConfiguration {
@Autowired
private SpringBus springBus;
@PostConstruct
public void activateLoggingFeature() {
// Log SoapMessages to Logfile
springBus.getInInterceptors().add(logInInterceptor());
springBus.getInFaultInterceptors().add(logInInterceptor());
springBus.getOutInterceptors().add(logOutInterceptor());
springBus.getOutFaultInterceptors().add(logOutInterceptor());
}
@Bean
public AbstractLoggingInterceptor logInInterceptor() {
LoggingInInterceptor logInInterceptor = new LoggingInInterceptor();
// The In-Messages are pretty without setting it, when setting it Apache CXF throws empty lines into the In-Messages
return logInInterceptor;
}
@Bean
public AbstractLoggingInterceptor logOutInterceptor() {
LoggingOutInterceptor logOutInterceptor = new LoggingOutInterceptor();
logOutInterceptor.setPrettyLogging(true);
return logOutInterceptor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment