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

@ -1,5 +1,11 @@
# 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)
## 3.1.5
修复文件上传大小不一致问题

@ -2,6 +2,12 @@
<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.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-admin-server</artifactId>
<version>1.0.0-SNAPSHOT</version>
@ -10,32 +16,51 @@
<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>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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>
<!-- 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>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${nacos-spring-boot-starter.version}</version>
<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.boot</groupId>
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
<version>${nacos-spring-boot-starter.version}</version>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- easyopen starter -->

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

@ -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"
>
<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">
<el-button type="text" size="mini" @click="onGrayConfigUpdate(scope.row)">设置灰度参数</el-button>
</div>
@ -204,6 +204,7 @@ export default {
searchFormData: {
serviceId: ''
},
blackList: ['sop-gateway', 'sop-admin'],
grayDialogVisible: false,
grayForm: {
serviceId: '',

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
@ -16,39 +16,57 @@
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<!-- 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>
<oltu.version>0.31</oltu.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>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- sop相关配置 -->
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</dependency>
<!-- sop相关配置 end-->
<!-- 使用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
-->
<!-- 使用nacos注册中心 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.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>
@ -117,18 +135,6 @@
</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>

@ -5,16 +5,26 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<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>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<spring-boot.version>2.1.2.RELEASE</spring-boot.version>
<!-- 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.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>
@ -58,24 +68,12 @@
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-discovery</artifactId>
<version>${spring-cloud-alibaba-nacos.version}</version>
<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>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>
@ -93,6 +91,11 @@
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>
<!-- commons -->
<dependency>
@ -110,35 +113,29 @@
<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>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</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>
</dependencyManagement>
<repositories>
<repository>

@ -5,11 +5,11 @@
<parent>
<artifactId>sop-common</artifactId>
<groupId>com.gitee.sop</groupId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<artifactId>sop-bridge-gateway</artifactId>
@ -17,7 +17,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</dependency>
<dependency>

@ -5,11 +5,11 @@
<parent>
<artifactId>sop-common</artifactId>
<groupId>com.gitee.sop</groupId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<artifactId>sop-bridge-zuul</artifactId>
@ -17,7 +17,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</dependency>
<dependency>

@ -5,11 +5,11 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sop-gateway-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sop-gateway-common</name>
@ -26,6 +26,10 @@
<version>27.1-jre</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
@ -36,22 +40,20 @@
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-ribbon</artifactId>
<scope>compile</scope>
</dependency>
<!-- optional -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-discovery</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<optional>true</optional>
</dependency>
@ -74,22 +76,34 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<version>2.1.0.RELEASE</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon-eureka</artifactId>
<version>2.3.0</version>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<optional>true</optional>
</dependency>
<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</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>

@ -1,6 +1,7 @@
package com.gitee.sop.gatewaycommon.bean;
import lombok.Data;
import org.springframework.cloud.gateway.route.Route;
import java.util.ArrayList;
import java.util.Collections;
@ -80,4 +81,6 @@ public class RouteDefinition {
* 是否是兼容模式即使用了@ApiAbility注解
*/
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.GlobalFilter;
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.CachedBodyOutputMessage;
import org.springframework.cloud.gateway.support.DefaultClientResponse;
import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;

@ -13,8 +13,8 @@ import com.gitee.sop.gatewaycommon.validate.Validator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.CachedBodyOutputMessage;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBuffer;

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

@ -42,10 +42,13 @@ public class GatewayRouteRepository implements RouteRepository<GatewayTargetRout
@Autowired
private ApplicationContext applicationContext;
private RouteLocator routeLocator;
private volatile RouteLocator routeLocator;
@Override
public Flux<Route> getRoutes() {
if (routeLocator == null) {
return Flux.empty();
}
return routeLocator.getRoutes();
}
@ -59,6 +62,7 @@ public class GatewayRouteRepository implements RouteRepository<GatewayTargetRout
r -> r.path(routeDefinition.getPath())
.uri(routeDefinition.getUri())));
this.routeLocator = builder.build();
// 触发
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 {
EXCLUDE_SERVICE_ID_LIST.add("sop-gateway");
EXCLUDE_SERVICE_ID_LIST.add("sop-website");
EXCLUDE_SERVICE_ID_LIST.add("sop-admin");
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.discovery.shared.Application;
import com.netflix.discovery.shared.Applications;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.cloud.netflix.eureka.CloudEurekaClient;
import org.springframework.context.ApplicationEvent;
@ -46,6 +44,7 @@ public class EurekaRegistryListener extends BaseRegistryListener {
.collect(Collectors.toList());
final Set<ServiceHolder> currentServices = new HashSet<>(serviceList);
// 删除现有的,剩下的就是新服务
currentServices.removeAll(cacheServices);
// 如果有新的服务注册进来
if (currentServices.size() > 0) {
@ -115,10 +114,4 @@ public class EurekaRegistryListener extends BaseRegistryListener {
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;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
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.alibaba.nacos.api.naming.pojo.ListView;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
import org.springframework.context.ApplicationEvent;
import org.springframework.util.CollectionUtils;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 加载服务路由nacos实现
@ -24,35 +28,57 @@ import java.util.Objects;
@Slf4j
public class NacosRegistryListener extends BaseRegistryListener {
private volatile Set<String> cacheServices = new HashSet<>();
@Autowired
private NacosDiscoveryProperties nacosDiscoveryProperties;
@NacosInjected
private ConfigService configService;
@Override
public void onEvent(ApplicationEvent applicationEvent) {
public synchronized void onEvent(ApplicationEvent applicationEvent) {
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
List<ServiceInfo> subscribes = null;
ListView<String> servicesOfServer = null;
try {
subscribes = namingService.getSubscribeServices();
servicesOfServer = namingService.getServicesOfServer(1, Integer.MAX_VALUE);
} 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;
}
subscribes.stream()
.filter(serviceInfo -> this.canOperator(serviceInfo.getName()))
.forEach(serviceInfo -> {
String serviceName = serviceInfo.getName();
Map<String, Instance> instanceMap = servicesOfServer
.getData()
.stream()
.filter(this::canOperator)
.map(serviceName -> {
try {
List<Instance> allInstances = namingService.getAllInstances(serviceName);
if (CollectionUtils.isEmpty(allInstances)) {
// 如果没有服务列表,则删除所有路由信息
removeRoutes(serviceName);
} else {
for (Instance instance : allInstances) {
return null;
}
Instance instance = allInstances.stream()
.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.setInstanceId(instance.getInstanceId());
instanceDefinition.setServiceId(serviceName);
@ -60,12 +86,37 @@ public class NacosRegistryListener extends BaseRegistryListener {
instanceDefinition.setPort(instance.getPort());
instanceDefinition.setMetadata(instance.getMetadata());
pullRoutes(instanceDefinition);
});
}
// 如果有服务删除
Set<String> removedServiceIdList = getRemovedServiceId(serviceNames);
if (removedServiceIdList.size() > 0) {
removedServiceIdList.forEach(this::removeRoutes);
}
} catch (Exception e) {
log.error("选择服务实例失败,serviceName: {}", serviceName, e);
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,11 @@
package com.gitee.sop.gatewaycommon.route;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class ServiceHolder {
private String serviceId;
private long lastUpdatedTimestamp;
}

@ -6,11 +6,11 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sop-service-common</name>
@ -28,6 +28,16 @@
<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>
<!-- optional -->
<dependency>
<groupId>org.springframework</groupId>
@ -76,6 +86,17 @@
<version>3.0.0</version>
<scope>test</scope>
</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>

@ -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);
}
}

@ -10,8 +10,6 @@
<modules>
<module>sop-story</module>
<module>sop-book</module>
<module>sop-easyopen</module>
<module>sop-springmvc</module>
</modules>
</project>

@ -1,7 +1,5 @@
# 服务示例
- sop-story:微服务示例,story服务,同时作为Provider提供服务。本地文档:http://localhost:2222/doc.html
- sop-book:微服务示例,book服务,也是Consumer,调用story提供的服务
- sop-story:微服务示例
- sop-auth:应用授权示例
- 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,147 +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-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,16 +0,0 @@
server.port=3333
spring.application.name=book-service
# nacos注册中心
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
# 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,126 +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>net.oschina.durcframework</groupId>
<artifactId>easyopen</artifactId>
<version>1.16.1</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
# nacos注册中心
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
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() {
}
}

@ -20,7 +20,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
</dependency>
<!-- nacos -->
<dependency>

@ -1,15 +1,129 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop-story</groupId>
<artifactId>sop-story-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>sop-story-api</module>
<module>sop-story-web</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-story</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>
<!-- 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>
</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>
</dependencies>
</dependencyManagement>
<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>
</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,140 +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-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.bean.OpenContext;
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.StoryParam;
import com.gitee.sop.storyweb.controller.result.CategoryResult;
@ -291,17 +290,6 @@ public class AlipayController {
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
public static class P {
private String name;

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

@ -1,9 +1,8 @@
package com.gitee.sop.storyweb.controller;
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.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.result.StoryResult;
import org.apache.commons.lang3.StringUtils;
@ -39,25 +38,4 @@ public class PostJsonController {
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