Search in sources :

Example 1 with SentinelProperties

use of com.alibaba.cloud.sentinel.SentinelProperties in project blade-tool by chillzhuang.

the class BladeSentinelFilterConfiguration method sentinelWebMvcConfig.

@Bean
public SentinelWebMvcConfig sentinelWebMvcConfig(SentinelProperties properties, Optional<UrlCleaner> urlCleanerOptional, Optional<BlockExceptionHandler> blockExceptionHandlerOptional, Optional<RequestOriginParser> requestOriginParserOptional) {
    SentinelWebMvcConfig sentinelWebMvcConfig = new SentinelWebMvcConfig();
    sentinelWebMvcConfig.setHttpMethodSpecify(properties.getHttpMethodSpecify());
    sentinelWebMvcConfig.setWebContextUnify(properties.getWebContextUnify());
    if (blockExceptionHandlerOptional.isPresent()) {
        blockExceptionHandlerOptional.ifPresent(sentinelWebMvcConfig::setBlockExceptionHandler);
    } else {
        if (StringUtils.hasText(properties.getBlockPage())) {
            sentinelWebMvcConfig.setBlockExceptionHandler(((request, response, e) -> response.sendRedirect(properties.getBlockPage())));
        } else {
            sentinelWebMvcConfig.setBlockExceptionHandler(new DefaultBlockExceptionHandler());
        }
    }
    urlCleanerOptional.ifPresent(sentinelWebMvcConfig::setUrlCleaner);
    requestOriginParserOptional.ifPresent(sentinelWebMvcConfig::setOriginParser);
    return sentinelWebMvcConfig;
}
Also used : DefaultBlockExceptionHandler(com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler) SentinelWebMvcConfig(com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig) SentinelWebInterceptor(com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor) UrlCleaner(com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SentinelProperties(com.alibaba.cloud.sentinel.SentinelProperties) Optional(java.util.Optional) RequestOriginParser(com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser) Bean(org.springframework.context.annotation.Bean) BlockExceptionHandler(com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler) ConditionalOnWebApplication(org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication) StringUtils(org.springframework.util.StringUtils) DefaultBlockExceptionHandler(com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler) SentinelWebMvcConfig(com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig) Bean(org.springframework.context.annotation.Bean)

Example 2 with SentinelProperties

use of com.alibaba.cloud.sentinel.SentinelProperties in project spring-cloud-alibaba by alibaba.

the class SentinelHealthIndicatorTests method setUp.

@Before
public void setUp() {
    beanFactory = mock(DefaultListableBeanFactory.class);
    sentinelProperties = mock(SentinelProperties.class);
    sentinelHealthIndicator = new SentinelHealthIndicator(beanFactory, sentinelProperties);
    SentinelConfig.setConfig(TransportConfig.CONSOLE_SERVER, "");
    heartbeatSender = mock(HeartbeatSender.class);
    Field heartbeatSenderField = ReflectionUtils.findField(HeartbeatSenderProvider.class, "heartbeatSender");
    heartbeatSenderField.setAccessible(true);
    ReflectionUtils.setField(heartbeatSenderField, null, heartbeatSender);
}
Also used : Field(java.lang.reflect.Field) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) SentinelProperties(com.alibaba.cloud.sentinel.SentinelProperties) HeartbeatSender(com.alibaba.csp.sentinel.transport.HeartbeatSender) Before(org.junit.Before)

Aggregations

SentinelProperties (com.alibaba.cloud.sentinel.SentinelProperties)2 SentinelWebInterceptor (com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor)1 BlockExceptionHandler (com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler)1 DefaultBlockExceptionHandler (com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler)1 RequestOriginParser (com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser)1 UrlCleaner (com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner)1 SentinelWebMvcConfig (com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig)1 HeartbeatSender (com.alibaba.csp.sentinel.transport.HeartbeatSender)1 Field (java.lang.reflect.Field)1 Optional (java.util.Optional)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Before (org.junit.Before)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 ConditionalOnWebApplication (org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication)1 Bean (org.springframework.context.annotation.Bean)1 StringUtils (org.springframework.util.StringUtils)1