Handler client request with / path
This commit is contained in:
@@ -224,6 +224,18 @@ public abstract class WebUtils {
|
||||
if (svc == null) {
|
||||
String p = exchange.getRequest().getPath().value();
|
||||
int secFS = p.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||
if (secFS == -1) {
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
svc = p.substring(1);
|
||||
} else {
|
||||
String prefix = p.substring(1);
|
||||
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
throw Utils.runtimeExceptionWithoutStack("no service in request path");
|
||||
} else {
|
||||
throw Utils.runtimeExceptionWithoutStack("request prefix is wrong and no service in request path");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String prefix = p.substring(0, secFS);
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
@@ -243,6 +255,7 @@ public abstract class WebUtils {
|
||||
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
exchange.getAttributes().put(clientService, svc);
|
||||
}
|
||||
return svc;
|
||||
@@ -356,6 +369,18 @@ public abstract class WebUtils {
|
||||
// p = exchange.getRequest().getPath().value();
|
||||
p = exchange.getRequest().getURI().getPath();
|
||||
int secFS = p.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||
if (secFS == -1) {
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
p = Consts.S.FORWARD_SLASH_STR;
|
||||
} else {
|
||||
String prefix = p.substring(1);
|
||||
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
throw Utils.runtimeExceptionWithoutStack("no service and request path");
|
||||
} else {
|
||||
throw Utils.runtimeExceptionWithoutStack("request prefix is wrong, no service and request path");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String prefix = p.substring(0, secFS);
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
@@ -365,7 +390,6 @@ public abstract class WebUtils {
|
||||
p = p.substring(secFS);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
||||
if (trdFS == -1) {
|
||||
@@ -377,6 +401,7 @@ public abstract class WebUtils {
|
||||
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
exchange.getAttributes().put(clientRequestPath, p);
|
||||
}
|
||||
return p;
|
||||
@@ -395,6 +420,18 @@ public abstract class WebUtils {
|
||||
if (prefix == null) {
|
||||
String path = exchange.getRequest().getPath().value();
|
||||
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||
if (secFS == -1) {
|
||||
prefix = path.substring(1);
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
prefix = Consts.S.FORWARD_SLASH_STR;
|
||||
} else {
|
||||
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
prefix = prefix + Consts.S.FORWARD_SLASH;
|
||||
} else {
|
||||
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
prefix = path.substring(0, secFS);
|
||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||
@@ -409,6 +446,7 @@ public abstract class WebUtils {
|
||||
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
exchange.getAttributes().put(clientRequestPathPrefix, prefix);
|
||||
}
|
||||
return prefix;
|
||||
|
||||
@@ -72,6 +72,24 @@ public class WebUtilsTests {
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/", clientReqPathPrefix);
|
||||
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/aservice/").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("aservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/", clientReqPathPrefix);
|
||||
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/aservice").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("aservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/", 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);
|
||||
@@ -91,6 +109,24 @@ public class WebUtilsTests {
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/", clientReqPathPrefix);
|
||||
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/aservice/").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("aservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/", clientReqPath);
|
||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||
assertEquals("/", clientReqPathPrefix);
|
||||
|
||||
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/aservice").build();
|
||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||
clientService = WebUtils.getClientService(mockExchange);
|
||||
assertEquals("aservice", clientService);
|
||||
clientReqPath = WebUtils.getClientReqPath(mockExchange);
|
||||
assertEquals("/", 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);
|
||||
|
||||
Reference in New Issue
Block a user