All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.log.PlatformLogToolServletAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.log;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
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.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.zodiac.autoconfigure.log.condition.ConditionalOnPatformLogRequestEnabled;

@SpringBootConfiguration
@ConditionalOnPatformLogRequestEnabled
@ConditionalOnWebApplication(type = Type.SERVLET)
//@AutoConfigureAfter(value = {PlatformLogToolAutoConfiguration.class})
@ConditionalOnClass(value = {org.zodiac.log.LogOperations.class, javax.servlet.Servlet.class, org.springframework.web.servlet.DispatcherServlet.class})
public class PlatformLogToolServletAutoConfiguration {

    private final PlatformRequestLogProperties platformRequestLogProperties;
    private final ApplicationContext applicationContext;

    public PlatformLogToolServletAutoConfiguration(PlatformRequestLogProperties platformRequestLogProperties,
        ApplicationContext applicationContext) {
        this.platformRequestLogProperties = platformRequestLogProperties;
        this.applicationContext = applicationContext;
    }

    @Bean
    protected org.springframework.boot.web.servlet.FilterRegistrationBean logTraceFilterRegistration() {
        org.springframework.boot.web.servlet.FilterRegistrationBean registration = new org.springframework.boot.web.servlet.FilterRegistrationBean<>();
        registration.setDispatcherTypes(javax.servlet.DispatcherType.REQUEST);
        registration.setFilter(new org.zodiac.log.filter.ServletLogTraceFilter(applicationContext));
        registration.addUrlPatterns("/*");
        registration.setName("ServletLogTraceFilter");
        registration.setOrder(Ordered.LOWEST_PRECEDENCE);
        return registration;
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.log.aspect.RequestLogAspect requestLogAspect() {
        return new org.zodiac.log.aspect.ServletRequestLogAspect(platformRequestLogProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.log.error.PlatformRestExceptionTranslator platformRestExceptionTranslator(ObjectProvider errorLogPublisherProvider) {
        return new org.zodiac.log.error.PlatformServletRestExceptionTranslator(errorLogPublisherProvider.getIfAvailable());
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.log.error.ServletRestExceptionTranslator servletRestExceptionTranslator() {
        return new org.zodiac.log.error.ServletRestExceptionTranslator();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy