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

grpcstarter.server.feature.exceptionhandling.ExceptionHandling Maven / Gradle / Ivy

There is a newer version: 3.4.1
Show newest version
package grpcstarter.server.feature.exceptionhandling;

import grpcstarter.server.GrpcServerProperties;
import grpcstarter.server.feature.exceptionhandling.annotation.AnnotationBasedGrpcExceptionResolver;
import grpcstarter.server.feature.exceptionhandling.annotation.DefaultGrpcExceptionAdvice;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Freeman
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(prefix = GrpcServerProperties.ExceptionHandling.PREFIX, name = "enabled", matchIfMissing = true)
public class ExceptionHandling {

    @Bean
    @ConditionalOnMissingBean
    public AnnotationBasedGrpcExceptionResolver annotationBasedGrpcExceptionHandler() {
        return new AnnotationBasedGrpcExceptionResolver();
    }

    @Bean
    @ConditionalOnMissingBean
    public ExceptionHandlingServerInterceptor grpcExceptionHandlingServerInterceptor(
            ObjectProvider exceptionHandlers,
            ObjectProvider unhandledExceptionProcessors) {
        return new ExceptionHandlingServerInterceptor(exceptionHandlers, unhandledExceptionProcessors);
    }

    @Configuration(proxyBeanMethods = false)
    @ConditionalOnProperty(
            prefix = GrpcServerProperties.ExceptionHandling.PREFIX,
            name = "default-exception-advice-enabled",
            matchIfMissing = true)
    static class DefaultGrpcExceptionAdviceConfiguration {

        @Bean
        @ConditionalOnMissingBean
        public DefaultGrpcExceptionAdvice defaultGrpcExceptionAdvice() {
            return new DefaultGrpcExceptionAdvice();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy