修复test bug
This commit is contained in:
parent
7c56c84758
commit
e26d0c17a6
@ -83,12 +83,27 @@ 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> defaultFiltersYaml = (Map<String, Object>) configYaml.get("default-filters");
|
List<String> defaultFiltersYaml = null;
|
||||||
Map<String, Object> restfulYaml = (Map<String, Object>) configYaml.get("restful");
|
Map<String, Object> restfulYaml = null;
|
||||||
Map<String, Object> dubboYaml = (Map<String, Object>) configYaml.get("dubbo");
|
Map<String, Object> dubboYaml = null;
|
||||||
|
|
||||||
|
Object unknown;
|
||||||
|
unknown = configYaml.get("default-filters");
|
||||||
|
if (unknown != null) {
|
||||||
|
defaultFiltersYaml = (List<String>) unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
unknown = configYaml.get("restful");
|
||||||
|
if (unknown != null) {
|
||||||
|
restfulYaml = (Map<String, Object>) unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
unknown = configYaml.get("dubbo");
|
||||||
|
if (unknown != null) {
|
||||||
|
dubboYaml = (Map<String, Object>) unknown;
|
||||||
|
}
|
||||||
|
|
||||||
List<RouteDefinition> routeList = new ArrayList<RouteDefinition>();
|
List<RouteDefinition> routeList = new ArrayList<RouteDefinition>();
|
||||||
|
|
||||||
if (restfulYaml != null && !restfulYaml.isEmpty()) {
|
if (restfulYaml != null && !restfulYaml.isEmpty()) {
|
||||||
this.getDefaultFilter(defaultFilters, defaultFiltersYaml);
|
this.getDefaultFilter(defaultFilters, defaultFiltersYaml);
|
||||||
this.configRestful(routeList, restfulYaml);
|
this.configRestful(routeList, restfulYaml);
|
||||||
@ -115,7 +130,6 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void configRestful(List<RouteDefinition> routeList, Map<String, Object> restfulYaml) {
|
private void configRestful(List<RouteDefinition> routeList, Map<String, Object> restfulYaml) {
|
||||||
if (restfulYaml != null) {
|
|
||||||
|
|
||||||
Object unknownRoutes = restfulYaml.get("routes");
|
Object unknownRoutes = restfulYaml.get("routes");
|
||||||
if (unknownRoutes != null) {
|
if (unknownRoutes != null) {
|
||||||
@ -141,7 +155,7 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
routeList.add(rd);
|
routeList.add(rd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,16 +208,14 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param filters {@link #defaultFilters} 全局的默认过滤列表, 可以和Spring Cloud 默认配置一起生效
|
* @param filters {@link #defaultFilters} 全局的默认过滤列表, 可以和Spring Cloud
|
||||||
|
* 默认配置一起生效
|
||||||
* @param defaultYaml 配置Yaml.default-filters对象
|
* @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, List<String> defaultFiltersYaml) {
|
||||||
// default-filters: 下的相关设置
|
// default-filters: 下的相关设置
|
||||||
Object unknownDefaultFilters = defaultYaml.get("default-filters");
|
if (defaultFiltersYaml != null) {
|
||||||
|
|
||||||
if (unknownDefaultFilters != null) {
|
|
||||||
List<String> defaultFiltersYaml = (ArrayList<String>) unknownDefaultFilters;
|
|
||||||
for (String filterString : defaultFiltersYaml) {
|
for (String filterString : defaultFiltersYaml) {
|
||||||
filters.add(new FilterDefinition(filterString));
|
filters.add(new FilterDefinition(filterString));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
default-filters:
|
default-filters:
|
||||||
- AddResponseHeader=X-Response-Default-Foo, Default-Bar
|
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
|
||||||
|
|
||||||
restful:
|
restful:
|
||||||
routes:
|
routes:
|
||||||
|
@ -37,7 +37,7 @@ public class TestYaml {
|
|||||||
|
|
||||||
Assert.assertEquals(restfulYaml.getClass(), LinkedHashMap.class);
|
Assert.assertEquals(restfulYaml.getClass(), LinkedHashMap.class);
|
||||||
|
|
||||||
List<String> defaultFilters = ((Map<String, List<String>>)restfulYaml).get("default-filters");
|
List<String> defaultFilters = (List<String>)configYaml.get("default-filters");
|
||||||
Assert.assertNotNull(defaultFilters);
|
Assert.assertNotNull(defaultFilters);
|
||||||
|
|
||||||
Assert.assertEquals(defaultFilters.size(), 1);
|
Assert.assertEquals(defaultFilters.size(), 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user