添加注释, 修改后. 单元测试2个错误 TODO: fix 2 errors
This commit is contained in:
parent
9d16062648
commit
7c56c84758
|
@ -1,6 +1,7 @@
|
|||
package cn.ecpark.service.usergw.config;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -42,9 +43,9 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
@Value("${yame.config}")
|
||||
private String yameConfigPath;
|
||||
|
||||
List<FilterDefinition> defaultFilters = new ArrayList<>();
|
||||
HashMap<String, BiConsumer<ReferenceConfig<GenericService>, Object>> specialField = new HashMap<String, BiConsumer<ReferenceConfig<GenericService>, Object>>();
|
||||
Set<String> ignoreKey = new HashSet<>();
|
||||
private List<FilterDefinition> defaultFilters = new ArrayList<>();
|
||||
private HashMap<String, BiConsumer<ReferenceConfig<GenericService>, Object>> specialField = new HashMap<String, BiConsumer<ReferenceConfig<GenericService>, Object>>();
|
||||
private Set<String> ignoreKey = new HashSet<>();
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext appContext;
|
||||
|
@ -82,14 +83,15 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
Map<String, Object> configYaml = new Yaml().load((InputStream) inputStream);
|
||||
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");
|
||||
|
||||
List<RouteDefinition> routeList = new ArrayList<RouteDefinition>();
|
||||
|
||||
if (defaultYaml != null && !defaultYaml.isEmpty()) {
|
||||
this.getDefaultFilter(defaultFilters, defaultYaml);
|
||||
this.configDefault(routeList, defaultYaml);
|
||||
if (restfulYaml != null && !restfulYaml.isEmpty()) {
|
||||
this.getDefaultFilter(defaultFilters, defaultFiltersYaml);
|
||||
this.configRestful(routeList, restfulYaml);
|
||||
}
|
||||
|
||||
if (dubboYaml != null && !dubboYaml.isEmpty()) {
|
||||
|
@ -106,11 +108,16 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
return Flux.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param routeList 路由列表
|
||||
* @param restfulYaml 配置Yaml.restful对象
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void configDefault(List<RouteDefinition> routeList, Map<String, Object> defaultYaml) {
|
||||
if (defaultYaml != null) {
|
||||
private void configRestful(List<RouteDefinition> routeList, Map<String, Object> restfulYaml) {
|
||||
if (restfulYaml != null) {
|
||||
|
||||
Object unknownRoutes = defaultYaml.get("routes");
|
||||
Object unknownRoutes = restfulYaml.get("routes");
|
||||
if (unknownRoutes != null) {
|
||||
List<LinkedHashMap<String, List<String>>> routes = (ArrayList<LinkedHashMap<String, List<String>>>) unknownRoutes;
|
||||
for (LinkedHashMap<String, List<String>> iter : routes) {
|
||||
|
@ -137,6 +144,11 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param routeList 路由列表
|
||||
* @param configDubbo 配置Yaml.dubbo对象
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
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")
|
||||
private void getDefaultFilter(List<FilterDefinition> filters, Map<String, Object> defaultYaml) {
|
||||
// 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) {
|
||||
// 设置id
|
||||
Object id = iter.get("id");
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
default-filters:
|
||||
- AddResponseHeader=X-Response-Default-Foo, Default-Bar
|
||||
|
||||
restful:
|
||||
default-filters:
|
||||
- AddResponseHeader=X-Response-Default-Foo, Default-Bar
|
||||
routes:
|
||||
- id: path_route
|
||||
uri: http://httpbin.org:80/*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
default-filters:
|
||||
- AddResponseHeader=X-Response-Default-Foo, Default-Bar
|
||||
|
||||
restful:
|
||||
default-filters:
|
||||
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
|
||||
routes:
|
||||
- id: path_route
|
||||
uri: http://httpbin.org:80/*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
default-filters:
|
||||
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
|
||||
|
||||
restful:
|
||||
default-filters:
|
||||
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
|
||||
routes:
|
||||
- id: path_route
|
||||
uri: http://httpbin.org:80/*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
default-filters:
|
||||
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
|
||||
|
||||
restful:
|
||||
default-filters:
|
||||
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
|
||||
routes:
|
||||
- id: path_route
|
||||
uri: http://httpbin.org:80/*
|
||||
|
|
Loading…
Reference in New Issue
Block a user