diff --git a/doc/docs/files/10010_快速体验.md b/doc/docs/files/10010_快速体验.md index 1f7acca0..8029b969 100644 --- a/doc/docs/files/10010_快速体验.md +++ b/doc/docs/files/10010_快速体验.md @@ -31,3 +31,19 @@ - 运行WebsiteServerApplication.java - 访问http://localhost:8083 +## 基本配置 + +在`sop-gateway`下的application-dev.properties配置,各项配置说明如下 + +```properties +# 忽略验证,设置true,则所有接口不会进行签名校验,默认false +sop.api-config.ignore-validate=false +# 是否对结果进行合并,默认true +sop.api-config.merge-result=true +# 显示返回sign,默认true +sop.api-config.show-return-sign=true +# 是否开启限流功能,默认true +sop.api-config.open-limit=true +# 请求超时时间,默认5分钟,即允许在5分钟内重复请求,默认300 +sop.api-config.timeout-seconds=300 +``` \ No newline at end of file diff --git a/sop-common/pom.xml b/sop-common/pom.xml index 7878108f..48b4bed4 100644 --- a/sop-common/pom.xml +++ b/sop-common/pom.xml @@ -119,6 +119,12 @@ true + + org.springframework.boot + spring-boot-configuration-processor + true + + org.projectlombok diff --git a/sop-common/sop-bridge-gateway/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java b/sop-common/sop-bridge-gateway/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java index 98184616..34c61cd8 100644 --- a/sop-common/sop-bridge-gateway/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java +++ b/sop-common/sop-bridge-gateway/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java @@ -1,5 +1,6 @@ package com.gitee.sop.bridge; +import com.gitee.sop.gatewaycommon.config.BaseGatewayAutoConfiguration; import com.gitee.sop.gatewaycommon.gateway.configuration.AlipayGatewayConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration; @@ -13,5 +14,5 @@ import org.springframework.context.annotation.Import; @Configuration @Import(AlipayGatewayConfiguration.class) @AutoConfigureBefore(RibbonAutoConfiguration.class) -public class SopGatewayAutoConfiguration { +public class SopGatewayAutoConfiguration extends BaseGatewayAutoConfiguration { } diff --git a/sop-common/sop-bridge-zuul/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java b/sop-common/sop-bridge-zuul/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java index 2fb375df..2e17861c 100644 --- a/sop-common/sop-bridge-zuul/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java +++ b/sop-common/sop-bridge-zuul/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java @@ -1,5 +1,6 @@ package com.gitee.sop.bridge; +import com.gitee.sop.gatewaycommon.config.BaseGatewayAutoConfiguration; import com.gitee.sop.gatewaycommon.zuul.configuration.AlipayZuulConfiguration; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration; @@ -18,6 +19,6 @@ import org.springframework.context.annotation.Import; // 如果不加会出现basicErrorController和zuulErrorController冲突 // zuulErrorController是SOP中的,提前加载后basicErrorController就不会加载 @AutoConfigureBefore({ErrorMvcAutoConfiguration.class}) -public class SopGatewayAutoConfiguration { +public class SopGatewayAutoConfiguration extends BaseGatewayAutoConfiguration { } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java index 60d04446..acda4d79 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java @@ -18,12 +18,12 @@ import com.gitee.sop.gatewaycommon.manager.IsvRoutePermissionManager; import com.gitee.sop.gatewaycommon.manager.LimitConfigManager; import com.gitee.sop.gatewaycommon.manager.RouteConfigManager; import com.gitee.sop.gatewaycommon.manager.ServiceErrorManager; -import com.gitee.sop.gatewaycommon.param.ParamBuilder; import com.gitee.sop.gatewaycommon.param.ParameterFormatter; import com.gitee.sop.gatewaycommon.result.DataNameBuilder; import com.gitee.sop.gatewaycommon.result.DefaultDataNameBuilder; import com.gitee.sop.gatewaycommon.result.ResultAppender; -import com.gitee.sop.gatewaycommon.result.ResultExecutor; +import com.gitee.sop.gatewaycommon.result.ResultExecutorForGateway; +import com.gitee.sop.gatewaycommon.result.ResultExecutorForZuul; import com.gitee.sop.gatewaycommon.secret.CacheIsvManager; import com.gitee.sop.gatewaycommon.secret.IsvManager; import com.gitee.sop.gatewaycommon.session.ApiSessionManager; @@ -38,10 +38,8 @@ import com.gitee.sop.gatewaycommon.validate.Validator; import com.gitee.sop.gatewaycommon.zuul.controller.ZuulErrorController; import com.gitee.sop.gatewaycommon.zuul.param.ZuulParamBuilder; import com.gitee.sop.gatewaycommon.zuul.result.ZuulResultExecutor; -import com.netflix.zuul.context.RequestContext; import lombok.Data; import org.apache.commons.lang3.StringUtils; -import org.springframework.web.server.ServerWebExchange; import java.util.ArrayList; import java.util.Comparator; @@ -65,12 +63,12 @@ public class ApiConfig { /** * gateway合并结果处理 */ - private ResultExecutor gatewayResultExecutor = new GatewayResultExecutor(); + private ResultExecutorForGateway gatewayResultExecutor = new GatewayResultExecutor(); /** * zuul合并结果处理 */ - private ResultExecutor zuulResultExecutor = new ZuulResultExecutor(); + private ResultExecutorForZuul zuulResultExecutor = new ZuulResultExecutor(); /** * isv管理 @@ -90,7 +88,7 @@ public class ApiConfig { /** * 参数解析,zuul */ - private ParamBuilder zuulParamBuilder = new ZuulParamBuilder(); + private ZuulParamBuilder zuulParamBuilder = new ZuulParamBuilder(); /** * 验证 diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/config/ApiConfigProperties.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/config/ApiConfigProperties.java new file mode 100644 index 00000000..c9d5526d --- /dev/null +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/config/ApiConfigProperties.java @@ -0,0 +1,48 @@ +package com.gitee.sop.gatewaycommon.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author tanghc + */ +@Data +@ConfigurationProperties(prefix = "sop.api-config") +public class ApiConfigProperties { + + private List i18nModules = new ArrayList<>(); + + /** + * 忽略验证,设置true,则所有接口不会进行签名校验 + */ + private boolean ignoreValidate; + + /** + * 是否对结果进行合并。
+ * 默认情况下是否合并结果由微服务端决定,一旦指定该值,则由该值决定,不管微服务端如何设置。 + */ + private Boolean mergeResult; + + /** + * 请求超时时间,默认5分钟,即允许在5分钟内重复请求 + */ + private int timeoutSeconds = 300; + + /** + * 是否开启限流功能 + */ + private boolean openLimit = true; + + /** + * 显示返回sign + */ + private boolean showReturnSign = true; + + /** + * 保存错误信息容器的容量 + */ + private int storeErrorCapacity = 20; +} diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/config/BaseGatewayAutoConfiguration.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/config/BaseGatewayAutoConfiguration.java new file mode 100644 index 00000000..e11c49eb --- /dev/null +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/config/BaseGatewayAutoConfiguration.java @@ -0,0 +1,29 @@ +package com.gitee.sop.gatewaycommon.config; + +import com.alibaba.fastjson.JSON; +import com.gitee.sop.gatewaycommon.bean.ApiConfig; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; + +import javax.annotation.PostConstruct; + +/** + * @author tanghc + */ +@Slf4j +@EnableConfigurationProperties(ApiConfigProperties.class) +public class BaseGatewayAutoConfiguration { + + @Autowired + private ApiConfigProperties apiConfigProperties; + + @PostConstruct + public void after() { + log.info("网关基本配置:{}", JSON.toJSONString(apiConfigProperties)); + ApiConfig apiConfig = ApiConfig.getInstance(); + BeanUtils.copyProperties(apiConfigProperties, apiConfig); + } + +} diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/easyopen/EasyopenResultExecutor.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/easyopen/EasyopenResultExecutor.java index d0ab701c..ba322249 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/easyopen/EasyopenResultExecutor.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/easyopen/EasyopenResultExecutor.java @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.gitee.sop.gatewaycommon.message.Error; import com.gitee.sop.gatewaycommon.result.ApiResult; -import com.gitee.sop.gatewaycommon.result.ResultExecutor; +import com.gitee.sop.gatewaycommon.result.ResultExecutorForZuul; import com.gitee.sop.gatewaycommon.zuul.result.ZuulResultExecutor; import com.netflix.zuul.context.RequestContext; @@ -13,7 +13,7 @@ import java.util.Optional; /** * @author tanghc */ -public class EasyopenResultExecutor implements ResultExecutor { +public class EasyopenResultExecutor implements ResultExecutorForZuul { boolean onlyReturnData; diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/result/GatewayResultExecutor.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/result/GatewayResultExecutor.java index 9554647a..3c69cdda 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/result/GatewayResultExecutor.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/result/GatewayResultExecutor.java @@ -9,6 +9,7 @@ import com.gitee.sop.gatewaycommon.message.Error; import com.gitee.sop.gatewaycommon.message.ErrorEnum; import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.result.BaseExecutorAdapter; +import com.gitee.sop.gatewaycommon.result.ResultExecutorForGateway; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.util.CollectionUtils; @@ -22,7 +23,8 @@ import java.util.Map; * @author tanghc */ @Slf4j -public class GatewayResultExecutor extends BaseExecutorAdapter { +public class GatewayResultExecutor extends BaseExecutorAdapter + implements ResultExecutorForGateway { @Override public int getResponseStatus(ServerWebExchange exchange) { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutorForGateway.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutorForGateway.java new file mode 100644 index 00000000..050309b1 --- /dev/null +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutorForGateway.java @@ -0,0 +1,9 @@ +package com.gitee.sop.gatewaycommon.result; + +import org.springframework.web.server.ServerWebExchange; + +/** + * @author tanghc + */ +public interface ResultExecutorForGateway extends ResultExecutor { +} diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutorForZuul.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutorForZuul.java new file mode 100644 index 00000000..12cbc89b --- /dev/null +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutorForZuul.java @@ -0,0 +1,9 @@ +package com.gitee.sop.gatewaycommon.result; + +import com.netflix.zuul.context.RequestContext; + +/** + * @author tanghc + */ +public interface ResultExecutorForZuul extends ResultExecutor { +} diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java index fb428811..ad4de22d 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java @@ -8,6 +8,7 @@ import com.gitee.sop.gatewaycommon.message.Error; import com.gitee.sop.gatewaycommon.message.ErrorEnum; import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.result.BaseExecutorAdapter; +import com.gitee.sop.gatewaycommon.result.ResultExecutorForZuul; import com.gitee.sop.gatewaycommon.zuul.ZuulContext; import com.netflix.util.Pair; import com.netflix.zuul.context.RequestContext; @@ -20,7 +21,7 @@ import java.util.List; * @author tanghc */ @Slf4j -public class ZuulResultExecutor extends BaseExecutorAdapter { +public class ZuulResultExecutor extends BaseExecutorAdapter implements ResultExecutorForZuul { @Override protected boolean isMergeResult(RequestContext request) {