mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Disable sentinel web filters.
This commit is contained in:
parent
effff23108
commit
68af16db4a
@ -2,23 +2,58 @@ package com.alibaba.cloud.sentinel.gateway;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.core.env.*;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by zhh on 2019/8/17.
|
||||
*/
|
||||
public class GatewayEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
private final static String SENTINEL_FILTER_ENABLED = "spring.cloud.sentinel.filter.enabled";
|
||||
private final static String FILTERS_DISABLED = "filters_disabled";
|
||||
private final static String PROPERTY_SOURCE_NAME = "defaultProperties";
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication springApplication) {
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(SENTINEL_FILTER_ENABLED, "false");
|
||||
PropertiesPropertySource propertySource = new PropertiesPropertySource(FILTERS_DISABLED, properties);
|
||||
environment.getPropertySources().addLast(propertySource);
|
||||
addDefaultPropertySource(environment);
|
||||
}
|
||||
|
||||
private void addDefaultPropertySource(ConfigurableEnvironment environment) {
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
configureDefaultProperties(map);
|
||||
|
||||
addOrReplace(environment.getPropertySources(), map);
|
||||
}
|
||||
|
||||
private void configureDefaultProperties(Map<String, Object> source) {
|
||||
// Required Properties
|
||||
source.put(SENTINEL_FILTER_ENABLED, "false");
|
||||
}
|
||||
|
||||
private void addOrReplace(MutablePropertySources propertySources,
|
||||
Map<String, Object> map) {
|
||||
MapPropertySource target = null;
|
||||
if (propertySources.contains(PROPERTY_SOURCE_NAME)) {
|
||||
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME);
|
||||
if (source instanceof MapPropertySource) {
|
||||
target = (MapPropertySource) source;
|
||||
for (String key : map.keySet()) {
|
||||
if (!target.containsProperty(key)) {
|
||||
target.getSource().put(key, map.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
target = new MapPropertySource(PROPERTY_SOURCE_NAME, map);
|
||||
}
|
||||
if (!propertySources.contains(PROPERTY_SOURCE_NAME)) {
|
||||
propertySources.addLast(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user