diff --git a/usergw-service/src/main/java/cn/ecpark/service/usergw/config/ConfigGateway.java b/usergw-service/src/main/java/cn/ecpark/service/usergw/config/ConfigGateway.java index 6424f00..d238cef 100644 --- a/usergw-service/src/main/java/cn/ecpark/service/usergw/config/ConfigGateway.java +++ b/usergw-service/src/main/java/cn/ecpark/service/usergw/config/ConfigGateway.java @@ -45,7 +45,7 @@ public class ConfigGateway implements RouteDefinitionLocator { // List mediaTypes = new ArrayList<>(); List defaultFilters = new ArrayList<>(); - HashMap , String>> specialField = new HashMap , String>>(); + HashMap, String>> specialField = new HashMap, String>>(); Set ignoreKey = new HashSet<>(); @Autowired @@ -54,7 +54,7 @@ public class ConfigGateway implements RouteDefinitionLocator { public ConfigGateway() { specialField.put("application", ConfigSpecialFunction::setApplication); specialField.put("registry", ConfigSpecialFunction::setRegistry); - + ignoreKey.add("predicates"); ignoreKey.add("filters"); } @@ -63,10 +63,7 @@ public class ConfigGateway implements RouteDefinitionLocator { @SuppressWarnings("unchecked") public Flux getRouteDefinitions() { // WebFluxConfigurationSupport a; - - - - + defaultFilters.clear(); Object inputStream = null; String[] gatewayConfigPathList = { "gateway.yml", "gateway.yaml", "Gateway.yml", "Gateway.yaml" }; for (String gatewayConfigPath : gatewayConfigPathList) { @@ -75,7 +72,7 @@ public class ConfigGateway implements RouteDefinitionLocator { break; } } - + if (inputStream != null) { Map configYaml = new Yaml().load((InputStream) inputStream); if (configYaml != null) { @@ -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 filters, Map defaultYaml) { // default-filters: 下的相关设置 Object unknownDefaultFilters = defaultYaml.get("default-filters"); + if (unknownDefaultFilters != null) { List defaultFiltersYaml = (ArrayList) 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) { @@ -266,44 +263,44 @@ public class ConfigGateway implements RouteDefinitionLocator { ReferenceConfig reference = new ReferenceConfig(); reference.setConnections(3); - String UriString = "dubbo://"; + String UriString = "dubbo://"; Object application = iter.get("application"); if (application != null) { BiConsumer, 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> entry : iter.entrySet() ) { + + for (Entry> 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, String> doFunc = specialField.get((String)key); - if(doFunc != null) { - doFunc.accept(reference, (String)value); + BiConsumer, 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(); } - } + } } } - + UriString += Extract.getReferenceConfigKey(reference); GenericServicePool gsPool = appContext.getBean(GenericServicePool.class); reference.setGeneric(true); - gsPool.put(UriString, reference.get()); + gsPool.put(UriString, reference.get()); return UriString; } @@ -322,17 +319,21 @@ public class ConfigGateway implements RouteDefinitionLocator { String yamlField) { List 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 filters, LinkedHashMap> iter, - String yamlField) { + private void ParseAndAddDubboFilters(String dubboUri, List filters, + LinkedHashMap> iter, String yamlField) { List filtersYaml = iter.get(yamlField); + filters.addAll(defaultFilters); + if (filtersYaml != null) { for (String filterString : filtersYaml) { FilterDefinition fd = new FilterDefinition(filterString);