pull/1/MERGE
tanghc 5 years ago
parent 935bb2a454
commit 820909036b
  1. 16
      doc/docs/files/10010_快速体验.md
  2. 6
      sop-common/pom.xml
  3. 3
      sop-common/sop-bridge-gateway/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java
  4. 3
      sop-common/sop-bridge-zuul/src/main/java/com/gitee/sop/bridge/SopGatewayAutoConfiguration.java
  5. 12
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java
  6. 48
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/config/ApiConfigProperties.java
  7. 29
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/config/BaseGatewayAutoConfiguration.java
  8. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/easyopen/EasyopenResultExecutor.java
  9. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/result/GatewayResultExecutor.java
  10. 9
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutorForGateway.java
  11. 9
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutorForZuul.java
  12. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java

@ -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
```

@ -119,6 +119,12 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- provided -->
<dependency>
<groupId>org.projectlombok</groupId>

@ -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 {
}

@ -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 {
}

@ -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<ServerWebExchange, String> gatewayResultExecutor = new GatewayResultExecutor();
private ResultExecutorForGateway gatewayResultExecutor = new GatewayResultExecutor();
/**
* zuul合并结果处理
*/
private ResultExecutor<RequestContext, String> zuulResultExecutor = new ZuulResultExecutor();
private ResultExecutorForZuul zuulResultExecutor = new ZuulResultExecutor();
/**
* isv管理
@ -90,7 +88,7 @@ public class ApiConfig {
/**
* 参数解析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.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<RequestContext, String> {
public class EasyopenResultExecutor implements ResultExecutorForZuul {
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.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<ServerWebExchange, String> {
public class GatewayResultExecutor extends BaseExecutorAdapter<ServerWebExchange, String>
implements ResultExecutorForGateway {
@Override
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.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<RequestContext, String> {
public class ZuulResultExecutor extends BaseExecutorAdapter<RequestContext, String> implements ResultExecutorForZuul {
@Override
protected boolean isMergeResult(RequestContext request) {

Loading…
Cancel
Save