diff --git a/changelog.md b/changelog.md index 6a3efb0d..bb8c1a13 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # changelog +## 2.4.1 + +- 优化restful接口调用(如果正在使用此功能,必看)[doc](https://durcframework.gitee.io/sop/#/files/10100_%E6%8F%90%E4%BE%9Brestful%E6%8E%A5%E5%8F%A3?t=1571107529449) + ## 2.4.0 - 支持自定义限流持续时间(每n秒允许m个请求,需要执行`sop-2.4.0.sql`升级脚本) diff --git a/doc/docs/files/10100_提供restful接口.md b/doc/docs/files/10100_提供restful接口.md index 46561ec4..fbf42923 100644 --- a/doc/docs/files/10100_提供restful接口.md +++ b/doc/docs/files/10100_提供restful接口.md @@ -20,7 +20,8 @@ sop.restful.enable=true **2.4.1之后:** `http://ip:port/rest/服务id/your_path`,其中`http://ip:port/rest/`为固定部分,后面跟微服务请求路径。 **注意,`2.4.1`开始多了一个服务id作为区分,这样做是为了避免各微服务之间url冲突,假如两个微服务都有一个叫`/getItems`这样的接口 -那么调用`http://ip:port/rest/getItems`接口网关无法做出正确的路由,虽然可以在代码上进行规范,为了防止万一,还是强行加上了,避免采坑** +那么调用`http://ip:port/rest/getItems`接口网关无法做出正确的路由,虽然可以在代码上进行规范,为了防止万一,还是强行加上了,避免采坑 +。可以指定`sop.restful.compatibility=true`强制使用老的调用方式** > 可在微服务端指定一个配置:`sop.restful.prefix=xxx`。请求路径将变成:`http://ip:port/rest/xxx/your_path` diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java index e564f569..c4844b4a 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ApiMetaBuilder.java @@ -102,7 +102,8 @@ public class ApiMetaBuilder { if (StringUtils.isEmpty(prefix)) { prefix = EnvironmentKeys.SPRING_APPLICATION_NAME.getValue(); } - if (StringUtils.hasText(prefix)) { + String compatibilityValue = EnvironmentKeys.SOP_RESTFUL_COMPATIBILITY.getValue(); + if (!"true".equals(compatibilityValue) && StringUtils.hasText(prefix)) { name = "/" + prefix + "/" + StringUtils.trimLeadingCharacter(path, '/'); } ServiceApiInfo.ApiMeta apiMeta = new ServiceApiInfo.ApiMeta(name, path, ""); diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/EnvironmentKeys.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/EnvironmentKeys.java index 3ec6bea4..2254aa64 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/EnvironmentKeys.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/EnvironmentKeys.java @@ -12,7 +12,12 @@ public enum EnvironmentKeys { /** * sop.restful.prefix=xxx,指定web开发模式前缀,不指定默认为service-id */ - SOP_RESTFUL_PREFIX("sop.restful.prefix"); + SOP_RESTFUL_PREFIX("sop.restful.prefix"), + + /** + * sop.restful.compatibility=true,兼容老的restful调用方式(2.4.1之前) + */ + SOP_RESTFUL_COMPATIBILITY("sop.restful.compatibility", "false"); private String key; private String defaultValue;