mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
4.0.3
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
|
||||
`http://ip:port/rest/服务id/your_path`,其中`http://ip:port/rest/`为固定部分,后面跟微服务请求路径。
|
||||
|
||||
> 可在微服务端指定一个配置:`sop.restful.prefix=xxx`。请求路径将变成:`http://ip:port/rest/xxx/your_path`
|
||||
|
||||
下面是一个微服务的接口例子
|
||||
|
||||
```java
|
||||
@@ -36,6 +34,10 @@ public class TraditionalWebappController {
|
||||
微服务之间的调用可以使用dubbo或feign,有了版本号的管理,可以做到服务的平滑升级,对用户来说都是无感知的。结合SOP-Admin提供的上下线功能,
|
||||
可实现预发布环境功能。
|
||||
|
||||
默认情况下,`http://ip:port/rest/`为固定部分,如果想要更改`rest`,可在网关配置文件指定:`sop.restful.path=/aaa`
|
||||
|
||||
请求前缀将变成:`http://ip:port/aaa/`
|
||||
|
||||
- 封装请求工具【可选】
|
||||
|
||||
封装请求,方便调用,针对vue的封装如下:
|
||||
|
@@ -44,7 +44,6 @@ public class ServerWebExchangeUtil {
|
||||
|
||||
private static final String THROWABLE_KEY = "sop.throwable";
|
||||
private static final String UNKNOWN_PATH = "/sop/unknown";
|
||||
private static final String REST_PATH = "/rest";
|
||||
|
||||
private static final FormHttpMessageConverter formHttpMessageConverter = new FormHttpMessageConverter();
|
||||
|
||||
@@ -77,10 +76,10 @@ public class ServerWebExchangeUtil {
|
||||
return ServerRequest.create(exchange, messageReaders);
|
||||
}
|
||||
|
||||
public static String getRestfulPath(String path) {
|
||||
int index = path.indexOf(REST_PATH);
|
||||
public static String getRestfulPath(String path, String prefix) {
|
||||
int index = path.indexOf(prefix);
|
||||
// 取"/rest"的后面部分
|
||||
return path.substring(index + REST_PATH.length());
|
||||
return path.substring(index + prefix.length());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -70,7 +70,7 @@ public class IndexFilter implements WebFilter {
|
||||
// 如果是restful请求,直接转发
|
||||
if (path.startsWith(EnvironmentKeys.SOP_RESTFUL_PATH.getValue())) {
|
||||
exchange.getAttributes().put(SopConstants.RESTFUL_REQUEST, true);
|
||||
String restfulPath = ServerWebExchangeUtil.getRestfulPath(path);
|
||||
String restfulPath = ServerWebExchangeUtil.getRestfulPath(path, EnvironmentKeys.SOP_RESTFUL_PATH.getValue());
|
||||
ServerWebExchange newExchange = ServerWebExchangeUtil.getForwardExchange(exchange, restfulPath);
|
||||
return chain.filter(newExchange);
|
||||
}
|
||||
|
Reference in New Issue
Block a user