com.sap.cloud.yaas.servicesdk.springboot.logging.LoggingContextAutoConfiguration Maven / Gradle / Ivy
/*
* © 2017 SAP SE or an SAP affiliate company.
* All rights reserved.
* Please see http://www.sap.com/corporate-en/legal/copyright/index.epx for additional trademark information and
* notices.
*/
package com.sap.cloud.yaas.servicesdk.springboot.logging;
import javax.servlet.Filter;
import com.sap.cloud.yaas.servicesdk.loggingfilters.LoggingContextFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
/**
* Auto Configuration class that auto-registers the functionality of logging-filters library of the YaaS Service SDK.
*
* It registers a RAML rewriting {@link LoggingContextFilter} that uses provides YaaS specific logging format.
*/
@Configuration
@ConditionalOnClass({
LoggingContextFilter.class,
DelegatingFilterProxyRegistrationBean.class})
@ConditionalOnWebApplication
@EnableConfigurationProperties(LoggingContextProperties.class)
public class LoggingContextAutoConfiguration
{
@Autowired
private LoggingContextProperties properties;
/**
* Factory method that instantiates the {@code LoggingContextFilter} from the YaaS Service SDK.
*
* @return The loggingContextFilter bean.
*/
@Bean
@Lazy
public Filter loggingContextFilter()
{
return new LoggingContextFilter();
}
/**
* Factory method that registers the {@link #loggingContextFilter()} bean as a Filter for all requests.
*
* @return The loggingContextFilterRegistration bean.
*/
@Bean
@ConditionalOnMissingBean(name = "loggingContextFilterRegistration")
public DelegatingFilterProxyRegistrationBean loggingContextFilterRegistration()
{
final DelegatingFilterProxyRegistrationBean registration = new DelegatingFilterProxyRegistrationBean(
"loggingContextFilter");
if (properties.getFilterOrder() != null)
{
registration.setOrder(properties.getFilterOrder());
}
return registration;
}
}