添加一个简单的yaml配置加载测试.

This commit is contained in:
huangsimin 2019-07-09 11:43:12 +08:00
parent dc759f8489
commit 01a175cfaa
5 changed files with 111 additions and 47 deletions

View File

@ -1,30 +0,0 @@
package cn.ecpark.service.usergw.impl.http;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* Http2Dubbo
*/
@Controller
@RestController
public class Http2Dubbo {
@ResponseBody
public String H2DTest() {
//Do clever stuff here
return "H2DTest";
// return new ResponseEntity<>(HttpStatus.OK);
}
@RequestMapping("/test/request")
public String fuck() {
return "request";
}
}

View File

@ -1,17 +0,0 @@
package cn.ecpark.service.usergw.impl.rpc;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;
import cn.ecpark.service.usergw.api.IDemo;
// @Service(interfaceClass = IDemo.class)
// @Component
public class DemoHello implements IDemo {
@Override
public String Hello() {
return "Hello";
}
}

View File

@ -0,0 +1,48 @@
package cn.ecpark.service.usergw.utils;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.boot.test.context.TestComponent;
import org.yaml.snakeyaml.Yaml;
@TestComponent
public class TestYaml {
@SuppressWarnings("unchecked")
@Test
public void TestLoadYaml() {
Object inputStream = null;
String[] gatewayConfigPathList = { "test-gateway.yml", "test-gateway.yaml", "test-Gateway.yml",
"test-Gateway.yaml" };
for (String gatewayConfigPath : gatewayConfigPathList) {
inputStream = this.getClass().getResourceAsStream(gatewayConfigPath);
if (inputStream != null) {
break;
}
}
Assert.assertNotNull(inputStream);
Map<String, Object> configYaml = new Yaml().load((InputStream) inputStream);
Assert.assertNotNull(configYaml);
Object restfulYaml = configYaml.get("restful");
Object dubboYaml = configYaml.get("dubbo");
Assert.assertNotNull(restfulYaml);
Assert.assertNotNull(dubboYaml);
Assert.assertEquals(restfulYaml.getClass(), LinkedHashMap.class);
List<String> defaultFilters = ((Map<String, List<String>>)restfulYaml).get("default-filters");
Assert.assertNotNull(defaultFilters);
Assert.assertEquals(defaultFilters.size(), 1);
Assert.assertEquals(defaultFilters.getClass(), ArrayList.class);
Assert.assertEquals(defaultFilters.get(0), "AddResponseHeader=X-Response-Default-Foo, Default-Bar");
}
}

View File

@ -0,0 +1,50 @@
restful:
default-filters:
- AddResponseHeader=X-Response-Default-Foo, Default-Bar
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

@ -0,0 +1,13 @@
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