Merge branch 'master' into eureka

# Conflicts:
#	sop-auth/pom.xml
#	sop-example/sop-book/sop-book-web/pom.xml
#	sop-example/sop-book/sop-book-web/src/main/resources/application-dev.properties
#	sop-example/sop-easyopen/pom.xml
#	sop-example/sop-easyopen/src/main/resources/application-dev.properties
#	sop-example/sop-story/sop-story-web/pom.xml
#	sop-example/sop-story/src/main/resources/application-dev.properties
#	sop-gateway/pom.xml
#	sop-website/pom.xml
eureka
tanghc 5 years ago
commit 1245f830dd
  1. 9
      changelog.md
  2. 74
      doc/docs/_sidebar.md
  3. 2
      doc/docs/files/10010_快速体验.md
  4. 2
      doc/docs/files/10087_自定义返回结果.md
  5. 7
      doc/docs/files/10092_接口限流.md
  6. 228
      pom.xml
  7. 9
      sop-admin/pom.xml
  8. 38
      sop-admin/sop-admin-server/pom.xml
  9. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/SopAdminServerApplication.java
  10. 4
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/ConfigServiceRoute.java
  11. 27
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/ServerService.java
  12. 2
      sop-admin/sop-admin-server/src/main/resources/public/index.html
  13. 1
      sop-admin/sop-admin-server/src/main/resources/public/static/js/chunk-9f479afe.4609bf8b.js
  14. 1
      sop-admin/sop-admin-server/src/main/resources/public/static/js/chunk-9f479afe.51cf2439.js
  15. 3
      sop-admin/sop-admin-vue/src/views/service/serviceList.vue
  16. 55
      sop-auth/pom.xml
  17. 2
      sop-auth/src/main/java/com/gitee/sop/sopauth/auth/impl/OAuth2ManagerRedis.java
  18. 176
      sop-common/pom.xml
  19. 10
      sop-common/sop-bridge-gateway/pom.xml
  20. 11
      sop-common/sop-bridge-zuul/pom.xml
  21. 54
      sop-common/sop-gateway-common/pom.xml
  22. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteDefinition.java
  23. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java
  24. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java
  25. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/loadbalancer/NacosServerIntrospector.java
  26. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java
  27. 119
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/NacosEventProcessor.java
  28. 183
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java
  29. 1
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java
  30. 9
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/EurekaRegistryListener.java
  31. 103
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/NacosRegistryListener.java
  32. 23
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/RegistryEvent.java
  33. 11
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceHolder.java
  34. 40
      sop-common/sop-service-common/pom.xml
  35. 30
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/RedisApiMetaManager.java
  36. 11
      sop-example/pom.xml
  37. 4
      sop-example/readme.md
  38. 15
      sop-example/sop-book/pom.xml
  39. 25
      sop-example/sop-book/sop-book-api/.gitignore
  40. 46
      sop-example/sop-book/sop-book-api/pom.xml
  41. 12
      sop-example/sop-book/sop-book-api/src/main/java/com/gitee/book/api/domain/Book.java
  42. 14
      sop-example/sop-book/sop-book-api/src/main/java/com/gitee/book/api/service/BookService.java
  43. 25
      sop-example/sop-book/sop-book-web/.gitignore
  44. 153
      sop-example/sop-book/sop-book-web/pom.xml
  45. 20
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/SopBookApplication.java
  46. 33
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/config/OpenServiceConfig.java
  47. 14
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/consumer/StoryServiceConsumer.java
  48. 55
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/AlipayBookController.java
  49. 72
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/ApiResult.java
  50. 73
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/BookController.java
  51. 40
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/controller/DubboConsumerController.java
  52. 16
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/param/BookParam.java
  53. 16
      sop-example/sop-book/sop-book-web/src/main/java/com/gitee/sop/bookweb/vo/BookVO.java
  54. 19
      sop-example/sop-book/sop-book-web/src/main/resources/application-dev.properties
  55. 17
      sop-example/sop-book/sop-book-web/src/test/java/com/gitee/sop/bookweb/SopBookApplicationTests.java
  56. 25
      sop-example/sop-easyopen/.gitignore
  57. 132
      sop-example/sop-easyopen/pom.xml
  58. 31
      sop-example/sop-easyopen/readme.md
  59. 25
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/IndexController.java
  60. 14
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/SopEasyopenApplication.java
  61. 31
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/Goods2Api.java
  62. 31
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/GoodsApi.java
  63. 23
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/param/GoodsParam.java
  64. 46
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/api/result/Goods.java
  65. 37
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/CorsConfig.java
  66. 28
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/config/SopConfig.java
  67. 23
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/interceptor/LogInterceptor.java
  68. 16
      sop-example/sop-easyopen/src/main/java/com/gitee/easyopen/server/message/CommonErrors.java
  69. 7
      sop-example/sop-easyopen/src/main/resources/application-dev.properties
  70. 1
      sop-example/sop-easyopen/src/main/resources/application.properties
  71. 2
      sop-example/sop-easyopen/src/main/resources/i18n/isv/error_zh_CN.properties
  72. 16
      sop-example/sop-easyopen/src/test/java/com/gitee/sop/adminserver/SopEasyopenApplicationApplicationTests.java
  73. 17
      sop-example/sop-springmvc/pom.xml
  74. 98
      sop-example/sop-story/pom.xml
  75. 25
      sop-example/sop-story/sop-story-api/.gitignore
  76. 46
      sop-example/sop-story/sop-story-api/pom.xml
  77. 18
      sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/domain/Story.java
  78. 14
      sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/param/DemoParam.java
  79. 15
      sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/result/DemoResult.java
  80. 17
      sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/DemoService.java
  81. 15
      sop-example/sop-story/sop-story-api/src/main/java/com/gitee/sop/story/api/service/StoryService.java
  82. 25
      sop-example/sop-story/sop-story-web/.gitignore
  83. 146
      sop-example/sop-story/sop-story-web/pom.xml
  84. 23
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryController.java
  85. 21
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/StoryDemoController.java
  86. 32
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/service/DefaultDemoService.java
  87. 1
      sop-example/sop-story/sop-story-web/src/main/resources/application.properties
  88. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/SopStoryApplication.java
  89. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/config/OpenServiceConfig.java
  90. 12
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java
  91. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/AlipayController2.java
  92. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/DownloadController.java
  93. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java
  94. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/JSR303DemoController.java
  95. 1
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/PermissionDemoController.java
  96. 24
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java
  97. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/ThrowExceptionDemoController.java
  98. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/TokenController.java
  99. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/TraditionalWebappController.java
  100. 0
      sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/param/CategoryParam.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -1,5 +1,14 @@
# changelog # changelog
## 3.2.0
- 使用alibaba cloud
Hoxton.SR3(Spring Cloud Version), 2.2.1.RELEASE(Spring Cloud Alibaba Version), 2.2.5.RELEASE(Spring Boot Version)
- 优化pom文件
- 优化灰度发布
## 3.1.5 ## 3.1.5
修复文件上传大小不一致问题 修复文件上传大小不一致问题

@ -1,39 +1,39 @@
* [首页](/?t=1589794156310) * [首页](/?t=1591927043815)
* 开发文档 * 开发文档
* [快速体验](files/10010_快速体验.md?t=1589794156312) * [快速体验](files/10010_快速体验.md?t=1591927043817)
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1589794156333) * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1591927043835)
* [新增接口](files/10020_新增接口.md?t=1589794156333) * [新增接口](files/10020_新增接口.md?t=1591927043836)
* [开发流程](files/10021_开发流程.md?t=1589794156333) * [开发流程](files/10021_开发流程.md?t=1591927043836)
* [业务参数校验](files/10030_业务参数校验.md?t=1589794156333) * [业务参数校验](files/10030_业务参数校验.md?t=1591927043836)
* [错误处理](files/10040_错误处理.md?t=1589794156333) * [错误处理](files/10040_错误处理.md?t=1591927043836)
* [编写文档](files/10041_编写文档.md?t=1589794156333) * [编写文档](files/10041_编写文档.md?t=1591927043836)
* [接口交互详解](files/10050_接口交互详解.md?t=1589794156333) * [接口交互详解](files/10050_接口交互详解.md?t=1591927043836)
* [easyopen支持](files/10070_easyopen支持.md?t=1589794156333) * [easyopen支持](files/10070_easyopen支持.md?t=1591927043836)
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1589794156334) * [使用签名校验工具](files/10080_使用签名校验工具.md?t=1591927043836)
* [ISV管理](files/10085_ISV管理.md?t=1589794156334) * [ISV管理](files/10085_ISV管理.md?t=1591927043836)
* [自定义返回结果](files/10087_自定义返回结果.md?t=1589794156334) * [自定义返回结果](files/10087_自定义返回结果.md?t=1591927043837)
* [自定义过滤器](files/10088_自定义过滤器.md?t=1589794156334) * [自定义过滤器](files/10088_自定义过滤器.md?t=1591927043837)
* [自定义校验token](files/10089_自定义校验token.md?t=1589794156334) * [自定义校验token](files/10089_自定义校验token.md?t=1591927043837)
* [网关拦截器](files/10090_网关拦截器.md?t=1589794156334) * [网关拦截器](files/10090_网关拦截器.md?t=1591927043837)
* [路由授权](files/10090_路由授权.md?t=1589794156335) * [路由授权](files/10090_路由授权.md?t=1591927043837)
* [接口限流](files/10092_接口限流.md?t=1589794156335) * [接口限流](files/10092_接口限流.md?t=1591927043837)
* [路由监控](files/10093_路由监控.md?t=1589794156335) * [路由监控](files/10093_路由监控.md?t=1591927043837)
* [SDK开发](files/10095_SDK开发.md?t=1589794156335) * [SDK开发](files/10095_SDK开发.md?t=1591927043837)
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1589794156335) * [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1591927043837)
* [应用授权](files/10097_应用授权.md?t=1589794156335) * [应用授权](files/10097_应用授权.md?t=1591927043837)
* [提供restful接口](files/10100_提供restful接口.md?t=1589794156335) * [提供restful接口](files/10100_提供restful接口.md?t=1591927043838)
* [文件上传](files/10104_文件上传.md?t=1589794156336) * [文件上传](files/10104_文件上传.md?t=1591927043838)
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1589794156336) * [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1591927043838)
* [预发布灰度发布](files/10110_预发布灰度发布.md?t=1589794156336) * [预发布灰度发布](files/10110_预发布灰度发布.md?t=1591927043838)
* [动态修改请求参数](files/10111_动态修改请求参数.md?t=1589794156336) * [动态修改请求参数](files/10111_动态修改请求参数.md?t=1591927043838)
* [使用eureka](files/10112_使用eureka.md?t=1589794156336) * [使用eureka](files/10112_使用eureka.md?t=1591927043838)
* [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1589794156336) * [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1591927043838)
* 原理分析 * 原理分析
* [网关性能测试](files/90001_网关性能测试.md?t=1589794156336) * [网关性能测试](files/90001_网关性能测试.md?t=1591927043838)
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1589794156337) * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1591927043838)
* [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1589794156337) * [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1591927043838)
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1589794156337) * [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1591927043839)
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1589794156337) * [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1591927043839)
* [原理分析之预发布灰度发布](files/90014_原理分析之预发布灰度发布.md?t=1589794156337) * [原理分析之预发布灰度发布](files/90014_原理分析之预发布灰度发布.md?t=1591927043839)
* [2.x升3.x注意事项](files/90099_2.x升3.x注意事项.md?t=1589794156337) * [2.x升3.x注意事项](files/90099_2.x升3.x注意事项.md?t=1591927043839)
* [常见问题](files/90100_常见问题.md?t=1589794156337) * [常见问题](files/90100_常见问题.md?t=1591927043839)

