Merge branch 'master' into eureka

# Conflicts:
#	sop-example/sop-story/src/main/resources/application-dev.properties
#	sop-gateway/pom.xml
#	sop-website/sop-website-server/pom.xml
eureka
tanghc 4 years ago
commit 726e35116c
  1. 4
      changelog.md
  2. 2
      doc/docs/files/10020_新增接口.md
  3. 21
      doc/docs/files/10087_自定义返回结果.md
  4. 8
      doc/docs/files/10110_预发布灰度发布.md
  5. 2
      doc/pom.xml
  6. 2
      pom.xml
  7. 4
      sop-admin/pom.xml
  8. 4
      sop-admin/sop-admin-server/pom.xml
  9. 6
      sop-auth/pom.xml
  10. 2
      sop-common/pom.xml
  11. 6
      sop-common/sop-bridge-eureka/pom.xml
  12. 6
      sop-common/sop-bridge-nacos/pom.xml
  13. 9
      sop-common/sop-gateway-common/pom.xml
  14. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java
  15. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/AlipayGatewayConfiguration.java
  16. 54
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/controller/RestfulController.java
  17. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java
  18. 1
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/interceptor/RouteInterceptorContext.java
  19. 4
      sop-common/sop-service-common/pom.xml
  20. 2
      sop-example/pom.xml
  21. 4
      sop-example/sop-springmvc/pom.xml
  22. 4
      sop-example/sop-story/pom.xml
  23. 6
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1008_RestfulController.java
  24. 6
      sop-example/sop-story/src/main/resources/application-dev.properties
  25. 5
      sop-gateway/pom.xml
  26. 4
      sop-sdk/pom.xml
  27. 4
      sop-sdk/sdk-java/pom.xml
  28. 2
      sop-test/pom.xml
  29. 4
      sop-website/pom.xml
  30. 5
      sop-website/sop-website-server/pom.xml

@ -1,5 +1,9 @@
# changelog
## 4.2.5
- 修复restful负载均衡问题
## 4.2.4
- 修复sop-auth模块启动失败问题

