From 5369fcb8be3fe9f5f0fec3adf65bc9b65383f486 Mon Sep 17 00:00:00 2001 From: huangsimin Date: Thu, 4 Jul 2019 11:20:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95connections=20=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ecpark/service/usergw/App.java | 4 ++ .../factory/DubboGatewayFilterFactory.java | 4 +- .../service/usergw/config/ConfigGateway.java | 44 ++++++++++++++++++- .../src/main/resources/gateway.yaml | 4 +- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/usergw-service/src/main/java/cn/ecpark/service/usergw/App.java b/usergw-service/src/main/java/cn/ecpark/service/usergw/App.java index faf39c3..e22f35f 100644 --- a/usergw-service/src/main/java/cn/ecpark/service/usergw/App.java +++ b/usergw-service/src/main/java/cn/ecpark/service/usergw/App.java @@ -1,5 +1,7 @@ package cn.ecpark.service.usergw; +import java.net.URI; + import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; @@ -17,6 +19,8 @@ import org.springframework.context.annotation.Configuration; public class App { public static void main(String[] args) { + URI a = URI.create("dubbo://127.0.0.1/com.a.b?group=test&version=123"); + URI b = URI.create("dubbo://com.a.b?group=test&version=123"); SpringApplication.run(App.class, args); } diff --git a/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/factory/DubboGatewayFilterFactory.java b/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/factory/DubboGatewayFilterFactory.java index 6532654..7427247 100644 --- a/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/factory/DubboGatewayFilterFactory.java +++ b/usergw-service/src/main/java/cn/ecpark/service/usergw/biz/filters/factory/DubboGatewayFilterFactory.java @@ -75,11 +75,11 @@ public class DubboGatewayFilterFactory extends AbstractGatewayFilterFactory> iter) { + // 设置id + Object id = iter.get("id"); + if (id != null) { + rd.setId((String) id); + } + + // 设置uri + Object uri = iter.get("uri"); + if (uri != null) { + rd.setUri(URI.create((String) uri)); + } else { + rd.setUri(URI.create("dubbo://")); + } + + // 设置uri + Object order = iter.get("order"); + if (order != null) { + rd.setOrder((int) order); + } + + if(uri != null) { + String uriString = (String)uri; + uriString = uriString.trim(); + if(uriString.startsWith("dubbo://")) { // dubbo://127.0.0.1/interface? + return uriString ; + } + } + + Object registry = iter.get("registry"); + if (registry != null) { + rd.setOrder((int) order); + } + + Object application = iter.get("application"); + if (registry != null) { + rd.setOrder((int) order); + } + + return ""; + } + private void ParseAndAddPredicates(List predicates, LinkedHashMap> iter, String yamlField) { List predicatesYaml = iter.get(yamlField); diff --git a/usergw-service/src/main/resources/gateway.yaml b/usergw-service/src/main/resources/gateway.yaml index 4dcbb00..57bcb2f 100644 --- a/usergw-service/src/main/resources/gateway.yaml +++ b/usergw-service/src/main/resources/gateway.yaml @@ -20,8 +20,8 @@ dubbo: - id: test order: 10 application: dubbo-exchange - uri: http://httpbin.org:80/get - # path: /dubbo/hello + registry: zookeeper://127.0.0.1:2181 + uri: unknown interface: ocean.demo.api.IExchange version: 1.0.0 predicates: