默认全局设置都要开始清空, 为了动态加载, 这样不会加载多次
This commit is contained in:
parent
57355309b7
commit
6b61269e8e
@ -45,7 +45,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
// List<MediaType> mediaTypes = new ArrayList<>();
|
// List<MediaType> mediaTypes = new ArrayList<>();
|
||||||
|
|
||||||
List<FilterDefinition> defaultFilters = 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<>();
|
Set<String> ignoreKey = new HashSet<>();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -63,10 +63,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Flux<RouteDefinition> getRouteDefinitions() {
|
public Flux<RouteDefinition> getRouteDefinitions() {
|
||||||
// WebFluxConfigurationSupport a;
|
// WebFluxConfigurationSupport a;
|
||||||
|
defaultFilters.clear();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Object inputStream = null;
|
Object inputStream = null;
|
||||||
String[] gatewayConfigPathList = { "gateway.yml", "gateway.yaml", "Gateway.yml", "Gateway.yaml" };
|
String[] gatewayConfigPathList = { "gateway.yml", "gateway.yaml", "Gateway.yml", "Gateway.yaml" };
|
||||||
for (String gatewayConfigPath : gatewayConfigPathList) {
|
for (String gatewayConfigPath : gatewayConfigPathList) {
|
||||||
@ -108,7 +105,6 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
this.configHttp2Dubbo(routeList, dubboYaml);
|
this.configHttp2Dubbo(routeList, dubboYaml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!routeList.isEmpty()) {
|
if (!routeList.isEmpty()) {
|
||||||
return Flux.fromIterable(routeList);
|
return Flux.fromIterable(routeList);
|
||||||
}
|
}
|
||||||
@ -124,6 +120,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
private void getDefaultFilter(List<FilterDefinition> filters, Map<String, Object> defaultYaml) {
|
private void getDefaultFilter(List<FilterDefinition> filters, Map<String, Object> defaultYaml) {
|
||||||
// default-filters: 下的相关设置
|
// default-filters: 下的相关设置
|
||||||
Object unknownDefaultFilters = defaultYaml.get("default-filters");
|
Object unknownDefaultFilters = defaultYaml.get("default-filters");
|
||||||
|
|
||||||
if (unknownDefaultFilters != null) {
|
if (unknownDefaultFilters != null) {
|
||||||
List<String> defaultFiltersYaml = (ArrayList<String>) unknownDefaultFilters;
|
List<String> defaultFiltersYaml = (ArrayList<String>) unknownDefaultFilters;
|
||||||
for (String filterString : defaultFiltersYaml) {
|
for (String filterString : defaultFiltersYaml) {
|
||||||
@ -199,7 +196,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.toString());
|
log.error(e.toString());
|
||||||
log.warn("App is exit");
|
log.warn("App is exit");
|
||||||
((ConfigurableApplicationContext)appContext).close();
|
((ConfigurableApplicationContext) appContext).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// gs.$invoke(method, parameterTypes, args)
|
// gs.$invoke(method, parameterTypes, args)
|
||||||
@ -236,7 +233,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
|
|
||||||
// 设置uri
|
// 设置uri
|
||||||
Object uri = iter.get("uri");
|
Object uri = iter.get("uri");
|
||||||
if(uri != null) {
|
if (uri != null) {
|
||||||
try {
|
try {
|
||||||
rd.setUri(URI.create((String) uri));
|
rd.setUri(URI.create((String) uri));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -270,31 +267,31 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
Object application = iter.get("application");
|
Object application = iter.get("application");
|
||||||
if (application != null) {
|
if (application != null) {
|
||||||
BiConsumer<ReferenceConfig<GenericService>, String> doFunc = specialField.get("application");
|
BiConsumer<ReferenceConfig<GenericService>, String> doFunc = specialField.get("application");
|
||||||
if(doFunc != null) {
|
if (doFunc != null) {
|
||||||
doFunc.accept(reference, (String)application);
|
doFunc.accept(reference, (String) application);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iter.remove("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");
|
// Object group = iter.get("group");
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
if(ignoreKey.contains(key)) {
|
if (ignoreKey.contains(key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
BiConsumer<ReferenceConfig<GenericService>, String> doFunc = specialField.get((String)key);
|
BiConsumer<ReferenceConfig<GenericService>, String> doFunc = specialField.get((String) key);
|
||||||
if(doFunc != null) {
|
if (doFunc != null) {
|
||||||
doFunc.accept(reference, (String)value);
|
doFunc.accept(reference, (String) value);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
ConfigSpecialFunction.setDefault(reference, key, value);
|
ConfigSpecialFunction.setDefault(reference, key, value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("配置解析错误 字段: {}:{}\n{}", key, value, e.toString());
|
log.error("配置解析错误 字段: {}:{}\n{}", key, value, e.toString());
|
||||||
log.warn("App is exit");
|
log.warn("App is exit");
|
||||||
((ConfigurableApplicationContext)appContext).close();
|
((ConfigurableApplicationContext) appContext).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -322,17 +319,21 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
String yamlField) {
|
String yamlField) {
|
||||||
List<String> filtersYaml = iter.get(yamlField);
|
List<String> filtersYaml = iter.get(yamlField);
|
||||||
if (filtersYaml != null) {
|
if (filtersYaml != null) {
|
||||||
|
|
||||||
filters.addAll(defaultFilters);
|
filters.addAll(defaultFilters);
|
||||||
|
|
||||||
for (String filterString : filtersYaml) {
|
for (String filterString : filtersYaml) {
|
||||||
filters.add(new FilterDefinition(filterString));
|
filters.add(new FilterDefinition(filterString));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseAndAddDubboFilters(String dubboUri, List<FilterDefinition> filters, LinkedHashMap<String, List<String>> iter,
|
private void ParseAndAddDubboFilters(String dubboUri, List<FilterDefinition> filters,
|
||||||
String yamlField) {
|
LinkedHashMap<String, List<String>> iter, String yamlField) {
|
||||||
List<String> filtersYaml = iter.get(yamlField);
|
List<String> filtersYaml = iter.get(yamlField);
|
||||||
|
|
||||||
filters.addAll(defaultFilters);
|
filters.addAll(defaultFilters);
|
||||||
|
|
||||||
if (filtersYaml != null) {
|
if (filtersYaml != null) {
|
||||||
for (String filterString : filtersYaml) {
|
for (String filterString : filtersYaml) {
|
||||||
FilterDefinition fd = new FilterDefinition(filterString);
|
FilterDefinition fd = new FilterDefinition(filterString);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user