@ -44,6 +44,8 @@ public StoryResult getStory() {
其中biz_content部分是我们想要的,在方法上申明一个对象,对应biz_content中的内容即可完成参数绑定,并且对参数进行JSR-303校验。
**注意:接口方法必须有且只有一个对象参数,如果申明多个会出现参数绑定失败**
```java
@Open("goods.add")
@RequestMapping("/goods/add")

@ -44,7 +44,7 @@ return method.replace('.', '_') + "_response";
```java
@Configuration
public class ZuulConfig extends AlipayZuulConfiguration {
public class MyConfig {
static {
...
@ -84,23 +84,18 @@ public class ZuulConfig extends AlipayZuulConfiguration {
如果想要对微服务结果做更深一步处理,步骤如下:
1. 新增一个类,继承`ZuulResultExecutor.java`,并重写`public String merge(T exchange, JSONObject responseData)`方法
方法merge参数说明如下:
exchange:RequestContext对象
responseData:微服务端返回的结果
方法返回最终结果
1. 新增一个类,继承`GatewayResultExecutor.java`,并重写`String mergeResult(T request, String serviceResult)`方法
2. 配置自定义类
```java
public class SopGatewayApplication {
@Configuration
public class MyConfig {
public static void main(String[] args) {
ApiConfig.getInstance().setZuulResultExecutor(new MyzuulResultExecutor());
SpringApplication.run(SopGatewayApplication.class, args);
static {
...
ApiConfig.getInstance().setGatewayResultExecutor(new MyGatewayResultExecutor());
...
}
}

@ -40,6 +40,14 @@ pre.domain=openpre.domain.com
## 使用灰度发布
- 灰度接口定义
接口名相同,版本号不同。比如接口`user.get`,version:1.0
新建一个接口`user.get`,version:2.0
那么这个2.0接口就是灰度接口
灰度发布可允许指定的用户访问灰度服务器,其它用户还是走正常流程。
登录SOP-Admin,前往`服务列表`。

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>doc</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<properties>
<!-- Generic properties -->

@ -12,7 +12,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<packaging>pom</packaging>
<description>一个开放平台解决方案项目,基于Spring Cloud实现,目标是能够让用户快速得搭建起自己的开放平台</description>

@ -6,13 +6,13 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-admin</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>

@ -5,13 +5,13 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-admin-server</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>

@ -5,7 +5,7 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
@ -25,7 +25,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
</dependency>
<!-- sop相关配置 end-->
@ -37,7 +37,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sdk-java</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
</dependency>
<!-- http请求 -->
<dependency>

@ -6,7 +6,7 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>

@ -5,12 +5,12 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<artifactId>sop-bridge-eureka</artifactId>
@ -18,7 +18,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
</dependency>
<dependency>

@ -5,12 +5,12 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<artifactId>sop-bridge-nacos</artifactId>
@ -18,7 +18,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
</dependency>
<dependency>

@ -5,13 +5,13 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-gateway-common</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
@ -54,6 +54,11 @@
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gateway-webflux</artifactId>
</dependency>
<!-- optional -->
<dependency>
<groupId>com.alibaba.cloud</groupId>

@ -28,12 +28,12 @@ import com.gitee.sop.gatewaycommon.result.ResultExecutorForGateway;
import com.gitee.sop.gatewaycommon.secret.CacheIsvManager;
import com.gitee.sop.gatewaycommon.secret.IsvManager;
import com.gitee.sop.gatewaycommon.validate.ApiEncrypter;
import com.gitee.sop.gatewaycommon.validate.ApiSigner;
import com.gitee.sop.gatewaycommon.validate.ApiValidator;
import com.gitee.sop.gatewaycommon.validate.Encrypter;
import com.gitee.sop.gatewaycommon.validate.Signer;
import com.gitee.sop.gatewaycommon.validate.TokenValidator;
import com.gitee.sop.gatewaycommon.validate.Validator;
import com.gitee.sop.gatewaycommon.validate.alipay.AlipaySigner;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
@ -74,7 +74,7 @@ public class ApiConfig {
/**
* 签名工具
*/
private Signer signer = new ApiSigner();
private Signer signer = new AlipaySigner();
/**
* 验证

@ -1,8 +1,5 @@
package com.gitee.sop.gatewaycommon.gateway.configuration;
import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.validate.alipay.AlipaySigner;
/**
* 具备支付宝开放平台能力配置 https://docs.open.alipay.com/api
*
@ -10,7 +7,4 @@ import com.gitee.sop.gatewaycommon.validate.alipay.AlipaySigner;
*/
public class AlipayGatewayConfiguration extends BaseGatewayConfiguration {
static {
ApiContext.getApiConfig().setSigner(new AlipaySigner());
}
}

@ -0,0 +1,54 @@
package com.gitee.sop.gatewaycommon.gateway.controller;
import com.gitee.sop.gatewaycommon.bean.SpringContext;
import com.gitee.sop.gatewaycommon.gateway.loadbalancer.SopLoadBalancerClient;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.gateway.webflux.ProxyExchange;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/**
* 处理restful请求
* @author tanghc
*/
@Controller
public class RestfulController {
private static final int PREFIX_LEN = "/rest/".length();
@RequestMapping("/rest/**")
public Mono<ResponseEntity<byte[]>> proxy(ProxyExchange<byte[]> proxy, ServerWebExchange exchange) {
String path = proxy.path();
String serviceId = getServiceId(path);
String targetPath = getTargetPath(serviceId, path);
String rawQuery = exchange.getRequest().getURI().getRawQuery();
if (StringUtils.hasLength(rawQuery)) {
targetPath = targetPath + "?" + rawQuery;
}
// 负载均衡
ServiceInstance serviceInstance = SpringContext.getBean(SopLoadBalancerClient.class).choose(serviceId, exchange);
String uri = "http://" + serviceInstance.getHost() + ":" + serviceInstance.getPort() + targetPath;
return proxy.uri(uri).forward();
}
/**
* 从path中解析出serviceId
* @param path 格式/rest/<serviceId><real_path>
* @return 返回serviceId
*/
private String getServiceId(String path) {
path = path.substring(PREFIX_LEN);
int index = path.indexOf('/');
path = path.substring(0, index);
return path;
}
private String getTargetPath(String serviceId, String path) {
int len = PREFIX_LEN + serviceId.length();
return path.substring(len);
}
}

@ -72,11 +72,9 @@ public class IndexFilter implements WebFilter {
return chain.filter(exchange);
}
// 如果是restful请求,直接转发
// see:com.gitee.sop.gatewaycommon.gateway.controller.RestfulController
if (enableRestful && path.startsWith(EnvironmentKeys.SOP_RESTFUL_PATH.getValue())) {
exchange.getAttributes().put(SopConstants.RESTFUL_REQUEST, true);
String restfulPath = ServerWebExchangeUtil.getRestfulPath(path, EnvironmentKeys.SOP_RESTFUL_PATH.getValue());
ServerWebExchange newExchange = ServerWebExchangeUtil.getForwardExchange(exchange, restfulPath);
return chain.filter(newExchange);
return chain.filter(exchange);
}
if (Objects.equals(path, indexPath)) {
if (request.getMethod() == HttpMethod.POST) {

@ -1,6 +1,5 @@
package com.gitee.sop.gatewaycommon.interceptor;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.param.ApiParam;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.http.HttpStatus;

@ -6,13 +6,13 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-service-common</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>

@ -5,7 +5,7 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>

@ -5,7 +5,7 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
@ -26,7 +26,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
</dependency>
<!-- nacos -->
<dependency>

@ -4,7 +4,7 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
@ -19,7 +19,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
</dependency>
<dependency>

@ -4,6 +4,8 @@ import com.gitee.sop.servercommon.util.UploadUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -25,6 +27,8 @@ import java.util.Collection;
@Api(tags = "食物接口")
public class Example1008_RestfulController {
@Autowired
private Environment environment;
// http://localhost:8081/rest/story-service/food/getFoodById?id=1 网关入口
// http://localhost:2222/food/getFoodById/?id=12 本地入口
@ -33,7 +37,7 @@ public class Example1008_RestfulController {
public Food getFoodById(Integer id) {
Food food = new Food();
food.setId(id);
food.setName("香蕉");
food.setName("香蕉, " + environment.getProperty("server.port"));
food.setPrice(new BigDecimal(20.00));
return food;
}

@ -1,6 +1,10 @@
server.port=2222
spring.application.name=story-service
register.url=http://localhost:1111/eureka/
# 注册中心
# \u6CE8\u518C\u4E2D\u5FC3
eureka.client.serviceUrl.defaultZone=${register.url}
# \u4E0A\u4F20\u6587\u4EF6\u6700\u5927\u503C
spring.servlet.multipart.max-file-size=20MB
spring.servlet.multipart.max-request-size=20MB

@ -4,7 +4,7 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
@ -22,9 +22,8 @@
-->
<dependency>
<groupId>com.gitee.sop</groupId>
<!-- <artifactId>sop-bridge-eureka</artifactId>-->
<artifactId>sop-bridge-eureka</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
</dependency>
<dependency>

@ -6,13 +6,13 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-sdk</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>

@ -4,13 +4,13 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sdk-java</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<properties>
<!-- Generic properties -->

@ -5,7 +5,7 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>

@ -6,13 +6,13 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-website</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>

@ -5,7 +5,7 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-website</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
@ -23,9 +23,8 @@
-->
<dependency>
<groupId>com.gitee.sop</groupId>
<!-- <artifactId>sop-bridge-nacos</artifactId>-->
<artifactId>sop-bridge-eureka</artifactId>
<version>4.2.4-SNAPSHOT</version>
<version>4.2.5-SNAPSHOT</version>
</dependency>
<dependency>

Loading…
Cancel
Save