Fix blank gateway context problem #458
This commit is contained in:
@@ -216,10 +216,15 @@ public abstract class WebUtils {
|
||||
if (svc == null) {
|
||||
String p = exchange.getRequest().getPath().value();
|
||||
int secFS = p.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||
String prefix = p.substring(0, secFS);
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
svc = p.substring(1, secFS);
|
||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
||||
svc = p.substring(secFS + 1, trdFS);
|
||||
} else {
|
||||
svc = p.substring(1, secFS);
|
||||
}
|
||||
} else {
|
||||
String prefix = p.substring(0, secFS);
|
||||
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
||||
svc = p.substring(secFS + 1, trdFS);
|
||||
@@ -340,10 +345,16 @@ public abstract class WebUtils {
|
||||
// p = exchange.getRequest().getPath().value();
|
||||
p = exchange.getRequest().getURI().getPath();
|
||||
int secFS = p.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||
String prefix = p.substring(0, secFS);
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
p = p.substring(secFS);
|
||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
||||
p = p.substring(trdFS);
|
||||
} else {
|
||||
p = p.substring(secFS);
|
||||
}
|
||||
} else {
|
||||
String prefix = p.substring(0, secFS);
|
||||
|
||||
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
||||
p = p.substring(trdFS);
|
||||
@@ -367,12 +378,16 @@ public abstract class WebUtils {
|
||||
public static String getClientReqPathPrefix(ServerWebExchange exchange) {
|
||||
String prefix = exchange.getAttribute(clientRequestPathPrefix);
|
||||
if (prefix == null) {
|
||||
String path = exchange.getRequest().getPath().value();
|
||||
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||
prefix = path.substring(0, secFS);
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
prefix = Consts.S.FORWARD_SLASH_STR;
|
||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
prefix = prefix + Consts.S.FORWARD_SLASH;
|
||||
} else {
|
||||
prefix = Consts.S.FORWARD_SLASH_STR;
|
||||
}
|
||||
} else {
|
||||
String path = exchange.getRequest().getPath().value();
|
||||
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||
prefix = path.substring(0, secFS);
|
||||
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
prefix = prefix + Consts.S.FORWARD_SLASH;
|
||||
} else {
|
||||
|
||||
@@ -31,6 +31,15 @@ public class WebUtilsTests {
|
||||
assertEquals("/ybiz", clientReqPath);
|
||||
String clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/_proxytest/", clientReqPathPrefix);
|
||||
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/_proxytestx/test/ybiz").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("test", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/ybiz", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/_proxytestx/", clientReqPathPrefix);
|
||||
|
||||
WebUtils.setGatewayPrefix("/prox");
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/prox/test/ybiz").build();
|
||||
@@ -39,6 +48,17 @@ public class WebUtilsTests {
|
||||
assertEquals("test", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/ybiz", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/prox/", clientReqPathPrefix);
|
||||
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/_proxytest/xservice/ybiz?a=b").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("xservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/ybiz", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/_proxytest/", clientReqPathPrefix);
|
||||
|
||||
WebUtils.setGatewayPrefix("");
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/aservice/ybiz1").build();
|
||||
@@ -47,6 +67,36 @@ public class WebUtilsTests {
|
||||
assertEquals("aservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/ybiz1", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/", clientReqPathPrefix);
|
||||
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/_proxytest/xservice/ybiz?a=b").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("xservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/ybiz", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/_proxytest/", clientReqPathPrefix);
|
||||
|
||||
WebUtils.setGatewayPrefix("/");
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/aservice/ybiz1").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("aservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/ybiz1", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/", clientReqPathPrefix);
|
||||
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/_proxytest/xservice/ybiz?a=b").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("xservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/ybiz", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/_proxytest/", clientReqPathPrefix);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user