默认全局设置都要开始清空, 为了动态加载, 这样不会加载多次

This commit is contained in:
eson 2019-07-07 23:04:26 +08:00
parent 57355309b7
commit 6b61269e8e

View File

@ -45,7 +45,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
// List<MediaType> mediaTypes = new ArrayList<>();
List<FilterDefinition> defaultFilters = new ArrayList<>();
HashMap<String, BiConsumer<ReferenceConfig<GenericService> , String>> specialField = new HashMap<String, BiConsumer<ReferenceConfig<GenericService> , String>>();
HashMap<String, BiConsumer<ReferenceConfig<GenericService>, String>> specialField = new HashMap<String, BiConsumer<ReferenceConfig<GenericService>, String>>();
Set<String> ignoreKey = new HashSet<>();
@Autowired
@ -63,10 +63,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
@SuppressWarnings("unchecked")
public Flux<RouteDefinition> getRouteDefinitions() {
// WebFluxConfigurationSupport a;
defaultFilters.clear();
Object inputStream = null;
String[] gatewayConfigPathList = { "gateway.yml", "gateway.yaml", "Gateway.yml", "Gateway.yaml" };
for (String gatewayConfigPath : gatewayConfigPathList) {
@ -108,7 +105,6 @@ public class ConfigGateway implements RouteDefinitionLocator {
this.configHttp2Dubbo(routeList, dubboYaml);
}
if (!routeList.isEmpty()) {
return Flux.fromIterable(routeList);
}
@ -124,6 +120,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
private void getDefaultFilter(List<FilterDefinition> filters, Map<String, Object> defaultYaml) {
// default-filters: 下的相关设置
Object unknownDefaultFilters = defaultYaml.get("default-filters");
if (unknownDefaultFilters != null) {
List<String> defaultFiltersYaml = (ArrayList<String>) unknownDefaultFilters;
for (String filterString : defaultFiltersYaml) {
@ -199,7 +196,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
} catch (Exception e) {
log.error(e.toString());
log.warn("App is exit");
((ConfigurableApplicationContext)appContext).close();
((ConfigurableApplicationContext) appContext).close();
}
// gs.$invoke(method, parameterTypes, args)
@ -236,7 +233,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
// 设置uri
Object uri = iter.get("uri");
if(uri != null) {
if (uri != null) {
try {
rd.setUri(URI.create((String) uri));
} catch (Exception e) {
@ -270,31 +267,31 @@ public class ConfigGateway implements RouteDefinitionLocator {
Object application = iter.get("application");
if (application != null) {
BiConsumer<ReferenceConfig<GenericService>, String> doFunc = specialField.get("application");
if(doFunc != null) {
doFunc.accept(reference, (String)application);
if (doFunc != null) {
doFunc.accept(reference, (String) application);
}
}
iter.remove("application");
for( Entry<String, List<String>> entry : iter.entrySet() ) {
for (Entry<String, List<String>> entry : iter.entrySet()) {
// Object group = iter.get("group");
String key = entry.getKey();
if(ignoreKey.contains(key)) {
if (ignoreKey.contains(key)) {
continue;
}
Object value = entry.getValue();
if (value != null) {
BiConsumer<ReferenceConfig<GenericService>, String> doFunc = specialField.get((String)key);
if(doFunc != null) {
doFunc.accept(reference, (String)value);
BiConsumer<ReferenceConfig<GenericService>, String> doFunc = specialField.get((String) key);
if (doFunc != null) {
doFunc.accept(reference, (String) value);
} else {
try {
ConfigSpecialFunction.setDefault(reference, key, value);
} catch (Exception e) {
log.error("配置解析错误 字段: {}:{}\n{}", key, value, e.toString());
log.warn("App is exit");
((ConfigurableApplicationContext)appContext).close();
((ConfigurableApplicationContext) appContext).close();
}
}
}
@ -322,17 +319,21 @@ public class ConfigGateway implements RouteDefinitionLocator {
String yamlField) {
List<String> filtersYaml = iter.get(yamlField);
if (filtersYaml != null) {
filters.addAll(defaultFilters);
for (String filterString : filtersYaml) {
filters.add(new FilterDefinition(filterString));
}
}
}
private void ParseAndAddDubboFilters(String dubboUri, List<FilterDefinition> filters, LinkedHashMap<String, List<String>> iter,
String yamlField) {
private void ParseAndAddDubboFilters(String dubboUri, List<FilterDefinition> filters,
LinkedHashMap<String, List<String>> iter, String yamlField) {
List<String> filtersYaml = iter.get(yamlField);
filters.addAll(defaultFilters);
if (filtersYaml != null) {
for (String filterString : filtersYaml) {
FilterDefinition fd = new FilterDefinition(filterString);