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

org.zodiac.autoconfigure.sentinel.web.SentinelServletAutoConfiguration Maven / Gradle / Ivy

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

import java.util.Optional;

import org.springframework.beans.factory.annotation.Value;
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.context.annotation.Bean;
import org.zodiac.autoconfigure.bootstrap.condition.ConditionalOnSpringCloudBootstrapDisabled;
import org.zodiac.autoconfigure.sentinel.SentinelConfigProperties;
import org.zodiac.autoconfigure.sentinel.condition.ConditionalOnSentinelConfigEnabled;
import org.zodiac.commons.constants.SystemPropertiesConstants;

@SpringBootConfiguration
@ConditionalOnSentinelConfigEnabled
@ConditionalOnSpringCloudBootstrapDisabled
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass(value = {com.alibaba.csp.sentinel.Env.class, com.alibaba.csp.sentinel.annotation.aspectj.AbstractSentinelAspectSupport.class, com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor.class, org.zodiac.sentinel.base.model.SentinelRule.class})
public class SentinelServletAutoConfiguration {

    private String projectName;
    private SentinelConfigProperties sentinelConfigProperties;

    public SentinelServletAutoConfiguration(
        @Value("${" + org.zodiac.sentinel.base.constants.SentinelBaseSystemPropertiesConstants.Sentinel.PROJECT_NAME + ":${" + SystemPropertiesConstants.Spring.SPRING_APP_NAME + ":}}") String projectName,
        SentinelConfigProperties sentinelConfigProperties) {
        this.projectName = projectName;
        this.sentinelConfigProperties = sentinelConfigProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.sentinel.base.config.web.ServletSentinelConfigurer servletSentinelConfigurer(
        Optional urlCleanerOptional,
        Optional blockExceptionHandlerOptional,
        Optional requestOriginParserOptional,
        Optional sentinelWebInterceptorOptional) {
        return new org.zodiac.sentinel.base.config.web.ServletSentinelConfigurer(projectName, sentinelConfigProperties, urlCleanerOptional,
            blockExceptionHandlerOptional, requestOriginParserOptional, sentinelWebInterceptorOptional);
    }

//    @Bean
//    @ConditionalOnMissingBean
//    protected  com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser requestOriginParser(org.zodiac.sentinel.base.config.web.ServletSentinelConfigurer servletSentinelConfigurer) {
//        return servletSentinelConfigurer.requestOriginParser();
//    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(name = org.zodiac.sentinel.base.constants.SentinelBaseSystemPropertiesConstants.Zodiac.SENTINEL_HTTP_FILTER_ENABLED, havingValue = "true", matchIfMissing = true)
    protected com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig sentinelWebMvcConfig(
        org.zodiac.sentinel.base.config.web.ServletSentinelConfigurer servletSentinelConfigurer) {
        return servletSentinelConfigurer.sentinelWebMvcConfig();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(name = org.zodiac.sentinel.base.constants.SentinelBaseSystemPropertiesConstants.Zodiac.SENTINEL_HTTP_FILTER_ENABLED, havingValue = "true", matchIfMissing = true)
    protected com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor sentinelWebInterceptor(
        org.zodiac.sentinel.base.config.web.ServletSentinelConfigurer servletSentinelConfigurer,
        com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig sentinelWebMvcConfig) {
        return servletSentinelConfigurer.sentinelWebInterceptor(sentinelWebMvcConfig);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy