添加注释, 修改后. 单元测试2个错误 TODO: fix 2 errors

This commit is contained in:
huangsimin 2019-07-09 18:50:15 +08:00
parent 9d16062648
commit 7c56c84758
5 changed files with 45 additions and 18 deletions

View File

@ -1,6 +1,7 @@
package cn.ecpark.service.usergw.config; package cn.ecpark.service.usergw.config;
import java.io.InputStream; import java.io.InputStream;
import java.lang.annotation.Documented;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -42,9 +43,9 @@ public class ConfigGateway implements RouteDefinitionLocator {
@Value("${yame.config}") @Value("${yame.config}")
private String yameConfigPath; private String yameConfigPath;
List<FilterDefinition> defaultFilters = new ArrayList<>(); private List<FilterDefinition> defaultFilters = new ArrayList<>();
HashMap<String, BiConsumer<ReferenceConfig<GenericService>, Object>> specialField = new HashMap<String, BiConsumer<ReferenceConfig<GenericService>, Object>>(); private HashMap<String, BiConsumer<ReferenceConfig<GenericService>, Object>> specialField = new HashMap<String, BiConsumer<ReferenceConfig<GenericService>, Object>>();
Set<String> ignoreKey = new HashSet<>(); private Set<String> ignoreKey = new HashSet<>();
@Autowired @Autowired
private ApplicationContext appContext; private ApplicationContext appContext;
@ -82,14 +83,15 @@ public class ConfigGateway implements RouteDefinitionLocator {
Map<String, Object> configYaml = new Yaml().load((InputStream) inputStream); Map<String, Object> configYaml = new Yaml().load((InputStream) inputStream);
if (configYaml != null) { if (configYaml != null) {
Map<String, Object> defaultYaml = (Map<String, Object>) configYaml.get("restful"); Map<String, Object> defaultFiltersYaml = (Map<String, Object>) configYaml.get("default-filters");
Map<String, Object> restfulYaml = (Map<String, Object>) configYaml.get("restful");
Map<String, Object> dubboYaml = (Map<String, Object>) configYaml.get("dubbo"); Map<String, Object> dubboYaml = (Map<String, Object>) configYaml.get("dubbo");
List<RouteDefinition> routeList = new ArrayList<RouteDefinition>(); List<RouteDefinition> routeList = new ArrayList<RouteDefinition>();
if (defaultYaml != null && !defaultYaml.isEmpty()) { if (restfulYaml != null && !restfulYaml.isEmpty()) {
this.getDefaultFilter(defaultFilters, defaultYaml); this.getDefaultFilter(defaultFilters, defaultFiltersYaml);
this.configDefault(routeList, defaultYaml); this.configRestful(routeList, restfulYaml);
} }
if (dubboYaml != null && !dubboYaml.isEmpty()) { if (dubboYaml != null && !dubboYaml.isEmpty()) {
@ -106,11 +108,16 @@ public class ConfigGateway implements RouteDefinitionLocator {
return Flux.empty(); return Flux.empty();
} }
/**
*
* @param routeList 路由列表
* @param restfulYaml 配置Yaml.restful对象
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void configDefault(List<RouteDefinition> routeList, Map<String, Object> defaultYaml) { private void configRestful(List<RouteDefinition> routeList, Map<String, Object> restfulYaml) {
if (defaultYaml != null) { if (restfulYaml != null) {
Object unknownRoutes = defaultYaml.get("routes"); Object unknownRoutes = restfulYaml.get("routes");
if (unknownRoutes != null) { if (unknownRoutes != null) {
List<LinkedHashMap<String, List<String>>> routes = (ArrayList<LinkedHashMap<String, List<String>>>) unknownRoutes; List<LinkedHashMap<String, List<String>>> routes = (ArrayList<LinkedHashMap<String, List<String>>>) unknownRoutes;
for (LinkedHashMap<String, List<String>> iter : routes) { for (LinkedHashMap<String, List<String>> iter : routes) {
@ -137,6 +144,11 @@ public class ConfigGateway implements RouteDefinitionLocator {
} }
} }
/**
*
* @param routeList 路由列表
* @param configDubbo 配置Yaml.dubbo对象
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void configHttp2Dubbo(List<RouteDefinition> routeList, Map<String, Object> configDubbo) { private void configHttp2Dubbo(List<RouteDefinition> routeList, Map<String, Object> configDubbo) {
@ -180,6 +192,11 @@ public class ConfigGateway implements RouteDefinitionLocator {
} }
/**
*
* @param filters {@link #defaultFilters} 全局的默认过滤列表, 可以和Spring Cloud 默认配置一起生效
* @param defaultYaml 配置Yaml.default-filters对象
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void getDefaultFilter(List<FilterDefinition> filters, Map<String, Object> defaultYaml) { private void getDefaultFilter(List<FilterDefinition> filters, Map<String, Object> defaultYaml) {
// default-filters: 下的相关设置 // default-filters: 下的相关设置
@ -193,6 +210,11 @@ public class ConfigGateway implements RouteDefinitionLocator {
} }
} }
/***
*
* @param rd 路由列表
* @param iter Yaml.restful.routes
*/
private void parseAndSetBase(RouteDefinition rd, LinkedHashMap<String, List<String>> iter) { private void parseAndSetBase(RouteDefinition rd, LinkedHashMap<String, List<String>> iter) {
// 设置id // 设置id
Object id = iter.get("id"); Object id = iter.get("id");

View File

@ -1,6 +1,8 @@
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Default-Bar
restful: restful:
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Default-Bar
routes: routes:
- id: path_route - id: path_route
uri: http://httpbin.org:80/* uri: http://httpbin.org:80/*

View File

@ -1,6 +1,7 @@
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Default-Bar
restful: restful:
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
routes: routes:
- id: path_route - id: path_route
uri: http://httpbin.org:80/* uri: http://httpbin.org:80/*

View File

@ -1,6 +1,7 @@
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
restful: restful:
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
routes: routes:
- id: path_route - id: path_route
uri: http://httpbin.org:80/* uri: http://httpbin.org:80/*

View File

@ -1,6 +1,7 @@
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
restful: restful:
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
routes: routes:
- id: path_route - id: path_route
uri: http://httpbin.org:80/* uri: http://httpbin.org:80/*