@ -12,7 +12,7 @@
- 启动微服务:打开`sop-example/sop-story/sop-story-web`下的`application-dev.properties`文件 - 启动微服务:打开`sop-example/sop-story/sop-story-web`下的`application-dev.properties`文件
1. 指定nacos地址,如果nacos安装在本机则不用改 1. 指定nacos地址,如果nacos安装在本机则不用改
2. 运行`SopStoryApplication.java` 2. 运行`SopStoryApplication.java`
- 找到sop-test,打开`AllInOneTest.java`进行接口调用测试 - 找到sop-test,运行`com.gitee.sop.test.AlipayClientPostTest.testGet`进行接口调用测试
## 使用admin ## 使用admin

@ -78,7 +78,7 @@ public class ZuulConfig extends AlipayZuulConfiguration {
} }
``` ```
**注**:网关设置了CustomDataNameBuilder后,SDK也要做相应的更改:`SdkConfig.dataNameBuilder = new CustomDataNameBuilder();` **注**:网关设置了CustomDataNameBuilder后,SDK也要做相应的更改:`OpenConfig.dataNameBuilder = new CustomDataNameBuilder();`
## 自定义结果处理 ## 自定义结果处理

@ -67,15 +67,14 @@ spring.redis.host=127.0.0.1
spring.redis.port=6379 spring.redis.port=6379
``` ```
- ZuulConfig.java中添加如下代码: - 在启动类中添加如下代码:
```java ```java
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Override @PostConstruct
protected void doAfter() { public void doAfter() {
super.doAfter();
ApiConfig.getInstance().setLimitManager(new RedisLimitManager(redisTemplate)); ApiConfig.getInstance().setLimitManager(new RedisLimitManager(redisTemplate));
} }
``` ```

@ -2,12 +2,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId> <artifactId>sop-parent</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<description>一个开放平台解决方案项目,基于Spring Cloud实现,目标是能够让用户快速得搭建起自己的开放平台</description> <description>一个开放平台解决方案项目,基于Spring Cloud实现,目标是能够让用户快速得搭建起自己的开放平台</description>
<modules> <modules>
@ -21,4 +27,224 @@
<module>sop-sdk</module> <module>sop-sdk</module>
<module>sop-website</module> <module>sop-website</module>
</modules> </modules>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- springboot 版本-->
<spring-boot.version>2.2.5.RELEASE</spring-boot.version>
<!-- spring cloud 版本 -->
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
<!-- spring cloud alibaba 版本 -->
<!-- 具体版本对应关系见:https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E -->
<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
<!-- Logging -->
<logback.version>1.2.3</logback.version>
<slf4j.version>1.7.5</slf4j.version>
<!-- Test -->
<junit.version>4.11</junit.version>
<fastjson.version>1.2.70</fastjson.version>
<commons-io.version>2.5</commons-io.version>
<commons-fileupload.version>1.3.3</commons-fileupload.version>
<commons-collection.version>3.2.2</commons-collection.version>
<commons-lang3.version>3.8.1</commons-lang3.version>
<commons-codec.version>1.11</commons-codec.version>
<commons-logging.version>1.2</commons-logging.version>
<validation-api.version>2.0.1.Final</validation-api.version>
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
<fastmybatis.version>1.9.1</fastmybatis.version>
<spring-data-redis.version>2.3.0.RELEASE</spring-data-redis.version>
<guava.version>27.1-jre</guava.version>
<swagger.version>1.5.21</swagger.version>
<springfox-spring-web.version>2.9.2</springfox-spring-web.version>
<easyopen.version>1.16.9</easyopen.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- 加了这个就不需要加版本号了 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>net.oschina.durcframework</groupId>
<artifactId>fastmybatis-spring-boot-starter</artifactId>
<version>${fastmybatis.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId>
<version>${springfox-spring-web.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>net.oschina.durcframework</groupId>
<artifactId>easyopen</artifactId>
<version>${easyopen.version}</version>
</dependency>
<dependency>
<groupId>net.oschina.durcframework</groupId>
<artifactId>easyopen-spring-boot-starter</artifactId>
<version>${easyopen.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${validation-api.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring-data-redis.version}</version>
</dependency>
<!-- commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons-collection.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<build>
<plugins>
<!-- 打包时跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>

@ -2,8 +2,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-admin</artifactId> <artifactId>sop-admin</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>

@ -1,60 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-admin-server</artifactId> <artifactId>sop-admin-server</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-admin-server</name>
<description>sop-admin-server</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties> <properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<okhttp.version>3.11.0</okhttp.version>
<!-- springboot for nacos,https://nacos.io/zh-cn/docs/quick-start-spring-boot.html -->
<nacos-spring-boot-starter.version>0.2.3</nacos-spring-boot-starter.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.alibaba.boot</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${nacos-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
<version>${nacos-spring-boot-starter.version}</version>
</dependency> </dependency>
<!-- easyopen starter --> <!-- easyopen starter -->
<dependency> <dependency>
<groupId>net.oschina.durcframework</groupId> <groupId>net.oschina.durcframework</groupId>
<artifactId>easyopen-spring-boot-starter</artifactId> <artifactId>easyopen-spring-boot-starter</artifactId>
<version>1.16.6.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.oschina.durcframework</groupId> <groupId>net.oschina.durcframework</groupId>
<artifactId>fastmybatis-spring-boot-starter</artifactId> <artifactId>fastmybatis-spring-boot-starter</artifactId>
<version>1.8.6.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId> <artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency> </dependency>
<dependency> <dependency>
@ -67,6 +52,7 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>

@ -2,7 +2,9 @@ package com.gitee.sop.adminserver;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication @SpringBootApplication
public class SopAdminServerApplication { public class SopAdminServerApplication {

@ -46,8 +46,8 @@ public class ConfigServiceRoute {
/** uri后面跟的path, 数据库字段:path */ /** uri后面跟的path, 数据库字段:path */
private String path; private String path;
/** 路由执行的顺序, 数据库字段:order */ /** 路由执行的顺序, 数据库字段:order_index */
private Integer order; private Integer orderIndex;
/** 是否忽略验证,业务参数验证除外, 数据库字段:ignore_validate */ /** 是否忽略验证,业务参数验证除外, 数据库字段:ignore_validate */
private Byte ignoreValidate; private Byte ignoreValidate;

@ -1,9 +1,12 @@
package com.gitee.sop.adminserver.service; package com.gitee.sop.adminserver.service;
import com.gitee.fastmybatis.core.query.Query;
import com.gitee.sop.adminserver.api.service.param.ServiceSearchParam; import com.gitee.sop.adminserver.api.service.param.ServiceSearchParam;
import com.gitee.sop.adminserver.api.service.result.ServiceInstanceVO; import com.gitee.sop.adminserver.api.service.result.ServiceInstanceVO;
import com.gitee.sop.adminserver.bean.ServiceInfo; import com.gitee.sop.adminserver.bean.ServiceInfo;
import com.gitee.sop.adminserver.bean.ServiceInstance; import com.gitee.sop.adminserver.bean.ServiceInstance;
import com.gitee.sop.adminserver.entity.ConfigGrayInstance;
import com.gitee.sop.adminserver.mapper.ConfigGrayInstanceMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -12,8 +15,12 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
/** /**
* @author tanghc * @author tanghc
@ -22,9 +29,13 @@ import java.util.concurrent.atomic.AtomicInteger;
@Service @Service
public class ServerService { public class ServerService {
public static final int GRAY_OPEN = 1;
@Autowired @Autowired
private RegistryService registryService; private RegistryService registryService;
@Autowired
private ConfigGrayInstanceMapper grayInstanceMapper;
public List<ServiceInstanceVO> listService(ServiceSearchParam param) { public List<ServiceInstanceVO> listService(ServiceSearchParam param) {
List<ServiceInfo> serviceInfos; List<ServiceInfo> serviceInfos;
try { try {
@ -33,6 +44,10 @@ public class ServerService {
log.error("获取服务实例失败", e); log.error("获取服务实例失败", e);
return Collections.emptyList(); return Collections.emptyList();
} }
List<ConfigGrayInstance> configGrayInstances = grayInstanceMapper.list(new Query());
// key: instanceId
Map<String, ConfigGrayInstance> grayInstanceMap = configGrayInstances.stream()
.collect(Collectors.toMap(ConfigGrayInstance::getInstanceId, Function.identity()));
List<ServiceInstanceVO> serviceInfoVoList = new ArrayList<>(); List<ServiceInstanceVO> serviceInfoVoList = new ArrayList<>();
AtomicInteger idGen = new AtomicInteger(1); AtomicInteger idGen = new AtomicInteger(1);
serviceInfos.stream() serviceInfos.stream()
@ -58,12 +73,22 @@ public class ServerService {
instanceVO.setId(id); instanceVO.setId(id);
instanceVO.setParentId(pid); instanceVO.setParentId(pid);
if (instanceVO.getMetadata() == null) { if (instanceVO.getMetadata() == null) {
instanceVO.setMetadata(Collections.emptyMap()); instanceVO.setMetadata(new HashMap<>(8));
} }
bindGrayEnv(instanceVO, grayInstanceMap);
serviceInfoVoList.add(instanceVO); serviceInfoVoList.add(instanceVO);
} }
}); });
return serviceInfoVoList; return serviceInfoVoList;
} }
private void bindGrayEnv(ServiceInstanceVO instanceVO, Map<String, ConfigGrayInstance> grayInstanceMap) {
String instanceId = instanceVO.getInstanceId();
ConfigGrayInstance configGrayInstance = grayInstanceMap.get(instanceId);
if (configGrayInstance != null && configGrayInstance.getStatus() == GRAY_OPEN) {
Map<String, String> metadata = instanceVO.getMetadata();
metadata.put("env", "gray");
}
}
} }

@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=favicon.ico><title>SOP Admin</title><link href=static/css/chunk-elementUI.81cf475c.css rel=stylesheet><link href=static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=static/css/app.c6dfb7ee.css rel=stylesheet></head><body><noscript><strong>We're sorry but SOP Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script>(function(e){function n(n){for(var r,c,a=n[0],f=n[1],i=n[2],d=0,l=[];d<a.length;d++)c=a[d],u[c]&&l.push(u[c][0]),u[c]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);h&&h(n);while(l.length)l.shift()();return o.push.apply(o,i||[]),t()}function t(){for(var e,n=0;n<o.length;n++){for(var t=o[n],r=!0,c=1;c<t.length;c++){var a=t[c];0!==u[a]&&(r=!1)}r&&(o.splice(n--,1),e=f(f.s=t[0]))}return e}var r={},c={runtime:0},u={runtime:0},o=[];function a(e){return f.p+"static/js/"+({}[e]||e)+"."+{"chunk-25908fca":"66819987","chunk-2c1f2e8f":"f092c0a0","chunk-2d0d32e7":"213708f2","chunk-2d2085ef":"91d75f3c","chunk-2d221c34":"20057287","chunk-4de1c2b6":"e74e3d03","chunk-626b7094":"97d3a892","chunk-73b2dcec":"60c5d8e9","chunk-9b31c83a":"52bc6b2c","chunk-9f479afe":"51cf2439","chunk-c3ce42fe":"9517b588"}[e]+".js"}function f(n){if(r[n])return r[n].exports;var t=r[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var n=[],t={"chunk-25908fca":1,"chunk-2c1f2e8f":1,"chunk-4de1c2b6":1,"chunk-626b7094":1,"chunk-73b2dcec":1,"chunk-9b31c83a":1,"chunk-c3ce42fe":1};c[e]?n.push(c[e]):0!==c[e]&&t[e]&&n.push(c[e]=new Promise(function(n,t){for(var r="static/css/"+({}[e]||e)+"."+{"chunk-25908fca":"a66354ec","chunk-2c1f2e8f":"0314067f","chunk-2d0d32e7":"31d6cfe0","chunk-2d2085ef":"31d6cfe0","chunk-2d221c34":"31d6cfe0","chunk-4de1c2b6":"a37cd815","chunk-626b7094":"e41ad972","chunk-73b2dcec":"ed391cc5","chunk-9b31c83a":"3b12267b","chunk-9f479afe":"31d6cfe0","chunk-c3ce42fe":"6b789903"}[e]+".css",u=f.p+r,o=document.getElementsByTagName("link"),a=0;a<o.length;a++){var i=o[a],d=i.getAttribute("data-href")||i.getAttribute("href");if("stylesheet"===i.rel&&(d===r||d===u))return n()}var l=document.getElementsByTagName("style");for(a=0;a<l.length;a++){i=l[a],d=i.getAttribute("data-href");if(d===r||d===u)return n()}var h=document.createElement("link");h.rel="stylesheet",h.type="text/css",h.onload=n,h.onerror=function(n){var r=n&&n.target&&n.target.src||u,o=new Error("Loading CSS chunk "+e+" failed.\n("+r+")");o.code="CSS_CHUNK_LOAD_FAILED",o.request=r,delete c[e],h.parentNode.removeChild(h),t(o)},h.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(h)}).then(function(){c[e]=0}));var r=u[e];if(0!==r)if(r)n.push(r[2]);else{var o=new Promise(function(n,t){r=u[e]=[n,t]});n.push(r[2]=o);var i,d=document.createElement("script");d.charset="utf-8",d.timeout=120,f.nc&&d.setAttribute("nonce",f.nc),d.src=a(e),i=function(n){d.onerror=d.onload=null,clearTimeout(l);var t=u[e];if(0!==t){if(t){var r=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src,o=new Error("Loading chunk "+e+" failed.\n("+r+": "+c+")");o.type=r,o.request=c,t[1](o)}u[e]=void 0}};var l=setTimeout(function(){i({type:"timeout",target:d})},12e4);d.onerror=d.onload=i,document.head.appendChild(d)}return Promise.all(n)},f.m=e,f.c=r,f.d=function(e,n,t){f.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,n){if(1&n&&(e=f(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)f.d(t,r,function(n){return e[n]}.bind(null,r));return t},f.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return f.d(n,"a",n),n},f.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},f.p="",f.oe=function(e){throw console.error(e),e};var i=window["webpackJsonp"]=window["webpackJsonp"]||[],d=i.push.bind(i);i.push=n,i=i.slice();for(var l=0;l<i.length;l++)n(i[l]);var h=d;t()})([]);</script><script src=static/js/chunk-elementUI.298ac98c.js></script><script src=static/js/chunk-libs.75deb05f.js></script><script src=static/js/app.c6e80241.js></script></body></html> <!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=favicon.ico><title>SOP Admin</title><link href=static/css/chunk-elementUI.81cf475c.css rel=stylesheet><link href=static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=static/css/app.c6dfb7ee.css rel=stylesheet></head><body><noscript><strong>We're sorry but SOP Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script>(function(e){function n(n){for(var r,c,a=n[0],f=n[1],i=n[2],d=0,l=[];d<a.length;d++)c=a[d],u[c]&&l.push(u[c][0]),u[c]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);h&&h(n);while(l.length)l.shift()();return o.push.apply(o,i||[]),t()}function t(){for(var e,n=0;n<o.length;n++){for(var t=o[n],r=!0,c=1;c<t.length;c++){var a=t[c];0!==u[a]&&(r=!1)}r&&(o.splice(n--,1),e=f(f.s=t[0]))}return e}var r={},c={runtime:0},u={runtime:0},o=[];function a(e){return f.p+"static/js/"+({}[e]||e)+"."+{"chunk-25908fca":"66819987","chunk-2c1f2e8f":"f092c0a0","chunk-2d0d32e7":"213708f2","chunk-2d2085ef":"91d75f3c","chunk-2d221c34":"20057287","chunk-4de1c2b6":"e74e3d03","chunk-626b7094":"97d3a892","chunk-73b2dcec":"60c5d8e9","chunk-9b31c83a":"52bc6b2c","chunk-9f479afe":"4609bf8b","chunk-c3ce42fe":"9517b588"}[e]+".js"}function f(n){if(r[n])return r[n].exports;var t=r[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var n=[],t={"chunk-25908fca":1,"chunk-2c1f2e8f":1,"chunk-4de1c2b6":1,"chunk-626b7094":1,"chunk-73b2dcec":1,"chunk-9b31c83a":1,"chunk-c3ce42fe":1};c[e]?n.push(c[e]):0!==c[e]&&t[e]&&n.push(c[e]=new Promise(function(n,t){for(var r="static/css/"+({}[e]||e)+"."+{"chunk-25908fca":"a66354ec","chunk-2c1f2e8f":"0314067f","chunk-2d0d32e7":"31d6cfe0","chunk-2d2085ef":"31d6cfe0","chunk-2d221c34":"31d6cfe0","chunk-4de1c2b6":"a37cd815","chunk-626b7094":"e41ad972","chunk-73b2dcec":"ed391cc5","chunk-9b31c83a":"3b12267b","chunk-9f479afe":"31d6cfe0","chunk-c3ce42fe":"6b789903"}[e]+".css",u=f.p+r,o=document.getElementsByTagName("link"),a=0;a<o.length;a++){var i=o[a],d=i.getAttribute("data-href")||i.getAttribute("href");if("stylesheet"===i.rel&&(d===r||d===u))return n()}var l=document.getElementsByTagName("style");for(a=0;a<l.length;a++){i=l[a],d=i.getAttribute("data-href");if(d===r||d===u)return n()}var h=document.createElement("link");h.rel="stylesheet",h.type="text/css",h.onload=n,h.onerror=function(n){var r=n&&n.target&&n.target.src||u,o=new Error("Loading CSS chunk "+e+" failed.\n("+r+")");o.code="CSS_CHUNK_LOAD_FAILED",o.request=r,delete c[e],h.parentNode.removeChild(h),t(o)},h.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(h)}).then(function(){c[e]=0}));var r=u[e];if(0!==r)if(r)n.push(r[2]);else{var o=new Promise(function(n,t){r=u[e]=[n,t]});n.push(r[2]=o);var i,d=document.createElement("script");d.charset="utf-8",d.timeout=120,f.nc&&d.setAttribute("nonce",f.nc),d.src=a(e),i=function(n){d.onerror=d.onload=null,clearTimeout(l);var t=u[e];if(0!==t){if(t){var r=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src,o=new Error("Loading chunk "+e+" failed.\n("+r+": "+c+")");o.type=r,o.request=c,t[1](o)}u[e]=void 0}};var l=setTimeout(function(){i({type:"timeout",target:d})},12e4);d.onerror=d.onload=i,document.head.appendChild(d)}return Promise.all(n)},f.m=e,f.c=r,f.d=function(e,n,t){f.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,n){if(1&n&&(e=f(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)f.d(t,r,function(n){return e[n]}.bind(null,r));return t},f.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return f.d(n,"a",n),n},f.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},f.p="",f.oe=function(e){throw console.error(e),e};var i=window["webpackJsonp"]=window["webpackJsonp"]||[],d=i.push.bind(i);i.push=n,i=i.slice();for(var l=0;l<i.length;l++)n(i[l]);var h=d;t()})([]);</script><script src=static/js/chunk-elementUI.298ac98c.js></script><script src=static/js/chunk-libs.75deb05f.js></script><script src=static/js/app.c6e80241.js></script></body></html>

@ -67,7 +67,7 @@
width="250" width="250"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<div v-if="scope.row.serviceId.toLowerCase() !== 'sop-gateway'"> <div v-if="blackList.indexOf(scope.row.serviceId.toLowerCase()) < 0">
<div v-if="scope.row.parentId === 0"> <div v-if="scope.row.parentId === 0">
<el-button type="text" size="mini" @click="onGrayConfigUpdate(scope.row)">设置灰度参数</el-button> <el-button type="text" size="mini" @click="onGrayConfigUpdate(scope.row)">设置灰度参数</el-button>
</div> </div>
@ -204,6 +204,7 @@ export default {
searchFormData: { searchFormData: {
serviceId: '' serviceId: ''
}, },
blackList: ['sop-gateway', 'sop-admin'],
grayDialogVisible: false, grayDialogVisible: false,
grayForm: { grayForm: {
serviceId: '', serviceId: '',

@ -1,22 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-auth</artifactId> <artifactId>sop-parent</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-auth</artifactId>
<name>sop-auth</name> <name>sop-auth</name>
<description>授权程序</description> <description>授权程序</description>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<oltu.version>0.31</oltu.version> <oltu.version>0.31</oltu.version>
</properties> </properties>
@ -26,35 +25,14 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</dependency> </dependency>
<!-- sop相关配置 end--> <!-- sop相关配置 end-->
<!-- 使用nacos注册中心 <!-- 使用nacos注册中心 -->
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>0.2.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>1.1.0</version>
</dependency>
-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> </dependency>
<dependency> <dependency>
@ -72,7 +50,6 @@
<dependency> <dependency>
<groupId>net.oschina.durcframework</groupId> <groupId>net.oschina.durcframework</groupId>
<artifactId>fastmybatis-spring-boot-starter</artifactId> <artifactId>fastmybatis-spring-boot-starter</artifactId>
<version>1.7.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
@ -123,18 +100,6 @@
</dependency> </dependency>
</dependencies> </dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
* oauth2管理redis实现这个类跟OAuth2ManagerCache类只能用一个 * oauth2管理redis实现这个类跟OAuth2ManagerCache类只能用一个
* 如果要用这个类 * 如果要用这个类
* 1注释掉OAuth2ManagerCache的@Service * 1注释掉OAuth2ManagerCache的@Service
* 2打开yml中redis部分 * 2在properties中配置redis
* 3启用这个类的@Service * 3启用这个类的@Service
* *
* @author tanghc * @author tanghc

@ -2,35 +2,21 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<spring-boot.version>2.1.2.RELEASE</spring-boot.version>
<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>
<!-- Test -->
<junit.version>4.11</junit.version>
<fastjson.version>1.2.62</fastjson.version>
<commons-io.version>2.5</commons-io.version>
<commons-fileupload.version>1.3.3</commons-fileupload.version>
<commons-collection.version>3.2.2</commons-collection.version>
<commons-lang3.version>3.8.1</commons-lang3.version>
<commons-codec.version>1.11</commons-codec.version>
<validation-api.version>2.0.1.Final</validation-api.version>
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
<spring-cloud-alibaba-nacos.version>0.9.0.RELEASE</spring-cloud-alibaba-nacos.version>
</properties> </properties>
<modules> <modules>
@ -40,149 +26,5 @@
<module>sop-bridge-gateway</module> <module>sop-bridge-gateway</module>
</modules> </modules>
<dependencyManagement>
<dependencies>
<!-- 加了这个就不需要加版本号了 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-discovery</artifactId>
<version>${spring-cloud-alibaba-nacos.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
<version>${spring-cloud-alibaba-nacos.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${validation-api.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<!-- commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons-collection.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<!-- optional -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.1.4.RELEASE</version>
<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>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<build>
<plugins>
<!-- 打包时跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>

@ -3,13 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>sop-common</artifactId>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<version>3.1.5-SNAPSHOT</version> <artifactId>sop-parent</artifactId>
<relativePath>../pom.xml</relativePath> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
<artifactId>sop-bridge-gateway</artifactId> <artifactId>sop-bridge-gateway</artifactId>
@ -17,7 +17,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

@ -3,13 +3,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>sop-common</artifactId>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<version>3.1.5-SNAPSHOT</version> <artifactId>sop-parent</artifactId>
<relativePath>../pom.xml</relativePath> <version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
<artifactId>sop-bridge-zuul</artifactId> <artifactId>sop-bridge-zuul</artifactId>
@ -17,7 +18,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-parent</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent> </parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-gateway-common</name>
<description>sop-gateway-common</description>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
</properties> </properties>
@ -23,9 +22,12 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency> <dependency>
<groupId>commons-fileupload</groupId> <groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId> <artifactId>commons-fileupload</artifactId>
@ -36,22 +38,20 @@
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version> <version>${commons-codec.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-ribbon</artifactId> <artifactId>spring-cloud-netflix-ribbon</artifactId>
<scope>compile</scope>
</dependency> </dependency>
<!-- optional --> <!-- optional -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
@ -74,22 +74,34 @@
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId> <artifactId>spring-cloud-netflix-eureka-server</artifactId>
<version>2.1.0.RELEASE</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.netflix.ribbon</groupId> <groupId>org.springframework.data</groupId>
<artifactId>ribbon-eureka</artifactId> <artifactId>spring-data-redis</artifactId>
<version>2.3.0</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- test -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.12</version> <version>4.12</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>

@ -1,6 +1,7 @@
package com.gitee.sop.gatewaycommon.bean; package com.gitee.sop.gatewaycommon.bean;
import lombok.Data; import lombok.Data;
import org.springframework.cloud.gateway.route.Route;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -80,4 +81,6 @@ public class RouteDefinition {
* 是否是兼容模式即使用了@ApiAbility注解 * 是否是兼容模式即使用了@ApiAbility注解
*/ */
private int compatibleMode; private int compatibleMode;
private Route route;
} }

@ -7,8 +7,8 @@ import org.reactivestreams.Publisher;
import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.filter.NettyWriteResponseFilter; import org.springframework.cloud.gateway.filter.NettyWriteResponseFilter;
import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage;
import org.springframework.cloud.gateway.support.BodyInserterContext; import org.springframework.cloud.gateway.support.BodyInserterContext;
import org.springframework.cloud.gateway.support.CachedBodyOutputMessage;
import org.springframework.cloud.gateway.support.DefaultClientResponse; import org.springframework.cloud.gateway.support.DefaultClientResponse;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBuffer;

@ -13,8 +13,8 @@ import com.gitee.sop.gatewaycommon.validate.Validator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage;
import org.springframework.cloud.gateway.support.BodyInserterContext; import org.springframework.cloud.gateway.support.BodyInserterContext;
import org.springframework.cloud.gateway.support.CachedBodyOutputMessage;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBuffer;

@ -1,7 +1,7 @@
package com.gitee.sop.gatewaycommon.gateway.loadbalancer; package com.gitee.sop.gatewaycommon.gateway.loadbalancer;
import com.alibaba.cloud.nacos.ribbon.NacosServer;
import com.netflix.loadbalancer.Server; import com.netflix.loadbalancer.Server;
import org.springframework.cloud.alibaba.nacos.ribbon.NacosServer;
import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector; import org.springframework.cloud.netflix.ribbon.DefaultServerIntrospector;
import java.util.Map; import java.util.Map;

@ -42,10 +42,13 @@ public class GatewayRouteRepository implements RouteRepository<GatewayTargetRout
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
private RouteLocator routeLocator; private volatile RouteLocator routeLocator;
@Override @Override
public Flux<Route> getRoutes() { public Flux<Route> getRoutes() {
if (routeLocator == null) {
return Flux.empty();
}
return routeLocator.getRoutes(); return routeLocator.getRoutes();
} }
@ -59,6 +62,7 @@ public class GatewayRouteRepository implements RouteRepository<GatewayTargetRout
r -> r.path(routeDefinition.getPath()) r -> r.path(routeDefinition.getPath())
.uri(routeDefinition.getUri()))); .uri(routeDefinition.getUri())));
this.routeLocator = builder.build(); this.routeLocator = builder.build();
// 触发 // 触发
applicationContext.publishEvent(new RefreshRoutesEvent(new Object())); applicationContext.publishEvent(new RefreshRoutesEvent(new Object()));
} }

@ -1,119 +0,0 @@
package com.gitee.sop.gatewaycommon.manager;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.AbstractListener;
import com.alibaba.nacos.api.exception.NacosException;
import com.gitee.sop.gatewaycommon.bean.ChannelMsg;
import com.gitee.sop.gatewaycommon.bean.NacosConfigs;
import com.gitee.sop.gatewaycommon.secret.IsvManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.PostConstruct;
/**
* 用不到了这个类的作用是监听消息推送用的由admin推送一条config配置然后这里触发事件
* 现在改为直接由admin请求网关提供的接口进行配置修改
* 考虑
*
* @author tanghc
*/
@Slf4j
@Deprecated
public class NacosEventProcessor {
@NacosInjected
private ConfigService configService;
@Autowired
private EnvGrayManager envGrayManager;
@Autowired
private IPBlacklistManager ipBlacklistManager;
@Autowired
private IsvManager isvManager;
@Autowired
private IsvRoutePermissionManager isvRoutePermissionManager;
@Autowired
private LimitConfigManager limitConfigManager;
@Autowired
private RouteConfigManager routeConfigManager;
@PostConstruct
public void after() throws NacosException {
log.debug("初始化nacos事件监听");
initEnvGray();
initIPBlack();
initIsv();
initIsvRoutePermission();
initLimitConfig();
initRouteConfig();
}
private void initEnvGray() throws NacosException {
configService.addListener(NacosConfigs.DATA_ID_GRAY, NacosConfigs.GROUP_CHANNEL, new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class);
envGrayManager.process(channelMsg);
}
});
}
private void initIPBlack() throws NacosException {
configService.addListener(NacosConfigs.DATA_ID_IP_BLACKLIST, NacosConfigs.GROUP_CHANNEL, new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class);
ipBlacklistManager.process(channelMsg);
}
});
}
private void initIsv() throws NacosException {
configService.addListener(NacosConfigs.DATA_ID_ISV, NacosConfigs.GROUP_CHANNEL, new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class);
isvManager.process(channelMsg);
}
});
}
private void initIsvRoutePermission() throws NacosException {
configService.addListener(NacosConfigs.DATA_ID_ROUTE_PERMISSION, NacosConfigs.GROUP_CHANNEL, new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class);
isvRoutePermissionManager.process(channelMsg);
}
});
}
private void initLimitConfig() throws NacosException {
configService.addListener(NacosConfigs.DATA_ID_LIMIT_CONFIG, NacosConfigs.GROUP_CHANNEL, new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class);
limitConfigManager.process(channelMsg);
}
});
}
private void initRouteConfig() throws NacosException {
configService.addListener(NacosConfigs.DATA_ID_ROUTE_CONFIG, NacosConfigs.GROUP_CHANNEL, new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class);
routeConfigManager.process(channelMsg);
}
});
}
}

@ -1,183 +0,0 @@
package com.gitee.sop.gatewaycommon.manager;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.gitee.sop.gatewaycommon.bean.NacosConfigs;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.bean.TargetRoute;
import com.gitee.sop.gatewaycommon.route.RegistryMetadata;
import com.gitee.sop.gatewaycommon.route.RegistryListener;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
import org.springframework.context.ApplicationEvent;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 发现新服务更新路由信息
*
* @author tanghc
*
* @deprecated
* @see RegistryListener
*/
@Deprecated
@Slf4j
public class ServiceRoutesLoader<T extends TargetRoute> implements RegistryMetadata {
private static final String SOP_ROUTES_PATH = "/sop/routes";
private static final String SECRET = "a3d9sf!1@odl90zd>fkASwq";
private static final int FIVE_SECONDS = 1000 * 5;
private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path";
@Autowired
private NacosDiscoveryProperties nacosDiscoveryProperties;
@NacosInjected
private ConfigService configService;
@Autowired
private BaseRouteCache<T> baseRouteCache;
private RestTemplate restTemplate = new RestTemplate();
private Map<String, Long> updateTimeMap = new HashMap<>(16);
public ServiceRoutesLoader() {
// 解决statusCode不等于200,就抛异常问题
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
protected boolean hasError(HttpStatus statusCode) {
return statusCode == null;
}
});
}
public synchronized void load(ApplicationEvent event) {
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
List<ServiceInfo> subscribes = null;
try {
subscribes = namingService.getSubscribeServices();
} catch (NacosException e) {
log.error("namingService.getSubscribeServices()错误", e);
}
if (CollectionUtils.isEmpty(subscribes)) {
return;
}
// subscribe
String thisServiceId = nacosDiscoveryProperties.getService();
for (ServiceInfo serviceInfo : subscribes) {
String serviceName = serviceInfo.getName();
// 如果是本机服务,跳过
if (Objects.equals(thisServiceId, serviceName)) {
continue;
}
// nacos会不停的触发事件,这里做了一层拦截
// 同一个serviceId5秒内允许访问一次
Long lastUpdateTime = updateTimeMap.getOrDefault(serviceName, 0L);
long now = System.currentTimeMillis();
if (now - lastUpdateTime < FIVE_SECONDS) {
continue;
}
updateTimeMap.put(serviceName, now);
try {
String dataId = NacosConfigs.getRouteDataId(serviceName);
String groupId = NacosConfigs.GROUP_ROUTE;
List<Instance> allInstances = namingService.getAllInstances(serviceName);
if (CollectionUtils.isEmpty(allInstances)) {
// 如果没有服务列表,则删除所有路由信息
log.info("服务下线,删除路由配置,serviceId: {}", serviceName);
baseRouteCache.remove(serviceName);
configService.removeConfig(dataId, groupId);
} else {
for (Instance instance : allInstances) {
String url = getRouteRequestUrl(instance);
log.info("拉取路由配置,serviceId: {}, url: {}", serviceName, url);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
if (responseEntity.getStatusCode() == HttpStatus.OK) {
String body = responseEntity.getBody();
ServiceRouteInfo serviceRouteInfo = JSON.parseObject(body, ServiceRouteInfo.class);
baseRouteCache.load(serviceRouteInfo, callback -> {
try {
log.info("推送路由配置到nacos,dataId: {}, groupId: {}", dataId, groupId);
configService.publishConfig(dataId, groupId, body);
} catch (NacosException e) {
log.error("nacos推送失败,serviceId: {}, instance: {}", serviceName, instance);
}
});
} else {
log.error("拉取路由配置异常,url: {}, status: {}, body: {}", url, responseEntity.getStatusCodeValue(), responseEntity.getBody());
}
}
}
} catch (Exception e) {
log.error("选择服务实例失败,serviceName: {}", serviceName, e);
}
}
}
/**
* 拉取路由请求url
* @param instance 服务实例
* @return 返回最终url
*/
private String getRouteRequestUrl(Instance instance) {
Map<String, String> metadata = instance.getMetadata();
String customPath = metadata.get(METADATA_SOP_ROUTES_PATH);
String homeUrl;
String servletPath;
// 如果metadata中指定了获取路由的url
if (StringUtils.isNotBlank(customPath)) {
// 自定义完整的url
if (customPath.startsWith("http")) {
homeUrl = customPath;
servletPath = "";
} else {
homeUrl = getHomeUrl(instance);
servletPath = customPath;
}
} else {
// 默认处理
homeUrl = getHomeUrl(instance);
String contextPath = this.getContextPath(metadata);
servletPath = contextPath + SOP_ROUTES_PATH;
}
if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) {
servletPath = '/' + servletPath;
}
String query = buildQuery(SECRET);
return homeUrl + servletPath + query;
}
private static String getHomeUrl(Instance instance) {
return "http://" + instance.getIp() + ":" + instance.getPort();
}
private static String buildQuery(String secret) {
String time = String.valueOf(System.currentTimeMillis());
String source = secret + time + secret;
String sign = DigestUtils.md5DigestAsHex(source.getBytes());
return "?time=" + time + "&sign=" + sign;
}
}

@ -27,6 +27,7 @@ public abstract class BaseRegistryListener implements RegistryListener {
static { static {
EXCLUDE_SERVICE_ID_LIST.add("sop-gateway"); EXCLUDE_SERVICE_ID_LIST.add("sop-gateway");
EXCLUDE_SERVICE_ID_LIST.add("sop-website"); EXCLUDE_SERVICE_ID_LIST.add("sop-website");
EXCLUDE_SERVICE_ID_LIST.add("sop-admin");
EXCLUDE_SERVICE_ID_LIST.add("website-server"); EXCLUDE_SERVICE_ID_LIST.add("website-server");
} }

@ -4,8 +4,6 @@ import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.Application; import com.netflix.discovery.shared.Application;
import com.netflix.discovery.shared.Applications; import com.netflix.discovery.shared.Applications;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.cloud.netflix.eureka.CloudEurekaClient; import org.springframework.cloud.netflix.eureka.CloudEurekaClient;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
@ -46,6 +44,7 @@ public class EurekaRegistryListener extends BaseRegistryListener {
.collect(Collectors.toList()); .collect(Collectors.toList());
final Set<ServiceHolder> currentServices = new HashSet<>(serviceList); final Set<ServiceHolder> currentServices = new HashSet<>(serviceList);
// 删除现有的,剩下的就是新服务
currentServices.removeAll(cacheServices); currentServices.removeAll(cacheServices);
// 如果有新的服务注册进来 // 如果有新的服务注册进来
if (currentServices.size() > 0) { if (currentServices.size() > 0) {
@ -115,10 +114,4 @@ public class EurekaRegistryListener extends BaseRegistryListener {
deletedServices.forEach(this::removeRoutes); deletedServices.forEach(this::removeRoutes);
} }
@Data
@AllArgsConstructor
private static class ServiceHolder {
private String serviceId;
private long lastUpdatedTimestamp;
}
} }

@ -1,20 +1,24 @@
package com.gitee.sop.gatewaycommon.route; package com.gitee.sop.gatewaycommon.route;
import com.alibaba.nacos.api.annotation.NacosInjected; import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import com.alibaba.nacos.api.naming.pojo.ListView;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/** /**
* 加载服务路由nacos实现 * 加载服务路由nacos实现
@ -24,35 +28,60 @@ import java.util.Objects;
@Slf4j @Slf4j
public class NacosRegistryListener extends BaseRegistryListener { public class NacosRegistryListener extends BaseRegistryListener {
private volatile Set<String> cacheServices = new HashSet<>();
@Autowired @Autowired
private NacosDiscoveryProperties nacosDiscoveryProperties; private NacosDiscoveryProperties nacosDiscoveryProperties;
@NacosInjected @Autowired(required = false)
private ConfigService configService; private List<RegistryEvent> registryEventList;
@Override @Override
public void onEvent(ApplicationEvent applicationEvent) { public synchronized void onEvent(ApplicationEvent applicationEvent) {
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance(); NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
List<ServiceInfo> subscribes = null; ListView<String> servicesOfServer = null;
try { try {
subscribes = namingService.getSubscribeServices(); servicesOfServer = namingService.getServicesOfServer(1, Integer.MAX_VALUE);
} catch (NacosException e) { } catch (NacosException e) {
log.error("namingService.getSubscribeServices()错误", e); log.error("namingService.getServicesOfServer()错误", e);
} }
if (CollectionUtils.isEmpty(subscribes)) { if (servicesOfServer == null || CollectionUtils.isEmpty(servicesOfServer.getData())) {
return; return;
} }
subscribes.stream()
.filter(serviceInfo -> this.canOperator(serviceInfo.getName())) Map<String, Instance> instanceMap = servicesOfServer
.forEach(serviceInfo -> { .getData()
String serviceName = serviceInfo.getName(); .stream()
.filter(this::canOperator)
.map(serviceName -> {
try { try {
List<Instance> allInstances = namingService.getAllInstances(serviceName); List<Instance> allInstances = namingService.getAllInstances(serviceName);
if (CollectionUtils.isEmpty(allInstances)) { if (CollectionUtils.isEmpty(allInstances)) {
// 如果没有服务列表,则删除所有路由信息 return null;
removeRoutes(serviceName); }
} else { Instance instance = allInstances.stream()
for (Instance instance : allInstances) { .filter(Instance::isHealthy)
.findFirst()
.orElse(null);
return instance == null ? null : new InstanceInfo(serviceName, instance);
} catch (NacosException e) {
log.error("namingService.getAllInstances(serviceName)错误,serviceName:{}", serviceName, e);
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toMap(InstanceInfo::getServiceName, InstanceInfo::getInstance));
Set<String> serviceNames = instanceMap.keySet();
final Set<String> currentServices = new HashSet<>(serviceNames);
// 删除现有的,剩下的就是新服务
currentServices.removeAll(cacheServices);
// 如果有新的服务注册进来
if (currentServices.size() > 0) {
currentServices.forEach(serviceName -> {
Instance instance = instanceMap.get(serviceName);
InstanceDefinition instanceDefinition = new InstanceDefinition(); InstanceDefinition instanceDefinition = new InstanceDefinition();
instanceDefinition.setInstanceId(instance.getInstanceId()); instanceDefinition.setInstanceId(instance.getInstanceId());
instanceDefinition.setServiceId(serviceName); instanceDefinition.setServiceId(serviceName);
@ -60,12 +89,44 @@ public class NacosRegistryListener extends BaseRegistryListener {
instanceDefinition.setPort(instance.getPort()); instanceDefinition.setPort(instance.getPort());
instanceDefinition.setMetadata(instance.getMetadata()); instanceDefinition.setMetadata(instance.getMetadata());
pullRoutes(instanceDefinition); pullRoutes(instanceDefinition);
if (registryEventList != null) {
registryEventList.forEach(registryEvent -> registryEvent.onRegistry(instanceDefinition));
} }
});
} }
} catch (Exception e) {
log.error("选择服务实例失败,serviceName: {}", serviceName, e); // 如果有服务删除
Set<String> removedServiceIdList = getRemovedServiceId(serviceNames);
if (removedServiceIdList.size() > 0) {
removedServiceIdList.forEach(serviceId->{
this.removeRoutes(serviceId);
if (registryEventList != null) {
registryEventList.forEach(registryEvent -> registryEvent.onRemove(serviceId));
} }
}); });
} }
cacheServices = new HashSet<>(serviceNames);
}
/**
* 获取已经下线的serviceId
*
* @param serviceList 最新的serviceId集合
* @return 返回已下线的serviceId
*/
private Set<String> getRemovedServiceId(Set<String> serviceList) {
Set<String> cache = cacheServices;
// 删除最新的,剩下就是已经删除的
cache.removeAll(serviceList);
return cache;
}
@Data
@AllArgsConstructor
private static class InstanceInfo {
private String serviceName;
private Instance instance;
}
} }

@ -0,0 +1,23 @@
package com.gitee.sop.gatewaycommon.route;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
/**
* 新的实例注册事件
*
* @author tanghc
*/
public interface RegistryEvent {
/**
* 新实例注册进来时触发
* @param instanceDefinition 实例信息
*/
void onRegistry(InstanceDefinition instanceDefinition);
/**
* 服务下线时触发
* @param serviceId 服务id
*/
void onRemove(String serviceId);
}

@ -0,0 +1,11 @@
package com.gitee.sop.gatewaycommon.route;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class ServiceHolder {
private String serviceId;
private long lastUpdatedTimestamp;
}

@ -2,20 +2,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-parent</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent> </parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-service-common</name>
<description>sop-service-common</description>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
</properties> </properties>
@ -25,7 +24,16 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>27.1-jre</version> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency> </dependency>
<!-- optional --> <!-- optional -->
@ -38,19 +46,16 @@
<dependency> <dependency>
<groupId>net.oschina.durcframework</groupId> <groupId>net.oschina.durcframework</groupId>
<artifactId>easyopen</artifactId> <artifactId>easyopen</artifactId>
<version>1.16.1</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-spring-web</artifactId> <artifactId>springfox-spring-web</artifactId>
<version>2.9.2</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.swagger</groupId> <groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId> <artifactId>swagger-annotations</artifactId>
<version>1.5.21</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
@ -76,6 +81,17 @@
<version>3.0.0</version> <version>3.0.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>

@ -1,30 +0,0 @@
package com.gitee.sop.servercommon.manager;
import com.alibaba.fastjson.JSON;
import com.gitee.sop.servercommon.bean.ServiceApiInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
/**
* @author tanghc
*/
@Slf4j
public class RedisApiMetaManager implements ApiMetaManager {
public static final String API_STORE_KEY = "com.gitee.sop.api";
public static final String API_CHANGE_CHANNEL = "channel.sop.api.change";
private StringRedisTemplate redisTemplate;
public RedisApiMetaManager(StringRedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
}
@Override
public void uploadApi(ServiceApiInfo serviceApiInfo) {
log.info("上传接口信息到Redis,serviceId:{}, 接口数量:{}", serviceApiInfo.getServiceId(), serviceApiInfo.getApis().size());
String serviceApiInfoJson = JSON.toJSONString(serviceApiInfo);
redisTemplate.opsForHash().put(API_STORE_KEY, serviceApiInfo.getServiceId(), serviceApiInfoJson);
// 发送订阅事件
redisTemplate.convertAndSend(API_CHANGE_CHANNEL, serviceApiInfoJson);
}
}

@ -2,16 +2,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-example</artifactId> <artifactId>sop-parent</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-example</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>sop-story</module> <module>sop-story</module>
<module>sop-book</module>
<module>sop-easyopen</module>
<module>sop-springmvc</module> <module>sop-springmvc</module>
</modules> </modules>
</project> </project>

@ -1,7 +1,5 @@
# 服务示例 # 服务示例
- sop-story:微服务示例,story服务,同时作为Provider提供服务。本地文档:http://localhost:2222/doc.html - sop-story:微服务示例
- sop-book:微服务示例,book服务,也是Consumer,调用story提供的服务
- sop-auth:应用授权示例 - sop-auth:应用授权示例
- sop-springmvc:springmvc工程实例 - sop-springmvc:springmvc工程实例
- sop-easyopen:整合easyopen示例

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-book-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>sop-book-api</module>
<module>sop-book-web</module>
</modules>
</project>

@ -1,25 +0,0 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-book-api</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -1,12 +0,0 @@
package com.gitee.book.api.domain;
import lombok.Data;
/**
* @author tanghc
*/
@Data
public class Book {
private int id;
private String name;
}

@ -1,14 +0,0 @@
package com.gitee.book.api.service;
import com.gitee.book.api.domain.Book;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author tanghc
*/
@RequestMapping("/book")
public interface BookService {
@RequestMapping("/getBook")
Book getBook(@RequestParam("id") int id);
}

@ -1,25 +0,0 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

@ -1,153 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-book-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sop-book</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<dubbo.version>2.6.5</dubbo.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<!-- nacos spring cloud版本号 -->
<spring-cloud-alibaba-nacos.version>0.9.0.RELEASE</spring-cloud-alibaba-nacos.version>
<!-- nacos客户端版本号 -->
<nacos-client.version>1.1.3</nacos-client.version>
</properties>
<dependencies>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-book-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 使用nacos注册中心
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${spring-cloud-alibaba-nacos.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${nacos-client.version}</version>
</dependency>
-->
<!-- 注册中心end -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- Dubbo Spring Boot Starter -->
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>

@ -1,20 +0,0 @@
package com.gitee.sop.bookweb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
// 允许调用其他服务
@EnableFeignClients
// 服务注册
@EnableDiscoveryClient
@SpringBootApplication
public class SopBookApplication {
public static void main(String[] args) {
SpringApplication.run(SopBookApplication.class, args);
}
}

@ -1,33 +0,0 @@
package com.gitee.sop.bookweb.config;
import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration;
import com.gitee.sop.servercommon.swagger.SwaggerSupport;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* 使用支付宝开放平台功能
* @author tanghc
*/
@Configuration
public class OpenServiceConfig extends AlipayServiceConfiguration {
// 开启文档
@Configuration
@EnableSwagger2
public static class Swagger2 extends SwaggerSupport {
@Override
protected String getDocTitle() {
return "图书API";
}
}
}
/**
* 使用淘宝开放平台功能
* @author tanghc
*/
//@Configuration
//public class OpenServiceConfig extends TaobaoServiceConfiguration {
//
//}

@ -1,14 +0,0 @@
package com.gitee.sop.bookweb.consumer;
import com.gitee.sop.story.api.service.StoryService;
import org.springframework.cloud.openfeign.FeignClient;
/**
* 调用story服务
*
* @author tanghc
*/
// value对应的spring.application.name
@FeignClient("story-service")
public interface StoryServiceConsumer extends StoryService {
}

@ -1,55 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.book.api.domain.Book;
import com.gitee.sop.bookweb.consumer.StoryServiceConsumer;
import com.gitee.sop.bookweb.param.BookParam;
import com.gitee.sop.bookweb.vo.BookVO;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.story.api.domain.Story;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
/**
* 这里演示如何接受业务参数
* @author tanghc
*/
@Api(tags = "图书接口")
@RestController
public class AlipayBookController {
@Autowired
StoryServiceConsumer storyServiceConsumer;
@ApiOperation(value="查询书本信息", notes = "可以根据ISBN查询书本信息")
@ApiMapping(value = "book.search")
public BookVO searchBook(BookParam param) {
BookVO bookVO = new BookVO();
bookVO.setId(1);
bookVO.setName("白雪公主,ISBN:" + param.getIsbn());
bookVO.setIsbn("ABCSSSSDDD");
return bookVO;
}
@ApiMapping(value = "alipay.book.get")
public Book getBook() {
Book story = new Book();
story.setId(1);
story.setName("白雪公主(alipay.book.get)");
return story;
}
// 通过Feign调用story服务
@ApiMapping(value = "alipay.book.story.get")
public Object getBook2() {
Story story = new Story();
story.setId(1);
story.setName("白雪公主(alipay.book.story.get)");
Story story2 = storyServiceConsumer.getStory(1);
return Arrays.asList(story, story2);
}
}

@ -1,72 +0,0 @@
package com.gitee.sop.bookweb.controller;
import lombok.Data;
/**
* 默认的结果封装类.
* <pre>
*
* xml返回结果:
* <response>
* <code>50</code>
* <msg>Remote service error</msg>
* <sub_code>isv.invalid-parameter</sub_code>
* <sub_msg>非法参数</sub_msg>
* </response>
* 成功情况
* <response>
* <code>0</code>
* <msg>成功消息</msg>
* <data>
* ...返回内容
* </data>
* </response>
*
* json返回格式
* {
* "code":"50",
* "msg":"Remote service error",
* "sub_code":"isv.invalid-parameter",
* "sub_msg":"非法参数"
* }
* 成功情况
* {
* "code":"0",
* "msg":"成功消息内容。。。",
* "data":{
* ...返回内容
* }
* }
* </pre>
* <p>
* 字段说明
* code:网关异常码 <br>
* msg:网关异常信息 <br>
* sub_code:业务异常码 <br>
* sub_msg:业务异常信息 <br>
*
* @author tanghc
*/
@Data
public class ApiResult {
/**
* 网关异常信息
*/
private String msg;
/**
* 业务异常码
*/
private String sub_msg;
/**
* 业务异常信息
*/
private String sub_code;
/**
* 返回结果
*/
private Object data;
}

@ -1,73 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.gitee.book.api.domain.Book;
import com.gitee.sop.bookweb.consumer.StoryServiceConsumer;
import com.gitee.sop.bookweb.param.BookParam;
import com.gitee.sop.story.api.domain.Story;
import com.gitee.book.api.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
/**
* book服务
*
* @author tanghc
*/
@RestController
public class BookController implements BookService {
@Autowired
StoryServiceConsumer storyServiceConsumer;
@Override
public Book getBook(int id) {
Book book = new Book();
book.setId(id);
book.setName("汪汪队");
return book;
}
@RequestMapping("listBookAndStory")
public Object listBookAndStory(int id) {
Book book = new Book();
book.setId(id);
book.setName("汪汪队");
// 调用story服务
Story story = storyServiceConsumer.getStory(id);
return Arrays.asList(book, story);
}
@RequestMapping("getBook2")
public Object getBookError(int id) {
if (id == 0) {
throw new RuntimeException("id不能为空");
}
Book book = new Book();
book.setId(id);
book.setName("汪汪队");
return Arrays.asList(book);
}
@RequestMapping("getBook3")
public Object getBook3(@RequestBody BookParam param) {
if (param.getId() == 0) {
throw new RuntimeException("id不能为空");
}
Book book = new Book();
book.setId(param.getId());
book.setName("小马宝莉");
ApiResult apiResult = new ApiResult();
apiResult.setData(book);
return apiResult;
}
}

@ -1,40 +0,0 @@
package com.gitee.sop.bookweb.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.story.api.domain.Story;
import com.gitee.sop.story.api.param.DemoParam;
import com.gitee.sop.story.api.result.DemoResult;
import com.gitee.sop.story.api.service.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;
/**
* 调用dubbo服务provider是story见DefaultDemoService.java
* dubbo配置方式参见https://github.com/apache/dubbo-spring-boot-project/blob/0.2.x/README_CN.md
* <p>
* 对比SpringCloud提供的Feigndubbo会方便很多
* <p>
* Feign的使用方式参见com.gitee.sop.bookweb.controller.AlipayBookController#getBook2()
*/
@RestController
@Slf4j
public class DubboConsumerController {
@Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
private DemoService demoService;
// 作为开放接口
@ApiMapping(value = "dubbo.story.get")
public Story openApi(DemoParam demoParam) {
log.info("dubbo consumer, param: {}", demoParam);
// 通过dubbo调用story提供的服务
DemoResult dubboStory = demoService.getStory(demoParam);
Story story = new Story();
story.setId(dubboStory.getId());
story.setName(dubboStory.getName());
return story;
}
}

@ -1,16 +0,0 @@
package com.gitee.sop.bookweb.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author tanghc
*/
@Data
public class BookParam {
@ApiModelProperty(value = "图书id", example = "1")
private int id;
@ApiModelProperty(value = "图书ISBN", example = "xxxx")
private String isbn;
}

@ -1,16 +0,0 @@
package com.gitee.sop.bookweb.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class BookVO {
@ApiModelProperty(value = "图书id", example = "1")
private int id;
@ApiModelProperty(value = "图书名称", example = "白雪公主")
private String name;
@ApiModelProperty(value = "isbn", example = "xxxxxx")
private String isbn;
}

@ -1,19 +0,0 @@
server.port=3333
spring.application.name=book-service
# nacos注册中心
#spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
# eureka注册中心
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
# consumer不需要检查provider是否启动
dubbo.consumer.check=false
# zipkin服务跟踪
#spring.zipkin.base-url=http://127.0.0.1:9411/
## 设置sleuth收集信息的比率,默认0.1,最大是1,数字越大越耗性能
#spring.sleuth.sampler.probability=1
## dubbo使用zipkin过滤器
#dubbo.provider.filter=tracing
#dubbo.consumer.filter=tracing

@ -1,17 +0,0 @@
package com.gitee.sop.bookweb;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SopBookApplicationTests {
@Test
public void contextLoads() {
}
}

@ -1,25 +0,0 @@
target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
/local-config/

@ -1,132 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-easyopen</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>easyopen-server</name>
<description>easyopen Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- sop接入依赖 -->
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
</dependency>
<!-- 使用nacos注册中心
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>0.2.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>1.1.0</version>
</dependency>
-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>net.oschina.durcframework</groupId>
<artifactId>easyopen</artifactId>
<version>1.16.8</version>
</dependency>
<!-- sop接入依赖 end -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- 打包时跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -1,31 +0,0 @@
# easyopen-server
接口服务器空项目,可在此基础上做开发。
入口类:IndexController
业务类在api下,重点关注这里即可。
```
└─com.gitee.easyopen.server
│ EmptySpringbootApplication.java // springboot启动类
│ IndexController.java // easyopen入口类
├─api // 存放接口
│ │ GoodsApi.java // 示例接口
│ │
│ ├─param // 存放接口参数类
│ │ GoodsParam.java
│ │
│ └─result // 存放放回接口类
│ Goods.java
├─config // spring配置
│ CorsConfig.java
├─interceptor // easyopen拦截器
│ LogInterceptor.java
└─message // 错误处理
CommonErrors.java
```

@ -1,25 +0,0 @@
package com.gitee.easyopen.server;
import com.gitee.easyopen.ApiConfig;
import com.gitee.easyopen.support.ApiController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.HashMap;
import java.util.Map;
/**
* 文档地址http://localhost:8080/api/doc
*/
@Controller
@RequestMapping("api")
public class IndexController extends ApiController {
@Override
protected void initApiConfig(ApiConfig apiConfig) {
apiConfig.setShowDoc(true); // 显示文档页面
// 配置国际化消息
Map<String, String> appSecretStore = new HashMap<String, String>();
appSecretStore.put("test", "123456");
apiConfig.addAppSecret(appSecretStore);
}
}

@ -1,14 +0,0 @@
package com.gitee.easyopen.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class SopEasyopenApplication {
public static void main(String[] args) {
SpringApplication.run(SopEasyopenApplication.class, args);
}
}

@ -1,31 +0,0 @@
package com.gitee.easyopen.server.api;
import com.gitee.easyopen.annotation.Api;
import com.gitee.easyopen.annotation.ApiService;
import com.gitee.easyopen.doc.annotation.ApiDoc;
import com.gitee.easyopen.doc.annotation.ApiDocMethod;
import com.gitee.easyopen.server.api.param.GoodsParam;
import com.gitee.easyopen.server.api.result.Goods;
import java.math.BigDecimal;
/**
* 业务类
*
* @author tanghc
*/
@ApiService
@ApiDoc("库存接口")
public class Goods2Api {
@Api(name = "store.get")
@ApiDocMethod(description = "获取库存")
Goods getGoods(GoodsParam param) {
Goods goods = new Goods();
goods.setId(1L);
goods.setGoods_name("苹果iPhoneX");
goods.setPrice(new BigDecimal(8000));
return goods;
}
}

@ -1,31 +0,0 @@
package com.gitee.easyopen.server.api;
import com.gitee.easyopen.annotation.Api;
import com.gitee.easyopen.annotation.ApiService;
import com.gitee.easyopen.doc.annotation.ApiDoc;
import com.gitee.easyopen.doc.annotation.ApiDocMethod;
import com.gitee.easyopen.server.api.param.GoodsParam;
import com.gitee.easyopen.server.api.result.Goods;
import java.math.BigDecimal;
/**
* 业务类
*
* @author tanghc
*/
@ApiService
@ApiDoc("商品接口")
public class GoodsApi {
@Api(name = "easyopen.goods.get")
@ApiDocMethod(description = "获取商品")
Goods getGoods(GoodsParam param) {
Goods goods = new Goods();
goods.setId(1L);
goods.setGoods_name("苹果iPhoneX");
goods.setPrice(new BigDecimal(8000));
return goods;
}
}

@ -1,23 +0,0 @@
package com.gitee.easyopen.server.api.param;
import com.gitee.easyopen.doc.annotation.ApiDocField;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
public class GoodsParam {
@ApiDocField(description = "商品名称", required = true, example = "iphoneX")
@NotEmpty(message = "商品名称不能为空")
@Length(min = 3, max = 20, message = "{goods.name.length}=3,20")
private String goods_name;
public String getGoods_name() {
return goods_name;
}
public void setGoods_name(String goods_name) {
this.goods_name = goods_name;
}
}

@ -1,46 +0,0 @@
package com.gitee.easyopen.server.api.result;
import com.gitee.easyopen.doc.DataType;
import com.gitee.easyopen.doc.annotation.ApiDocField;
import java.math.BigDecimal;
public class Goods {
@ApiDocField(description = "id")
private Long id;
@ApiDocField(description = "商品名称")
private String goods_name;
@ApiDocField(description = "价格", dataType = DataType.FLOAT)
private BigDecimal price;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getGoods_name() {
return goods_name;
}
public void setGoods_name(String goods_name) {
this.goods_name = goods_name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
@Override
public String toString() {
return "Goods [id=" + id + ", goods_name=" + goods_name + ", price=" + price + "]";
}
}

@ -1,37 +0,0 @@
package com.gitee.easyopen.server.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* 解决js跨域
* @author tanghc
*/
@Configuration
public class CorsConfig {
/**
* 跨域过滤器
*
* @return
*/
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", buildConfig()); // 4
return new CorsFilter(source);
}
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
return corsConfiguration;
}
}

@ -1,28 +0,0 @@
package com.gitee.easyopen.server.config;
import com.gitee.sop.servercommon.configuration.EasyopenDocSupportController;
import com.gitee.sop.servercommon.easyopen.EasyopenServiceConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
/**
* @author tanghc
*/
@Configuration
public class SopConfig extends EasyopenServiceConfiguration {
@Controller
public static class SopDocController extends EasyopenDocSupportController {
@Override
public String getDocTitle() {
return "商品API";
}
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//配置映射关系
registry.addResourceHandler("/opendoc/**").addResourceLocations("classpath:/META-INF/resources/opendoc/");
}
}

@ -1,23 +0,0 @@
package com.gitee.easyopen.server.interceptor;
import com.gitee.easyopen.ApiContext;
import com.gitee.easyopen.interceptor.ApiInterceptorAdapter;
import com.gitee.easyopen.util.RequestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLDecoder;
public class LogInterceptor extends ApiInterceptorAdapter {
Logger logger = LoggerFactory.getLogger(getClass());
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object serviceObj, Object argu)
throws Exception {
logger.info("收到客户端请求,ip={},参数={}", RequestUtil.getClientIP(request), URLDecoder.decode(ApiContext.getApiParam().toJSONString(), "UTF-8"));
return true;
}
}

@ -1,16 +0,0 @@
package com.gitee.easyopen.server.message;
import com.gitee.easyopen.message.ErrorMeta;
/**
* 错误码放在这里
*
* 使用方式throw CommonErrors.NUll_ERROR.getException();
*/
public interface CommonErrors {
String isvModule = "isv.error_"; // error_zh_CN2.properties内容前缀
ErrorMeta NUll_ERROR = new ErrorMeta(isvModule, "200", "不能为空");
}

@ -1,7 +0,0 @@
server.port=2121
spring.application.name=easyopen-service
# eureka注册中心
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
easyopen.prefix-path=/api

@ -1,2 +0,0 @@
# common errors here
isv.error_200=\u4E0D\u80FD\u4E3A\u7A7A

@ -1,16 +0,0 @@
package com.gitee.sop.adminserver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SopEasyopenApplicationApplicationTests {
@Test
public void contextLoads() {
}
}

@ -1,12 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-springmvc</artifactId> <artifactId>sop-springmvc</artifactId>
<name>sop-springmvc</name> <name>sop-springmvc</name>
<packaging>war</packaging> <packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties> <properties>
<java-version>1.8</java-version> <java-version>1.8</java-version>
@ -20,7 +26,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version> <version>3.2.0-SNAPSHOT</version>
</dependency> </dependency>
<!-- nacos --> <!-- nacos -->
<dependency> <dependency>
@ -43,6 +49,11 @@
<version>${org.springframework-version}</version> <version>${org.springframework-version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<!-- jackson --> <!-- jackson -->
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>

@ -1,15 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.gitee.sop-story</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-story-parent</artifactId> <artifactId>sop-parent</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging> <relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sop-story</artifactId>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>3.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 使用nacos注册中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- 注册中心end -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 打包时跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<modules>
<module>sop-story-api</module>
<module>sop-story-web</module>
</modules>
</project> </project>

@ -1,25 +0,0 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story-api</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -1,18 +0,0 @@
package com.gitee.sop.story.api.domain;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank;
/**
* @author tanghc
*/
@Data
public class Story {
private int id;
@NotBlank(message = "name不能为空")
@Length(max = 20, message = "name长度不能超过20")
private String name;
}

@ -1,14 +0,0 @@
package com.gitee.sop.story.api.param;
import lombok.Data;
import java.io.Serializable;
/**
* dubbo 参数
* @author tanghc
*/
@Data
public class DemoParam implements Serializable {
private int id;
}

@ -1,15 +0,0 @@
package com.gitee.sop.story.api.result;
import lombok.Data;
import java.io.Serializable;
/**
* dubbo返回结果
* @author tanghc
*/
@Data
public class DemoResult implements Serializable {
private int id;
private String name;
}

@ -1,17 +0,0 @@
package com.gitee.sop.story.api.service;
import com.gitee.sop.story.api.param.DemoParam;
import com.gitee.sop.story.api.result.DemoResult;
public interface DemoService {
String sayHello(String name);
/**
* 获取故事名称
* @param param
* @return
*/
DemoResult getStory(DemoParam param);
}

@ -1,15 +0,0 @@
package com.gitee.sop.story.api.service;
import com.gitee.sop.story.api.domain.Story;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author tanghc
*/
@RequestMapping("/story")
public interface StoryService {
@RequestMapping("/getStory")
Story getStory(@RequestParam("id")/* 必须指定@RequestParam,且value不能少 */
int id);
}

@ -1,25 +0,0 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/

@ -1,146 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sop-story</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<dubbo.version>2.6.5</dubbo.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<!-- nacos spring cloud版本号 -->
<spring-cloud-alibaba-nacos.version>0.9.0.RELEASE</spring-cloud-alibaba-nacos.version>
<!-- nacos客户端版本号 -->
<nacos-client.version>1.1.3</nacos-client.version>
</properties>
<dependencies>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 使用nacos注册中心
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${spring-cloud-alibaba-nacos.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${nacos-client.version}</version>
</dependency>
-->
<!-- 注册中心end -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- Dubbo Spring Boot Starter -->
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>0.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<!-- 打包时跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>

@ -1,23 +0,0 @@
package com.gitee.sop.storyweb.controller;
import com.gitee.sop.story.api.domain.Story;
import com.gitee.sop.story.api.service.StoryService;
import org.springframework.web.bind.annotation.RestController;
/**
* @author tanghc
*/
@RestController
public class StoryController implements StoryService {
// 提供给Feign的服务
@Override
public Story getStory(int id) {
Story story = new Story();
story.setId(id);
story.setName("海底小纵队(Feign)");
return story;
}
}

@ -1,21 +0,0 @@
package com.gitee.sop.storyweb.controller;
import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.story.api.domain.Story;
import org.springframework.web.bind.annotation.RestController;
/**
* @author tanghc
*/
@RestController
public class StoryDemoController {
@ApiMapping(value = "story.demo.get")
public Story getStory() {
Story story = new Story();
story.setId(1);
story.setName("白雪公主");
return story;
}
}

@ -1,32 +0,0 @@
package com.gitee.sop.storyweb.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.gitee.sop.story.api.param.DemoParam;
import com.gitee.sop.story.api.result.DemoResult;
import com.gitee.sop.story.api.service.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@Service(version = "1.0.0")
@Slf4j
public class DefaultDemoService implements DemoService {
/**
* The default value of ${dubbo.application.name} is ${spring.application.name}
*/
@Value("${dubbo.application.name}")
private String serviceName;
public String sayHello(String name) {
return String.format("[%s] : Hello, %s", serviceName, name);
}
@Override
public DemoResult getStory(DemoParam param) {
log.info("dubbo provider, param: {}", param);
DemoResult demoResult = new DemoResult();
demoResult.setId(param.getId());
demoResult.setName("dubbo 白雪公主, param=" + param);
return demoResult;
}
}

@ -6,7 +6,6 @@ import com.gitee.sop.servercommon.annotation.ApiAbility;
import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.servercommon.bean.OpenContext; import com.gitee.sop.servercommon.bean.OpenContext;
import com.gitee.sop.servercommon.bean.ServiceContext; import com.gitee.sop.servercommon.bean.ServiceContext;
import com.gitee.sop.story.api.domain.Story;
import com.gitee.sop.storyweb.controller.param.CategoryParam; import com.gitee.sop.storyweb.controller.param.CategoryParam;
import com.gitee.sop.storyweb.controller.param.StoryParam; import com.gitee.sop.storyweb.controller.param.StoryParam;
import com.gitee.sop.storyweb.controller.result.CategoryResult; import com.gitee.sop.storyweb.controller.result.CategoryResult;
@ -291,17 +290,6 @@ public class AlipayController {
return new TreeResult(); return new TreeResult();
} }
// 测试参数绑定,http://localhost:2222/story/getStory4?biz_content=%7b%22id%22%3a1%2c%22name%22%3a%22aaaa%22%7d
@ApiAbility
@GetMapping("getStory4")
public StoryResult getStory4(Story param, P p2) {
System.out.println(param + ", p2=" + p2);
StoryResult result = new StoryResult();
result.setId(1L);
result.setName("海底小纵队(默认版本号)" + param + ", p2=" + p2);
return result;
}
@Data @Data
public static class P { public static class P {
private String name; private String name;

@ -1,7 +1,6 @@
package com.gitee.sop.storyweb.controller; package com.gitee.sop.storyweb.controller;
import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.story.api.domain.Story;
import com.gitee.sop.storyweb.controller.result.StoryResult; import com.gitee.sop.storyweb.controller.result.StoryResult;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;

@ -1,9 +1,8 @@
package com.gitee.sop.storyweb.controller; package com.gitee.sop.storyweb.controller;
import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.servercommon.annotation.ApiMapping;
import com.gitee.sop.servercommon.bean.ServiceContext;
import com.gitee.sop.servercommon.bean.OpenContext; import com.gitee.sop.servercommon.bean.OpenContext;
import com.gitee.sop.story.api.domain.Story; import com.gitee.sop.servercommon.bean.ServiceContext;
import com.gitee.sop.storyweb.controller.param.StoryParam; import com.gitee.sop.storyweb.controller.param.StoryParam;
import com.gitee.sop.storyweb.controller.result.StoryResult; import com.gitee.sop.storyweb.controller.result.StoryResult;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -39,25 +38,4 @@ public class PostJsonController {
return result; return result;
} }
/**
* 演示客户端使用json方式请求application/json
* @param param
* @return
*/
@ApiMapping(value = "demo.post.json", version = "1.2")
public Story postJson2(StoryParam param) {
// 获取开放平台请求参数
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
List<Object> params = Arrays.asList(
openContext.getAppId(),
openContext.getMethod(),
openContext.getVersion()
);
Story story = new Story();
story.setId(1);
story.setName("1.2 参数:" + param.getName() + ", openParams:" + StringUtils.join(params));
return story;
}
} }

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save