org.zodiac.autoconfigure.web.error.ReactiveErrorAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.web.error;
import java.util.stream.Collectors;
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.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.autoconfigure.web.ResourceProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.result.view.ViewResolver;
import org.zodiac.autoconfigure.web.HttpContextProperties;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.web.error.CompositeErrorConfigurer;
import org.zodiac.core.web.reactive.ReactiveSmartErrorHandler;
@SpringBootConfiguration
@ConditionalOnWebApplication(type = Type.REACTIVE)
@ConditionalOnClass(value = {freemarker.template.Template.class})
@ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_HTTP_CONTEXT_ERROR_HANDLER_ENABLED, havingValue = "true")
public class ReactiveErrorAutoConfiguration extends AbstractErrorAutoConfiguration {
public ReactiveErrorAutoConfiguration(ApplicationContext applicationContext,
HttpContextProperties httpContextProperties) {
super(applicationContext, httpContextProperties);
}
/*
* @see {@link org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration#errorWebExceptionHandler(org.springframework.boot.web.reactive.error.ErrorAttributes, ResourceProperties, ObjectProvider, ServerCodecConfigurer, ApplicationContext)}
*/
@Bean
@Order(value = -2) /*Takes precedence over the default handler*/
@ConditionalOnMissingBean
public ReactiveSmartErrorHandler reactiveSmartErrorHandler(
org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes,
ResourceProperties resourceProperties, ObjectProvider viewResolvers,
ServerCodecConfigurer codecConfigurer, CompositeErrorConfigurer compositeErrorConfigurer) {
ReactiveSmartErrorHandler errorHandler = new ReactiveSmartErrorHandler(errorAttributes, resourceProperties,
applicationContext, httpCommonErrorHandlerInfo, compositeErrorConfigurer);
errorHandler.setViewResolvers(viewResolvers.orderedStream().collect(Collectors.toList()));
errorHandler.setMessageWriters(codecConfigurer.getWriters());
errorHandler.setMessageReaders(codecConfigurer.getReaders());
return errorHandler;
}
}