From eeeb0525c6ee2dd478fada781397e54c57a4e1d7 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 19 Mar 2019 15:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/LoadBalancerClientExtFilter.java | 4 ++-- .../util/{RoutePathUtil.java => RouteUtil.java} | 16 +++++++++++----- .../zuul/route/ZuulZookeeperRouteManager.java | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) rename sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/{RoutePathUtil.java => RouteUtil.java} (54%) diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LoadBalancerClientExtFilter.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LoadBalancerClientExtFilter.java index 109a44bf..cb447ba0 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LoadBalancerClientExtFilter.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LoadBalancerClientExtFilter.java @@ -1,6 +1,6 @@ package com.gitee.sop.gatewaycommon.gateway.filter; -import com.gitee.sop.gatewaycommon.util.RoutePathUtil; +import com.gitee.sop.gatewaycommon.util.RouteUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; @@ -47,7 +47,7 @@ public class LoadBalancerClientExtFilter implements GlobalFilter, Ordered { protected String findPath(Route route) { URI routeUri = route.getUri(); String uriStr = routeUri.toString(); - return RoutePathUtil.findPath(uriStr); + return RouteUtil.findPath(uriStr); } } diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RoutePathUtil.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RouteUtil.java similarity index 54% rename from sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RoutePathUtil.java rename to sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RouteUtil.java index db5a079b..ebe5d393 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RoutePathUtil.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RouteUtil.java @@ -1,16 +1,14 @@ package com.gitee.sop.gatewaycommon.util; -import org.springframework.cloud.gateway.route.Route; - -import java.net.URI; - /** * @author tanghc */ -public class RoutePathUtil { +public class RouteUtil { public static final String REGEX = "\\#"; + public static final String PROTOCOL_LOAD_BALANCE = "lb://"; + public static String findPath(String uri) { // #后面是对应的path String[] uriArr = uri.split(REGEX); @@ -20,4 +18,12 @@ public class RoutePathUtil { return null; } } + + public static String getZuulLocation(String uri) { + if (uri.toLowerCase().startsWith(PROTOCOL_LOAD_BALANCE)) { + return uri.substring(PROTOCOL_LOAD_BALANCE.length()); + } + return uri; + } + } diff --git a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulZookeeperRouteManager.java b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulZookeeperRouteManager.java index 75a3b03b..3485ad3c 100644 --- a/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulZookeeperRouteManager.java +++ b/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulZookeeperRouteManager.java @@ -2,7 +2,7 @@ package com.gitee.sop.gatewaycommon.zuul.route; import com.gitee.sop.gatewaycommon.manager.BaseRouteManager; import com.gitee.sop.gatewaycommon.manager.RouteRepository; -import com.gitee.sop.gatewaycommon.util.RoutePathUtil; +import com.gitee.sop.gatewaycommon.util.RouteUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.netflix.zuul.filters.Route; import org.springframework.core.env.Environment; @@ -31,7 +31,9 @@ public class ZuulZookeeperRouteManager extends BaseRouteManager