Handler client request with / path
This commit is contained in:
@@ -224,23 +224,36 @@ public abstract class WebUtils {
|
|||||||
if (svc == null) {
|
if (svc == null) {
|
||||||
String p = exchange.getRequest().getPath().value();
|
String p = exchange.getRequest().getPath().value();
|
||||||
int secFS = p.indexOf(Consts.S.FORWARD_SLASH, 1);
|
int secFS = p.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||||
String prefix = p.substring(0, secFS);
|
if (secFS == -1) {
|
||||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
svc = p.substring(1);
|
||||||
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
|
||||||
svc = p.substring(secFS + 1, trdFS);
|
|
||||||
} else {
|
|
||||||
svc = p.substring(1, 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) {
|
|
||||||
trdFS = p.length();
|
|
||||||
}
|
|
||||||
svc = p.substring(secFS + 1, trdFS);
|
|
||||||
} else {
|
} else {
|
||||||
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
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)) {
|
||||||
|
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
||||||
|
svc = p.substring(secFS + 1, trdFS);
|
||||||
|
} else {
|
||||||
|
svc = p.substring(1, 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) {
|
||||||
|
trdFS = p.length();
|
||||||
|
}
|
||||||
|
svc = p.substring(secFS + 1, trdFS);
|
||||||
|
} else {
|
||||||
|
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exchange.getAttributes().put(clientService, svc);
|
exchange.getAttributes().put(clientService, svc);
|
||||||
@@ -356,25 +369,37 @@ public abstract class WebUtils {
|
|||||||
// p = exchange.getRequest().getPath().value();
|
// p = exchange.getRequest().getPath().value();
|
||||||
p = exchange.getRequest().getURI().getPath();
|
p = exchange.getRequest().getURI().getPath();
|
||||||
int secFS = p.indexOf(Consts.S.FORWARD_SLASH, 1);
|
int secFS = p.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||||
String prefix = p.substring(0, secFS);
|
if (secFS == -1) {
|
||||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
p = Consts.S.FORWARD_SLASH_STR;
|
||||||
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
} else {
|
||||||
p = p.substring(trdFS);
|
String prefix = p.substring(1);
|
||||||
} else {
|
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||||
p = p.substring(secFS);
|
throw Utils.runtimeExceptionWithoutStack("no service and request path");
|
||||||
}
|
|
||||||
} 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) {
|
|
||||||
p = Consts.S.FORWARD_SLASH_STR;
|
|
||||||
} else {
|
} 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)) {
|
||||||
|
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
||||||
p = p.substring(trdFS);
|
p = p.substring(trdFS);
|
||||||
|
} else {
|
||||||
|
p = p.substring(secFS);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
if (gatewayPrefix.equals(prefix) || SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
||||||
|
int trdFS = p.indexOf(Consts.S.FORWARD_SLASH, secFS + 1);
|
||||||
|
if (trdFS == -1) {
|
||||||
|
p = Consts.S.FORWARD_SLASH_STR;
|
||||||
|
} else {
|
||||||
|
p = p.substring(trdFS);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exchange.getAttributes().put(clientRequestPath, p);
|
exchange.getAttributes().put(clientRequestPath, p);
|
||||||
@@ -394,19 +419,32 @@ public abstract class WebUtils {
|
|||||||
String prefix = exchange.getAttribute(clientRequestPathPrefix);
|
String prefix = exchange.getAttribute(clientRequestPathPrefix);
|
||||||
if (prefix == null) {
|
if (prefix == null) {
|
||||||
String path = exchange.getRequest().getPath().value();
|
String path = exchange.getRequest().getPath().value();
|
||||||
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||||
prefix = path.substring(0, secFS);
|
if (secFS == -1) {
|
||||||
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
prefix = path.substring(1);
|
||||||
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX.equals(prefix)) {
|
if (StringUtils.isBlank(gatewayPrefix) || Consts.S.FORWARD_SLASH_STR.equals(gatewayPrefix)) {
|
||||||
prefix = prefix + Consts.S.FORWARD_SLASH;
|
prefix = Consts.S.FORWARD_SLASH_STR;
|
||||||
} else {
|
|
||||||
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 {
|
} else {
|
||||||
throw Utils.runtimeExceptionWithoutStack("wrong prefix " + prefix);
|
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)) {
|
||||||
|
prefix = prefix + Consts.S.FORWARD_SLASH;
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exchange.getAttributes().put(clientRequestPathPrefix, prefix);
|
exchange.getAttributes().put(clientRequestPathPrefix, prefix);
|
||||||
|
|||||||
@@ -71,6 +71,24 @@ public class WebUtilsTests {
|
|||||||
assertEquals("/ybiz1", clientReqPath);
|
assertEquals("/ybiz1", clientReqPath);
|
||||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||||
assertEquals("/", clientReqPathPrefix);
|
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();
|
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/_proxytest/xservice/ybiz?a=b").build();
|
||||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||||
@@ -90,6 +108,24 @@ public class WebUtilsTests {
|
|||||||
assertEquals("/ybiz1", clientReqPath);
|
assertEquals("/ybiz1", clientReqPath);
|
||||||
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
clientReqPathPrefix = WebUtils.getClientReqPathPrefix(mockExchange);
|
||||||
assertEquals("/", clientReqPathPrefix);
|
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();
|
mockRequest = MockServerHttpRequest.get("http://127.0.0.1:8600/_proxytest/xservice/ybiz?a=b").build();
|
||||||
mockExchange = MockServerWebExchange.from(mockRequest);
|
mockExchange = MockServerWebExchange.from(mockRequest);
|
||||||
|
|||||||
Reference in New Issue
Block a user