需要特殊方式解决, Test问题

This commit is contained in:
eson 2019-08-15 04:07:32 +08:00
parent bd1f4b577b
commit e7dacaa09b
10 changed files with 59 additions and 164 deletions

View File

@ -1,5 +1,7 @@
{"properties": [{ {"properties": [
"name": "yame.config", {
"name": "yame.gateway.config",
"type": "java.lang.String", "type": "java.lang.String",
"description": "用于配置网关的路径, 如果不填.默认: gateway.yml, gateway.yaml, Gateway.yml, Gateway.yaml" "description": "用于配置网关的路径, 如果不填.默认: gateway.yml, gateway.yaml, Gateway.yml, Gateway.yaml"
}]} }
]}

View File

@ -19,5 +19,4 @@ public class ConfigRefresh implements ApplicationEventPublisherAware {
this.publisher.publishEvent(new RefreshRoutesEvent(this)); this.publisher.publishEvent(new RefreshRoutesEvent(this));
} }
} }

View File

@ -1,9 +1,14 @@
package cn.ecpark.service.usergw.config; package cn.ecpark.service.usergw.config;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.URI; import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -30,6 +35,7 @@ import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import cn.ecpark.service.usergw.biz.filters.bean.GenericServicePool; import cn.ecpark.service.usergw.biz.filters.bean.GenericServicePool;
@ -45,8 +51,8 @@ public class ConfigGateway implements RouteDefinitionLocator {
// List<MediaType> mediaTypes = new ArrayList<>(); // List<MediaType> mediaTypes = new ArrayList<>();
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ConfigGateway.class); private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ConfigGateway.class);
@Value("${yame.config:}") @Value("${yame.gateway.config:}")
private String yameConfigPath; private String gatewayConfigPath;
@ -130,21 +136,24 @@ public class ConfigGateway implements RouteDefinitionLocator {
} }
private InputStream loadLocalFileConfig() { private InputStream loadLocalFileConfig() {
Object inputStream = null; InputStream inputStream = null;
String[] gatewayConfigPathList; String[] gatewayConfigPathList;
if (yameConfigPath.equals("")) { if (gatewayConfigPath.equals("")) {
gatewayConfigPathList = new String[] { "gateway.yml", "gateway.yaml", "Gateway.yml", "Gateway.yaml" }; gatewayConfigPathList = new String[] { "gateway.yml", "gateway.yaml", "Gateway.yml", "Gateway.yaml" };
} else { } else {
gatewayConfigPathList = new String[] { yameConfigPath }; gatewayConfigPathList = new String[] { gatewayConfigPath };
} }
for (String gatewayConfigPath : gatewayConfigPathList) { for (String gatewayConfigPath : gatewayConfigPathList) {
gatewayConfigPath = gatewayConfigPath.trim(); gatewayConfigPath = gatewayConfigPath.trim();
inputStream = this.getClass().getClassLoader().getResourceAsStream(gatewayConfigPath); inputStream = this.getClass().getClassLoader().getResourceAsStream(gatewayConfigPath);
if(inputStream != null) { if(inputStream != null) {
break; return inputStream;
} }
} }
return (InputStream) inputStream;
log.error("can't find the config of gateway, like gateway.yaml");
return inputStream;
} }

View File

@ -1,8 +1,8 @@
spring.application.name=gateway spring.application.name=gateway
app.id=gateway # app.id=gateway
apollo.meta=http://localhost:8180 # apollo.meta=http://localhost:8180
# local.meta=http://localhost:8180 # local.meta=http://localhost:8180
# dev.meta=http://localhost:8180 # dev.meta=http://localhost:8180
# fat.meta=http://localhost:8180 # fat.meta=http://localhost:8180
@ -22,7 +22,7 @@ server.port=8888
# logging.level.org.springframework.cloud.gateway=debug # logging.level.org.springframework.cloud.gateway=debug
logging.file=logs/log logging.file=logs/log
yame.config=gateway.yaml yame.gateway.config=gateway.yaml

View File

@ -6,6 +6,7 @@ import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.PropertySource;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
@ -15,10 +16,9 @@ import reactor.netty.http.client.HttpClientResponse;
// TODO: 添加附加Dubbo Service for Test启动进程
@SpringBootTest(classes= App.class, webEnvironment = WebEnvironment.RANDOM_PORT) @SpringBootTest(classes= App.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@TestPropertySource(locations = "test.properties", properties = {"apollo.meta=", "app.id="}) @TestPropertySource(locations = "classpath:/resources/test.properties", properties = {"apollo.meta=", "app.id="})
public class TestHttp2DubboConfig { public class TestHttp2DubboConfig {
@LocalServerPort @LocalServerPort

View File

@ -1,51 +0,0 @@
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
restful:
routes:
- id: path_route
uri: http://httpbin.org:80/*
order: 9
predicates:
- Path=/get
- Header=XX, \d+
dubbo:
routes:
- id: test
order: 0
application: dubbo-exchange
# methods: # 如果没填就从 request拿 意味着所有接口都可以使用
# - name: Say
# param-types:
# - java.lang.String
# - name: Hello
connections: 4
group: test
# registry: zookeeper://127.0.0.1:2181
interface: ocean.demo.api.IExchange
version: 1.0.0
predicates:
- Path=/dubbo/hello
- id: test2
order: 0
application: dubbo-exchange
# methods: # 如果没填就从 request拿 意味着所有接口都可以使用
# - name: Say
# param-types:
# - java.lang.String
# - name: Hello
connections: 4
group: test
# registry: zookeeper://127.0.0.1:2181
interface: ocean.demo.api.IExchange
version: 1.0.0
predicates:
- Path=/dubbo/hello

View File

@ -1,13 +0,0 @@
spring.application.name=gateway
dubbo.scan.base-packages=cn.ecpark.service.usergw.impl
dubbo.protocol.name=dubbo
dubbo.protocol.port=20999
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.config-center.address=zookeeper://127.0.0.1:2181
dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
server.port=8888
# logging.level.org.springframework.cloud.gateway=debug
logging.file=logs/log

View File

@ -1,51 +0,0 @@
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Test-Default-Bar
restful:
routes:
- id: path_route
uri: http://httpbin.org:80/*
order: 9
predicates:
- Path=/get
- Header=XX, \d+
- id: path_route12;
uri: http://httpbin.org:80/*
order: 9
predicates:
- Path=/get
- Header=XX, \d+
- id: path_route13
uri: http://httpbin.org:80/*
order: 9
predicates:
- Path=/get
- Header=XX, \d+
# - id: redirect_to
# uri: http://localhost/test/**
# order: 11
# filters:
# - RedirectTo=302, http://httpbin.org:80/get
dubbo:
routes:
- id: test
order: 0
application: dubbo-exchange
# methods: # 如果没填就从 request拿 意味着所有接口都可以使用
# - name: Say
# param-types:
# - java.lang.String
# - name: Hello
connections: 4
group: test
# registry: zookeeper://127.0.0.1:2181
interface: ocean.demo.api.IExchange
version: 1.0.0
predicates:
- Path=/dubbo/hello

View File

@ -10,35 +10,17 @@ restful:
- Path=/get - Path=/get
- Header=XX, \d+ - Header=XX, \d+
- id: path_route12;
uri: http://httpbin.org:80/*
order: 9
predicates:
- Path=/get
- Header=XX, \d+
- id: path_route13
uri: http://httpbin.org:80/*
order: 9
predicates:
- Path=/get
- Header=XX, \d+
# - id: redirect_to
# uri: http://localhost/test/**
# order: 11
# filters:
# - RedirectTo=302, http://httpbin.org:80/get
dubbo: dubbo:
routes: routes:
- id: test - id: test
order: 0 order: 0
application: dubbo-exchange application: dubbo-exchange
methods: # 如果没填就从 request拿 意味着所有接口都可以使用 # methods: # 如果没填就从 request拿 意味着所有接口都可以使用
- name: Say
param-types: # - name: Say
- java.lang.String # param-types:
- name: Hello # - java.lang.String
# - name: Hello
connections: 4 connections: 4
group: test group: test
@ -48,3 +30,22 @@ dubbo:
predicates: predicates:
- Path=/dubbo/hello - Path=/dubbo/hello
- id: test2
order: 0
application: dubbo-exchange
# methods: # 如果没填就从 request拿 意味着所有接口都可以使用
# - name: Say
# param-types:
# - java.lang.String
# - name: Hello
connections: 4
group: test
# registry: zookeeper://127.0.0.1:2181
interface: ocean.demo.api.IExchange
version: 1.0.0
predicates:
- Path=/dubbo/hello

View File

@ -10,6 +10,5 @@ server.port=8888
# logging.level.org.springframework.cloud.gateway=debug # logging.level.org.springframework.cloud.gateway=debug
logging.file=logs/log logging.file=logs/log
yame.gateway.config=test-gateway.yaml
yame.config=test-gateway.yaml