mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
3.0.0
This commit is contained in:
@@ -31,3 +31,19 @@
|
|||||||
- 运行WebsiteServerApplication.java
|
- 运行WebsiteServerApplication.java
|
||||||
- 访问http://localhost:8083
|
- 访问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
|
||||||
|
```
|
@@ -119,6 +119,12 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- provided -->
|
<!-- provided -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.gitee.sop.bridge;
|
package com.gitee.sop.bridge;
|
||||||
|
|
||||||
|
import com.gitee.sop.gatewaycommon.config.BaseGatewayAutoConfiguration;
|
||||||
import com.gitee.sop.gatewaycommon.gateway.configuration.AlipayGatewayConfiguration;
|
import com.gitee.sop.gatewaycommon.gateway.configuration.AlipayGatewayConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
|
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
|
||||||
@@ -13,5 +14,5 @@ import org.springframework.context.annotation.Import;
|
|||||||
@Configuration
|
@Configuration
|
||||||
@Import(AlipayGatewayConfiguration.class)
|
@Import(AlipayGatewayConfiguration.class)
|
||||||
@AutoConfigureBefore(RibbonAutoConfiguration.class)
|
@AutoConfigureBefore(RibbonAutoConfiguration.class)
|
||||||
public class SopGatewayAutoConfiguration {
|
public class SopGatewayAutoConfiguration extends BaseGatewayAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package com.gitee.sop.bridge;
|
package com.gitee.sop.bridge;
|
||||||
|
|
||||||
|
import com.gitee.sop.gatewaycommon.config.BaseGatewayAutoConfiguration;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.configuration.AlipayZuulConfiguration;
|
import com.gitee.sop.gatewaycommon.zuul.configuration.AlipayZuulConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
|
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
|
||||||
@@ -18,6 +19,6 @@ import org.springframework.context.annotation.Import;
|
|||||||
// 如果不加会出现basicErrorController和zuulErrorController冲突
|
// 如果不加会出现basicErrorController和zuulErrorController冲突
|
||||||
// zuulErrorController是SOP中的,提前加载后basicErrorController就不会加载
|
// zuulErrorController是SOP中的,提前加载后basicErrorController就不会加载
|
||||||
@AutoConfigureBefore({ErrorMvcAutoConfiguration.class})
|
@AutoConfigureBefore({ErrorMvcAutoConfiguration.class})
|
||||||
public class SopGatewayAutoConfiguration {
|
public class SopGatewayAutoConfiguration extends BaseGatewayAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,12 +18,12 @@ import com.gitee.sop.gatewaycommon.manager.IsvRoutePermissionManager;
|
|||||||
import com.gitee.sop.gatewaycommon.manager.LimitConfigManager;
|
import com.gitee.sop.gatewaycommon.manager.LimitConfigManager;
|
||||||
import com.gitee.sop.gatewaycommon.manager.RouteConfigManager;
|
import com.gitee.sop.gatewaycommon.manager.RouteConfigManager;
|
||||||
import com.gitee.sop.gatewaycommon.manager.ServiceErrorManager;
|
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.param.ParameterFormatter;
|
||||||
import com.gitee.sop.gatewaycommon.result.DataNameBuilder;
|
import com.gitee.sop.gatewaycommon.result.DataNameBuilder;
|
||||||
import com.gitee.sop.gatewaycommon.result.DefaultDataNameBuilder;
|
import com.gitee.sop.gatewaycommon.result.DefaultDataNameBuilder;
|
||||||
import com.gitee.sop.gatewaycommon.result.ResultAppender;
|
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.CacheIsvManager;
|
||||||
import com.gitee.sop.gatewaycommon.secret.IsvManager;
|
import com.gitee.sop.gatewaycommon.secret.IsvManager;
|
||||||
import com.gitee.sop.gatewaycommon.session.ApiSessionManager;
|
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.controller.ZuulErrorController;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.param.ZuulParamBuilder;
|
import com.gitee.sop.gatewaycommon.zuul.param.ZuulParamBuilder;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.result.ZuulResultExecutor;
|
import com.gitee.sop.gatewaycommon.zuul.result.ZuulResultExecutor;
|
||||||
import com.netflix.zuul.context.RequestContext;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -65,12 +63,12 @@ public class ApiConfig {
|
|||||||
/**
|
/**
|
||||||
* gateway合并结果处理
|
* gateway合并结果处理
|
||||||
*/
|
*/
|
||||||
private ResultExecutor<ServerWebExchange, String> gatewayResultExecutor = new GatewayResultExecutor();
|
private ResultExecutorForGateway gatewayResultExecutor = new GatewayResultExecutor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* zuul合并结果处理
|
* zuul合并结果处理
|
||||||
*/
|
*/
|
||||||
private ResultExecutor<RequestContext, String> zuulResultExecutor = new ZuulResultExecutor();
|
private ResultExecutorForZuul zuulResultExecutor = new ZuulResultExecutor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* isv管理
|
* isv管理
|
||||||
@@ -90,7 +88,7 @@ public class ApiConfig {
|
|||||||
/**
|
/**
|
||||||
* 参数解析,zuul
|
* 参数解析,zuul
|
||||||
*/
|
*/
|
||||||
private ParamBuilder<RequestContext> zuulParamBuilder = new ZuulParamBuilder();
|
private ZuulParamBuilder zuulParamBuilder = new ZuulParamBuilder();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证
|
* 验证
|
||||||
|
@@ -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<String> i18nModules = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 忽略验证,设置true,则所有接口不会进行签名校验
|
||||||
|
*/
|
||||||
|
private boolean ignoreValidate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否对结果进行合并。<br>
|
||||||
|
* 默认情况下是否合并结果由微服务端决定,一旦指定该值,则由该值决定,不管微服务端如何设置。
|
||||||
|
*/
|
||||||
|
private Boolean mergeResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求超时时间,默认5分钟,即允许在5分钟内重复请求
|
||||||
|
*/
|
||||||
|
private int timeoutSeconds = 300;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启限流功能
|
||||||
|
*/
|
||||||
|
private boolean openLimit = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示返回sign
|
||||||
|
*/
|
||||||
|
private boolean showReturnSign = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存错误信息容器的容量
|
||||||
|
*/
|
||||||
|
private int storeErrorCapacity = 20;
|
||||||
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.gitee.sop.gatewaycommon.message.Error;
|
import com.gitee.sop.gatewaycommon.message.Error;
|
||||||
import com.gitee.sop.gatewaycommon.result.ApiResult;
|
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.gitee.sop.gatewaycommon.zuul.result.ZuulResultExecutor;
|
||||||
import com.netflix.zuul.context.RequestContext;
|
import com.netflix.zuul.context.RequestContext;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ import java.util.Optional;
|
|||||||
/**
|
/**
|
||||||
* @author tanghc
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
public class EasyopenResultExecutor implements ResultExecutor<RequestContext, String> {
|
public class EasyopenResultExecutor implements ResultExecutorForZuul {
|
||||||
|
|
||||||
boolean onlyReturnData;
|
boolean onlyReturnData;
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@ import com.gitee.sop.gatewaycommon.message.Error;
|
|||||||
import com.gitee.sop.gatewaycommon.message.ErrorEnum;
|
import com.gitee.sop.gatewaycommon.message.ErrorEnum;
|
||||||
import com.gitee.sop.gatewaycommon.param.ApiParam;
|
import com.gitee.sop.gatewaycommon.param.ApiParam;
|
||||||
import com.gitee.sop.gatewaycommon.result.BaseExecutorAdapter;
|
import com.gitee.sop.gatewaycommon.result.BaseExecutorAdapter;
|
||||||
|
import com.gitee.sop.gatewaycommon.result.ResultExecutorForGateway;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@@ -22,7 +23,8 @@ import java.util.Map;
|
|||||||
* @author tanghc
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class GatewayResultExecutor extends BaseExecutorAdapter<ServerWebExchange, String> {
|
public class GatewayResultExecutor extends BaseExecutorAdapter<ServerWebExchange, String>
|
||||||
|
implements ResultExecutorForGateway {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getResponseStatus(ServerWebExchange exchange) {
|
public int getResponseStatus(ServerWebExchange exchange) {
|
||||||
|
@@ -0,0 +1,9 @@
|
|||||||
|
package com.gitee.sop.gatewaycommon.result;
|
||||||
|
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tanghc
|
||||||
|
*/
|
||||||
|
public interface ResultExecutorForGateway extends ResultExecutor<ServerWebExchange, String> {
|
||||||
|
}
|
@@ -0,0 +1,9 @@
|
|||||||
|
package com.gitee.sop.gatewaycommon.result;
|
||||||
|
|
||||||
|
import com.netflix.zuul.context.RequestContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tanghc
|
||||||
|
*/
|
||||||
|
public interface ResultExecutorForZuul extends ResultExecutor<RequestContext, String> {
|
||||||
|
}
|
@@ -8,6 +8,7 @@ import com.gitee.sop.gatewaycommon.message.Error;
|
|||||||
import com.gitee.sop.gatewaycommon.message.ErrorEnum;
|
import com.gitee.sop.gatewaycommon.message.ErrorEnum;
|
||||||
import com.gitee.sop.gatewaycommon.param.ApiParam;
|
import com.gitee.sop.gatewaycommon.param.ApiParam;
|
||||||
import com.gitee.sop.gatewaycommon.result.BaseExecutorAdapter;
|
import com.gitee.sop.gatewaycommon.result.BaseExecutorAdapter;
|
||||||
|
import com.gitee.sop.gatewaycommon.result.ResultExecutorForZuul;
|
||||||
import com.gitee.sop.gatewaycommon.zuul.ZuulContext;
|
import com.gitee.sop.gatewaycommon.zuul.ZuulContext;
|
||||||
import com.netflix.util.Pair;
|
import com.netflix.util.Pair;
|
||||||
import com.netflix.zuul.context.RequestContext;
|
import com.netflix.zuul.context.RequestContext;
|
||||||
@@ -20,7 +21,7 @@ import java.util.List;
|
|||||||
* @author tanghc
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ZuulResultExecutor extends BaseExecutorAdapter<RequestContext, String> {
|
public class ZuulResultExecutor extends BaseExecutorAdapter<RequestContext, String> implements ResultExecutorForZuul {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isMergeResult(RequestContext request) {
|
protected boolean isMergeResult(RequestContext request) {
|
||||||
|
Reference in New Issue
Block a user