需要特殊方式解决, Test问题
This commit is contained in:
parent
bd1f4b577b
commit
e7dacaa09b
|
@ -1,5 +1,7 @@
|
|||
{"properties": [{
|
||||
"name": "yame.config",
|
||||
"type": "java.lang.String",
|
||||
"description": "用于配置网关的路径, 如果不填.默认: gateway.yml, gateway.yaml, Gateway.yml, Gateway.yaml"
|
||||
}]}
|
||||
{"properties": [
|
||||
{
|
||||
"name": "yame.gateway.config",
|
||||
"type": "java.lang.String",
|
||||
"description": "用于配置网关的路径, 如果不填.默认: gateway.yml, gateway.yaml, Gateway.yml, Gateway.yaml"
|
||||
}
|
||||
]}
|
|
@ -14,10 +14,9 @@ public class ConfigRefresh implements ApplicationEventPublisherAware {
|
|||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.publisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
|
||||
public void notifyChanged() {
|
||||
this.publisher.publishEvent(new RefreshRoutesEvent(this));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,9 +1,14 @@
|
|||
package cn.ecpark.service.usergw.config;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -30,6 +35,7 @@ import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
|
|||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import cn.ecpark.service.usergw.biz.filters.bean.GenericServicePool;
|
||||
|
@ -45,8 +51,8 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
// List<MediaType> mediaTypes = new ArrayList<>();
|
||||
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ConfigGateway.class);
|
||||
|
||||
@Value("${yame.config:}")
|
||||
private String yameConfigPath;
|
||||
@Value("${yame.gateway.config:}")
|
||||
private String gatewayConfigPath;
|
||||
|
||||
|
||||
|
||||
|
@ -130,21 +136,24 @@ public class ConfigGateway implements RouteDefinitionLocator {
|
|||
}
|
||||
|
||||
private InputStream loadLocalFileConfig() {
|
||||
Object inputStream = null;
|
||||
InputStream inputStream = null;
|
||||
String[] gatewayConfigPathList;
|
||||
if (yameConfigPath.equals("")) {
|
||||
if (gatewayConfigPath.equals("")) {
|
||||
gatewayConfigPathList = new String[] { "gateway.yml", "gateway.yaml", "Gateway.yml", "Gateway.yaml" };
|
||||
} else {
|
||||
gatewayConfigPathList = new String[] { yameConfigPath };
|
||||
gatewayConfigPathList = new String[] { gatewayConfigPath };
|
||||
}
|
||||
|
||||
for (String gatewayConfigPath : gatewayConfigPathList) {
|
||||
gatewayConfigPath = gatewayConfigPath.trim();
|
||||
inputStream = this.getClass().getClassLoader().getResourceAsStream(gatewayConfigPath);
|
||||
if (inputStream != null) {
|
||||
break;
|
||||
if(inputStream != null) {
|
||||
return inputStream;
|
||||
}
|
||||
}
|
||||
return (InputStream) inputStream;
|
||||
|
||||
log.error("can't find the config of gateway, like gateway.yaml");
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
spring.application.name=gateway
|
||||
|
||||
app.id=gateway
|
||||
apollo.meta=http://localhost:8180
|
||||
# app.id=gateway
|
||||
# apollo.meta=http://localhost:8180
|
||||
# local.meta=http://localhost:8180
|
||||
# dev.meta=http://localhost:8180
|
||||
# fat.meta=http://localhost:8180
|
||||
|
@ -22,7 +22,7 @@ server.port=8888
|
|||
|
||||
# logging.level.org.springframework.cloud.gateway=debug
|
||||
logging.file=logs/log
|
||||
yame.config=gateway.yaml
|
||||
yame.gateway.config=gateway.yaml
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.junit.runner.RunWith;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
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)
|
||||
@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 {
|
||||
|
||||
@LocalServerPort
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -1,44 +1,26 @@
|
|||
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
|
||||
- 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
|
||||
# methods: # 如果没填就从 request拿 意味着所有接口都可以使用
|
||||
|
||||
# - name: Say
|
||||
# param-types:
|
||||
# - java.lang.String
|
||||
# - name: Hello
|
||||
|
||||
connections: 4
|
||||
group: test
|
||||
|
@ -47,4 +29,23 @@ dubbo:
|
|||
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
|
||||
|
||||
|
|
@ -10,6 +10,5 @@ server.port=8888
|
|||
|
||||
# logging.level.org.springframework.cloud.gateway=debug
|
||||
logging.file=logs/log
|
||||
|
||||
yame.config=test-gateway.yaml
|
||||
yame.gateway.config=test-gateway.yaml
|
||||
|
Loading…
Reference in New Issue
Block a user