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

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

package org.zodiac.autoconfigure.log;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
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.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.web.ResourceProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler;
import org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration;
import org.springframework.boot.web.reactive.error.DefaultErrorAttributes;
import org.springframework.boot.web.reactive.error.ErrorAttributes;
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.zodiac.autoconfigure.log.condition.ConditionalOnPatformLogRequestEnabled;
import org.zodiac.autoconfigure.log.error.ReactiveErrorHandler;

@ConditionalOnPatformLogRequestEnabled
@ConditionalOnWebApplication(type = Type.REACTIVE)
@SpringBootConfiguration
@AutoConfigureBefore(value = {ErrorWebFluxAutoConfiguration.class})
@ConditionalOnClass(value = {org.zodiac.log.LogOperations.class, org.springframework.web.server.WebHandler.class, org.springframework.web.reactive.DispatcherHandler.class})
public class PlatformLogErrorReactiveAutoConfiguration {

    private final ServerProperties serverProperties;

    private final ApplicationContext applicationContext;

    private final ResourceProperties resourceProperties;

    private final org.zodiac.log.publisher.ErrorLogPublisher errorLogPublisher;

    public PlatformLogErrorReactiveAutoConfiguration(ServerProperties serverProperties,
        ApplicationContext applicationContext, ResourceProperties resourceProperties,
        org.zodiac.log.publisher.ErrorLogPublisher errorLogPublisher) {
        this.serverProperties = serverProperties;
        this.applicationContext = applicationContext;
        this.resourceProperties = resourceProperties;
        this.errorLogPublisher = errorLogPublisher;
    }

    @Bean
    @ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)
    protected DefaultErrorAttributes errorAttributes() {
        return new org.zodiac.log.error.ReactiveErrorAttributes(errorLogPublisher);
    }

    @Bean
    @ConditionalOnMissingBean(value = ErrorWebExceptionHandler.class, search = SearchStrategy.CURRENT)
    protected DefaultErrorWebExceptionHandler defaultErrorWebExceptionHandler(ErrorAttributes errorAttributes,
        ServerCodecConfigurer serverCodecConfigurer) {
        ReactiveErrorHandler errorHandler = new ReactiveErrorHandler(errorAttributes, resourceProperties, serverProperties.getError(), applicationContext);
        errorHandler.setMessageWriters(serverCodecConfigurer.getWriters());
        return errorHandler;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy