alicode,sonar

1.x
tanghc 6 years ago
parent 340598ee66
commit 42c4e4784b
  1. 3
      pom.xml
  2. 17
      sop-admin/sop-admin-front/pages/service/serviceList.js
  3. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/ServiceInfoVo.java
  4. 188
      sop-common/pom.xml
  5. 5
      sop-common/readme.md
  6. 0
      sop-common/sop-gateway-common/.gitignore
  7. 62
      sop-common/sop-gateway-common/pom.xml
  8. 0
      sop-common/sop-gateway-common/readme.md
  9. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/AbstractTargetRoute.java
  10. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiConfig.java
  11. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ApiContext.java
  12. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/BaseRouteDefinition.java
  13. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/BaseServiceRouteInfo.java
  14. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/RouteStatus.java
  15. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java
  16. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/TargetRoute.java
  17. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/easyopen/EasyopenResultExecutor.java
  18. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/easyopen/EasyopenSigner.java
  19. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/easyopen/EasyopenZuulConfiguration.java
  20. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/exception/ApiException.java
  21. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/GatewayContext.java
  22. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/AlipayGatewayConfiguration.java
  23. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/BaseGatewayConfiguration.java
  24. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/configuration/TaobaoGatewayConfiguration.java
  25. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java
  26. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LoadBalancerClientExtFilter.java
  27. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/ValidateFilter.java
  28. 16
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java
  29. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/param/GatewayParamBuilder.java
  30. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/result/GatewayResult.java
  31. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/result/GatewayResultExecutor.java
  32. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayFilterDefinition.java
  33. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayPredicateDefinition.java
  34. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteDefinition.java
  35. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java
  36. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayServiceRouteInfo.java
  37. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayTargetRoute.java
  38. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayZookeeperRouteManager.java
  39. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/NameVersionRoutePredicateFactory.java
  40. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/ReadBodyRoutePredicateFactory.java
  41. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/BaseRouteManager.java
  42. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteManager.java
  43. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteRepository.java
  44. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/RouteRepositoryContext.java
  45. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/Error.java
  46. 118
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorEnum.java
  47. 8
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorFactory.java
  48. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java
  49. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorMeta.java
  50. 30
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ApiParam.java
  51. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ApiParamFactory.java
  52. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ApiUploadContext.java
  53. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/Param.java
  54. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamBuilder.java
  55. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java
  56. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/UploadContext.java
  57. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ApiResult.java
  58. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java
  59. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/Result.java
  60. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/ResultExecutor.java
  61. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/secret/AppSecretManager.java
  62. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/secret/CacheAppSecretManager.java
  63. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/secret/FileAppSecretManager.java
  64. 42
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/ApiHttpSession.java
  65. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/ApiRedisTemplate.java
  66. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/ApiSessionManager.java
  67. 9
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/RedisHttpSession.java
  68. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/RedisSessionManager.java
  69. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/session/SessionManager.java
  70. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/AESUtil.java
  71. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/KeyStore.java
  72. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RSANewUtil.java
  73. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RSAUtil.java
  74. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RedisLockUtil.java
  75. 9
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RequestUtil.java
  76. 19
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/ResponseUtil.java
  77. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RouteUtil.java
  78. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/AbstractSigner.java
  79. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/ApiEncrypter.java
  80. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/ApiSigner.java
  81. 55
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/ApiValidator.java
  82. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/Encrypter.java
  83. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/SignEncipher.java
  84. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/SignEncipherHMAC_MD5.java
  85. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/SignEncipherMD5.java
  86. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/Signer.java
  87. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/Validator.java
  88. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/AlipayConstants.java
  89. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/AlipaySignature.java
  90. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/AlipaySigner.java
  91. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StreamUtil.java
  92. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/alipay/StringUtils.java
  93. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/validate/taobao/TaobaoSigner.java
  94. 24
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/ZuulContext.java
  95. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/AlipayZuulConfiguration.java
  96. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.java
  97. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/TaobaoZuulConfiguration.java
  98. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/ZuulErrorController.java
  99. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/filter/BaseZuulFilter.java
  100. 0
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/filter/ErrorFilter.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -9,11 +9,10 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>sop-common</module>
<module>sop-admin</module> <module>sop-admin</module>
<module>sop-registry</module> <module>sop-registry</module>
<module>sop-gateway</module> <module>sop-gateway</module>
<module>sop-gateway-common</module>
<module>sop-service-common</module>
<module>sop-story</module> <module>sop-story</module>
<module>sop-book</module> <module>sop-book</module>
<module>sop-test</module> <module>sop-test</module>

@ -23,13 +23,24 @@ lib.config({
page: false, page: false,
cols: [[ cols: [[
{type: 'numbers'}, {type: 'numbers'},
{field: 'name', title: '服务名称', width: 200}, {field: 'name', title: '服务名称(serviceId)', width: 200},
{field: 'instanceId', title: 'instanceId', width: 220}, {field: 'instanceId', title: 'instanceId', width: 220},
{field: 'ipAddr', title: 'IP地址', width: 150}, {field: 'ipAddr', title: 'IP地址', width: 150},
{field: 'serverPort', title: '端口号', width: 100}, {field: 'serverPort', title: '端口号', width: 100},
{field: 'status', title: 'status', width: 100}, {field: 'status', title: '服务状态', width: 100, templet: function (row) {
if (row.parentId > 0) {
var html = [];
if (row.status === 'UP') {
return '<span class="x-green">已上线</span>'
}
if (row.status === 'OUT_OF_SERVICE') {
return '<span class="x-red">已下线</span>'
}
}
return '';
}},
{field: 'updateTime', title: '最后更新时间', width: 150}, {field: 'updateTime', title: '最后更新时间', width: 150},
{fixed: 'right', title: '操作', width: 200, templet: function (row) { {fixed: 'right', title: '操作', width: 150, templet: function (row) {
if (row.parentId > 0) { if (row.parentId > 0) {
var html = []; var html = [];
if (row.status === 'UP') { if (row.status === 'UP') {

@ -27,7 +27,7 @@ public class ServiceInfoVo {
@ApiDocField(description = "端口") @ApiDocField(description = "端口")
private String serverPort; private String serverPort;
@ApiDocField(description = "status") @ApiDocField(description = "status,服务状态,UP:已上线,OUT_OF_SERVICE:已下线")
private String status; private String status;
@ApiDocField(description = "statusPageUrl") @ApiDocField(description = "statusPageUrl")

@ -0,0 +1,188 @@
<?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-common</artifactId>
<version>1.0.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>
<!-- Logging -->
<logback.version>1.0.13</logback.version>
<slf4j.version>1.7.5</slf4j.version>
<!-- Test -->
<junit.version>4.11</junit.version>
<fastjson.version>1.2.15</fastjson.version>
<commons-io.version>2.5</commons-io.version>
<commons-fileupload.version>1.3.3</commons-fileupload.version>
<commons-collection.version>3.2.2</commons-collection.version>
<commons-lang3.version>3.8.1</commons-lang3.version>
<commons-codec.version>1.11</commons-codec.version>
<zookeeper.version>3.4.12</zookeeper.version>
</properties>
<modules>
<module>sop-gateway-common</module>
<module>sop-service-common</module>
</modules>
<dependencyManagement>
<dependencies>
<!-- 加了这个就不需要加版本号了 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- zookeeper -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-all</artifactId>
<exclusions>
<!-- 不使用服务发现 -->
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</exclusion>
<!-- 这里为什么要排除,详见:http://curator.apache.org/zk-compatibility.html -->
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons-collection.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<!-- optional -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.1.4.RELEASE</version>
<optional>true</optional>
</dependency>
<!-- 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>
<build>
<plugins>
<!-- 打包时跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<!-- JDK8必须使用下面的配置 -->
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,5 @@
# sop-common
- 打包成jar:`mvn clean package`
- 上传到本机仓库:`mvn clean install`
- 上传到maven私服:`mvn clean deploy`

@ -0,0 +1,62 @@
<?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>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>${parent.version}</version>
<packaging>jar</packaging>
<name>sop-gateway-common</name>
<description>sop-gateway-common</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</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-starter-netflix-zuul</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>

@ -90,7 +90,7 @@ public class ApiConfig {
/** /**
* 错误模块 * 错误模块
*/ */
private List<String> i18nModules = new ArrayList<String>(); private List<String> i18nModules = new ArrayList<>();
// -------- fields --------- // -------- fields ---------

@ -7,6 +7,8 @@ import java.nio.charset.StandardCharsets;
* @author tanghc * @author tanghc
*/ */
public class SopConstants { public class SopConstants {
private SopConstants() {}
public static final Charset CHARSET_UTF8 = StandardCharsets.UTF_8; public static final Charset CHARSET_UTF8 = StandardCharsets.UTF_8;
public static final String FORMAT_JSON = "json"; public static final String FORMAT_JSON = "json";
@ -35,4 +37,5 @@ public class SopConstants {
* zookeeper存放接口路由信息的根目录 * zookeeper存放接口路由信息的根目录
*/ */
public static final String SOP_SERVICE_ROUTE_PATH = "/com.gitee.sop.route"; public static final String SOP_SERVICE_ROUTE_PATH = "/com.gitee.sop.route";
} }

@ -2,7 +2,6 @@ package com.gitee.sop.gatewaycommon.easyopen;
import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.validate.AbstractSigner; import com.gitee.sop.gatewaycommon.validate.AbstractSigner;
import com.gitee.sop.gatewaycommon.validate.taobao.TaobaoSigner;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import java.util.ArrayList; import java.util.ArrayList;
@ -17,7 +16,7 @@ public class EasyopenSigner extends AbstractSigner {
@Override @Override
protected String buildServerSign(ApiParam params, String secret) { protected String buildServerSign(ApiParam params, String secret) {
Set<String> keySet = params.keySet(); Set<String> keySet = params.keySet();
List<String> paramNames = new ArrayList<String>(keySet); List<String> paramNames = new ArrayList<>(keySet);
Collections.sort(paramNames); Collections.sort(paramNames);

@ -2,9 +2,7 @@ package com.gitee.sop.gatewaycommon.easyopen;
import com.gitee.sop.gatewaycommon.bean.ApiConfig; import com.gitee.sop.gatewaycommon.bean.ApiConfig;
import com.gitee.sop.gatewaycommon.bean.ApiContext; import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.gateway.configuration.BaseGatewayConfiguration;
import com.gitee.sop.gatewaycommon.param.ParamNames; import com.gitee.sop.gatewaycommon.param.ParamNames;
import com.gitee.sop.gatewaycommon.validate.taobao.TaobaoSigner;
import com.gitee.sop.gatewaycommon.zuul.configuration.BaseZuulConfiguration; import com.gitee.sop.gatewaycommon.zuul.configuration.BaseZuulConfiguration;
/** /**

@ -8,7 +8,7 @@ import com.gitee.sop.gatewaycommon.message.Error;
*/ */
public class ApiException extends RuntimeException { public class ApiException extends RuntimeException {
private Error error; private transient final Error error;
public ApiException(Throwable cause, Error error) { public ApiException(Throwable cause, Error error) {
super(cause); super(cause);

@ -24,6 +24,7 @@ import java.util.List;
/** /**
* 统一异常处理 * 统一异常处理
*
* @author thc * @author thc
*/ */
public class GatewayExceptionHandler implements ErrorWebExceptionHandler { public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
@ -46,9 +47,10 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
if (exchange.getResponse().isCommitted()) { if (exchange.getResponse().isCommitted()) {
return Mono.error(ex); return Mono.error(ex);
} }
exceptionHandlerResult.set(errorResult);
ServerRequest newRequest = ServerRequest.create(exchange, this.messageReaders); ServerRequest newRequest = ServerRequest.create(exchange, this.messageReaders);
return RouterFunctions.route(RequestPredicates.all(), this::renderErrorResponse).route(newRequest) return RouterFunctions.route(RequestPredicates.all(), (serverRequest) -> {
return this.renderErrorResponse(errorResult);
}).route(newRequest)
.switchIfEmpty(Mono.error(ex)) .switchIfEmpty(Mono.error(ex))
.flatMap((handler) -> handler.handle(newRequest)) .flatMap((handler) -> handler.handle(newRequest))
.flatMap((response) -> write(exchange, response)); .flatMap((response) -> write(exchange, response));
@ -70,11 +72,6 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
*/ */
private List<ViewResolver> viewResolvers = Collections.emptyList(); private List<ViewResolver> viewResolvers = Collections.emptyList();
/**
* 存储处理异常后的信息
*/
private ThreadLocal<GatewayResult> exceptionHandlerResult = new ThreadLocal<>();
/** /**
* 参考AbstractErrorWebExceptionHandler * 参考AbstractErrorWebExceptionHandler
* *
@ -108,11 +105,10 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
/** /**
* 参考DefaultErrorWebExceptionHandler * 参考DefaultErrorWebExceptionHandler
* *
* @param request * @param result
* @return * @return
*/ */
protected Mono<ServerResponse> renderErrorResponse(ServerRequest request) { protected Mono<ServerResponse> renderErrorResponse(GatewayResult result) {
GatewayResult result = exceptionHandlerResult.get();
return ServerResponse return ServerResponse
.status(result.getHttpStatus()) .status(result.getHttpStatus())
.contentType(result.getContentType()) .contentType(result.getContentType())

@ -2,6 +2,8 @@ package com.gitee.sop.gatewaycommon.gateway.route;
import org.springframework.cloud.gateway.handler.predicate.ReadBodyPredicateFactory; import org.springframework.cloud.gateway.handler.predicate.ReadBodyPredicateFactory;
import java.util.Objects;
/** /**
* 获取form表单插件使用方式 * 获取form表单插件使用方式
* @Bean * @Bean
@ -17,9 +19,7 @@ public class ReadBodyRoutePredicateFactory extends ReadBodyPredicateFactory {
public Config newConfig() { public Config newConfig() {
Config config = super.newConfig(); Config config = super.newConfig();
config.setInClass(String.class); config.setInClass(String.class);
config.setPredicate(body -> { config.setPredicate(Objects::nonNull);
return body != null;
});
return config; return config;
} }
} }

@ -6,6 +6,9 @@ import com.gitee.sop.gatewaycommon.bean.TargetRoute;
* @author tanghc * @author tanghc
*/ */
public class RouteRepositoryContext { public class RouteRepositoryContext {
private RouteRepositoryContext(){}
private static RouteRepository<? extends TargetRoute> routeRepository; private static RouteRepository<? extends TargetRoute> routeRepository;
public static RouteRepository<? extends TargetRoute> getRouteRepository() { public static RouteRepository<? extends TargetRoute> getRouteRepository() {

@ -0,0 +1,118 @@
package com.gitee.sop.gatewaycommon.message;
/**
* 网关错误定义
* @author tanghc
*/
public enum ErrorEnum {
/** 成功 */
SUCCESS(Codes.CODE_SUCCESS, ""),
/** 服务暂不可用 */
ISP_UNKNOW_ERROR(Codes.CODE_UNKNOW, "isp.unknow-error"),
/** */
AOP_UNKNOW_ERROR(Codes.CODE_UNKNOW, "aop.unknow-error"),
/** 无效的访问令牌 */
AOP_INVALID_AUTH_TOKEN(Codes.CODE_AUTH, "aop.invalid-auth-token"),
/** 访问令牌已过期 */
AOP_AUTH_TOKEN_TIME_OUT(Codes.CODE_AUTH, "aop.auth-token-time-out"),
/** 无效的应用授权令牌 */
AOP_INVALID_APP_AUTH_TOKEN(Codes.CODE_AUTH, "aop.invalid-app-auth-token"),
/** 商户未授权当前接口 */
AOP_INVALID_APP_AUTH_TOKEN_NO_API(Codes.CODE_AUTH, "aop.invalid-app-auth-token-no-api"),
/** 应用授权令牌已过期 */
AOP_APP_AUTH_TOKEN_TIME_OUT(Codes.CODE_AUTH, "aop.app-auth-token-time-out"),
/** 商户未签约任何产品 */
AOP_NO_PRODUCT_REG_BY_PARTNER(Codes.CODE_AUTH, "aop.no-product-reg-by-partner"),
/** 缺少方法名参数 */
ISV_MISSING_METHOD(Codes.CODE_MISSING, "isv.missing-method"),
/** 缺少签名参数 */
ISV_MISSING_SIGNATURE(Codes.CODE_MISSING, "isv.missing-signature"),
/** 缺少签名类型参数 */
ISV_MISSING_SIGNATURE_TYPE(Codes.CODE_MISSING, "isv.missing-signature-type"),
/** 缺少签名配置 */
ISV_MISSING_SIGNATURE_KEY(Codes.CODE_MISSING, "isv.missing-signature-key"),
/** 缺少appId参数 */
ISV_MISSING_APP_ID(Codes.CODE_MISSING, "isv.missing-app-id"),
/** 缺少时间戳参数 */
ISV_MISSING_TIMESTAMP(Codes.CODE_MISSING, "isv.missing-timestamp"),
/** 缺少版本参数 */
ISV_MISSING_VERSION(Codes.CODE_MISSING, "isv.missing-version"),
/** 解密出错, 未指定加密算法 */
ISV_DECRYPTION_ERROR_MISSING_ENCRYPT_TYPE(Codes.CODE_MISSING, "isv.decryption-error-missing-encrypt-type"),
/** 参数无效 */
ISV_INVALID_PARAMETER(Codes.CODE_INVALID, "isv.invalid-parameter"),
/** 文件上传失败 */
ISV_UPLOAD_FAIL(Codes.CODE_INVALID, "isv.upload-fail"),
/** 文件扩展名无效 */
ISV_INVALID_FILE_EXTENSION(Codes.CODE_INVALID, "isv.invalid-file-extension"),
/** 文件大小无效 */
ISV_INVALID_FILE_SIZE(Codes.CODE_INVALID, "isv.invalid-file-size"),
/** 不存在的方法名 */
ISV_INVALID_METHOD(Codes.CODE_INVALID, "isv.invalid-method"),
/** 无效的数据格式 */
ISV_INVALID_FORMAT(Codes.CODE_INVALID, "isv.invalid-format"),
/** 无效的签名类型 */
ISV_INVALID_SIGNATURE_TYPE(Codes.CODE_INVALID, "isv.invalid-signature-type"),
/** 无效签名 */
ISV_INVALID_SIGNATURE(Codes.CODE_INVALID, "isv.invalid-signature"),
/** 无效的加密类型 */
ISV_INVALID_ENCRYPT_TYPE(Codes.CODE_INVALID, "isv.invalid-encrypt-type"),
/** 解密异常 */
ISV_INVALID_ENCRYPT(Codes.CODE_INVALID, "isv.invalid-encrypt"),
/** 无效的appId参数 */
ISV_INVALID_APP_ID(Codes.CODE_INVALID, "isv.invalid-app-id"),
/** 非法的时间戳参数 */
ISV_INVALID_TIMESTAMP(Codes.CODE_INVALID, "isv.invalid-timestamp"),
/** 字符集错误 */
ISV_INVALID_CHARSET(Codes.CODE_INVALID, "isv.invalid-charset"),
/** 摘要错误 */
ISV_INVALID_DIGEST(Codes.CODE_INVALID, "isv.invalid-digest"),
/** 解密出错,不支持的加密算法 */
ISV_DECRYPTION_ERROR_NOT_VALID_ENCRYPT_TYPE(Codes.CODE_INVALID, "isv.decryption-error-not-valid-encrypt-type"),
/** 解密出错, 未配置加密密钥或加密密钥格式错误 */
ISV_DECRYPTION_ERROR_NOT_VALID_ENCRYPT_KEY(Codes.CODE_INVALID, "isv.decryption-error-not-valid-encrypt-key"),
/** 解密出错,未知异常 */
ISV_DECRYPTION_ERROR_UNKNOWN(Codes.CODE_INVALID, "isv.decryption-error-unknown"),
/** 验签出错, 未配置对应签名算法的公钥或者证书 */
ISV_MISSING_SIGNATURE_CONFIG(Codes.CODE_INVALID, "isv.missing-signature-config"),
/** 本接口不支持第三方代理调用 */
ISV_NOT_SUPPORT_APP_AUTH(Codes.CODE_INVALID, "isv.not-support-app-auth"),
/** 可疑的攻击请求 */
ISV_SUSPECTED_ATTACK(Codes.CODE_INVALID, "isv.suspected-attack"),
/** 无效的content-type */
ISV_INVALID_CONTENT_TYPE(Codes.CODE_INVALID, "isv.invalid-content-type"),
/** 业务处理失败 */
BIZ_ERROR(Codes.CODE_BIZ, ""),
/** 请检查配置的账户是否有当前接口权限 */
ISV_INSUFFICIENT_ISV_PERMISSIONS(Codes.CODE_ISV_PERM, "isv.insufficient-isv-permissions"),
/** 代理的商户没有当前接口权限 */
ISV_INSUFFICIENT_USER_PERMISSIONS(Codes.CODE_ISV_PERM, "isv.insufficient-user-permissions"),
;
private ErrorMeta errorMeta;
ErrorEnum(String code, String subCode) {
this.errorMeta = new ErrorMeta("open.error_", code, subCode);
}
public ErrorMeta getErrorMeta() {
return errorMeta;
}
private static class Codes {
public static final String CODE_SUCCESS = "10000";
public static final String CODE_AUTH = "20001";
public static final String CODE_MISSING = "40001";
public static final String CODE_INVALID = "40002";
public static final String CODE_BIZ = "40004";
public static final String CODE_ISV_PERM = "40006";
public static final String CODE_UNKNOW = "20000";
}
}

@ -22,12 +22,14 @@ import java.util.Set;
@Slf4j @Slf4j
public class ErrorFactory { public class ErrorFactory {
private ErrorFactory(){}
public static final String SYS_ERR = "系统错误"; public static final String SYS_ERR = "系统错误";
private static final String I18N_OPEN_ERROR = "i18n/open/error"; private static final String I18N_OPEN_ERROR = "i18n/open/error";
public static final String UNDERLINE = "_"; public static final String UNDERLINE = "_";
private static Set<String> noModuleCache = new HashSet<String>(); private static Set<String> noModuleCache = new HashSet<>();
private static Map<String, Error> errorCache = new HashMap<>(64); private static Map<String, Error> errorCache = new HashMap<>(64);
@ -40,7 +42,7 @@ public class ErrorFactory {
* 设置国际化资源信息 * 设置国际化资源信息
*/ */
public static void initMessageSource(List<String> isvModules) { public static void initMessageSource(List<String> isvModules) {
HashSet<String> baseNamesSet = new HashSet<String>(); HashSet<String> baseNamesSet = new HashSet<>();
baseNamesSet.add(I18N_OPEN_ERROR); baseNamesSet.add(I18N_OPEN_ERROR);
if (!isvModules.isEmpty()) { if (!isvModules.isEmpty()) {
@ -84,7 +86,7 @@ public class ErrorFactory {
} }
// solution暂未实现,如果要实现,可以这样配置: // solution暂未实现,如果要实现,可以这样配置:
// open.error_20000_isp.unknow-error_solution=Service is temporarily unavailable // open.error_20000_isp.unknow-error_solution=Service is temporarily unavailable
// String solution = getErrorMessage(modulePrefix + code + UNDERLINE + subCode + "_solution", locale, params); // <code>String solution = getErrorMessage(modulePrefix + code + UNDERLINE + subCode + "_solution", locale, params);</code>
error = new ErrorImpl(code, msg, subCode, subMsg, null); error = new ErrorImpl(code, msg, subCode, subMsg, null);
errorCache.put(key, error); errorCache.put(key, error);
} }

@ -1,10 +1,8 @@
package com.gitee.sop.gatewaycommon.message; package com.gitee.sop.gatewaycommon.message;
import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.exception.ApiException; import com.gitee.sop.gatewaycommon.exception.ApiException;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import lombok.Getter; import lombok.Getter;
import sun.plugin.cache.CacheUpdateHelper;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Locale; import java.util.Locale;

@ -2,11 +2,8 @@ package com.gitee.sop.gatewaycommon.param;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.gitee.sop.gatewaycommon.bean.SopConstants; import com.gitee.sop.gatewaycommon.bean.SopConstants;
//import com.netflix.zuul.context.RequestContext;
//import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.Map; import java.util.Map;
/** /**
@ -29,6 +26,8 @@ public class ApiParam extends JSONObject implements Param {
private String restName; private String restName;
private String restVersion; private String restVersion;
private transient ApiUploadContext apiUploadContext;
/** /**
* 获取sign并从param中删除 * 获取sign并从param中删除
* *
@ -40,11 +39,6 @@ public class ApiParam extends JSONObject implements Param {
return sign; return sign;
} }
public HttpServletRequest fetchRequest() {
// return RequestContext.getCurrentContext().getRequest();
return null;
}
/** /**
* 是否忽略验证签名 * 是否忽略验证签名
* *
@ -191,13 +185,21 @@ public class ApiParam extends JSONObject implements Param {
return getString(ParamNames.CHARSET_NAME); return getString(ParamNames.CHARSET_NAME);
} }
@Override public void setApiUploadContext(ApiUploadContext apiUploadContext) {
public ApiParam clone() { this.apiUploadContext = apiUploadContext;
ApiParam param = new ApiParam(this); }
param.ignoreSign = this.ignoreSign;
param.ignoreValidate = this.ignoreValidate; public ApiUploadContext fetchApiUploadContext() {
return param; return apiUploadContext;
} }
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
@Override
public int hashCode() {
return super.hashCode();
}
} }

@ -15,6 +15,9 @@ import java.util.Map;
*/ */
@Slf4j @Slf4j
public class ApiParamFactory { public class ApiParamFactory {
private ApiParamFactory(){}
public static ApiParam build(Map<String, ?> params) { public static ApiParam build(Map<String, ?> params) {
ApiParam apiParam = new ApiParam(); ApiParam apiParam = new ApiParam();
for (Map.Entry<String, ?> entry : params.entrySet()) { for (Map.Entry<String, ?> entry : params.entrySet()) {

@ -1,7 +1,6 @@
package com.gitee.sop.gatewaycommon.result; package com.gitee.sop.gatewaycommon.result;
import com.gitee.sop.gatewaycommon.message.ErrorEnum; import com.gitee.sop.gatewaycommon.message.ErrorEnum;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data; import lombok.Data;
/** /**
@ -49,7 +48,6 @@ import lombok.Data;
* *
* @author tanghc * @author tanghc
*/ */
@XStreamAlias("response")
@Data @Data
public class ApiResult implements Result { public class ApiResult implements Result {

@ -1,7 +1,5 @@
package com.gitee.sop.gatewaycommon.result; package com.gitee.sop.gatewaycommon.result;
import com.gitee.sop.gatewaycommon.gateway.result.GatewayResult;
/** /**
* 对返回结果进行处理 * 对返回结果进行处理
* 成功示例 * 成功示例

@ -10,7 +10,7 @@ import java.util.Map;
*/ */
public class CacheAppSecretManager implements AppSecretManager { public class CacheAppSecretManager implements AppSecretManager {
private Map<String, String> secretMap = new HashMap<String, String>(64); private Map<String, String> secretMap = new HashMap<>(64);
@Override @Override
public void addAppSecret(Map<String, String> appSecretStore) { public void addAppSecret(Map<String, String> appSecretStore) {

@ -34,7 +34,7 @@ public class FileAppSecretManager implements AppSecretManager {
Resource resource = resourceLoader.getResource(appSecretFile); Resource resource = resourceLoader.getResource(appSecretFile);
properties = PropertiesLoaderUtils.loadProperties(resource); properties = PropertiesLoaderUtils.loadProperties(resource);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("在类路径下找不到appSecret.properties的应用密钥的属性文件"); throw new IllegalArgumentException("在类路径下找不到appSecret.properties的应用密钥的属性文件");
} }
} }

@ -22,6 +22,7 @@ import java.util.Vector;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class ApiHttpSession implements HttpSession, Serializable { public class ApiHttpSession implements HttpSession, Serializable {
private static final long serialVersionUID = 946272038219216222L; private static final long serialVersionUID = 946272038219216222L;
private static final String ATTRIBUTE_NAME_MUST_NOT_BE_NULL = "Attribute name must not be null";
private final String id; private final String id;
@ -31,9 +32,9 @@ public class ApiHttpSession implements HttpSession, Serializable {
private long lastAccessedTime = System.currentTimeMillis(); private long lastAccessedTime = System.currentTimeMillis();
private final ServletContext servletContext; private final transient ServletContext servletContext;
private final Map<String, Object> attributes = new LinkedHashMap<String, Object>(); private final transient Map<String, Object> attributes = new LinkedHashMap<>();
private boolean invalid = false; private boolean invalid = false;
@ -48,9 +49,8 @@ public class ApiHttpSession implements HttpSession, Serializable {
/** /**
* Create a new ApiHttpSession. * Create a new ApiHttpSession.
* *
* @param servletContext * @param servletContext the ServletContext that the session runs in
* the ServletContext that the session runs in
*/ */
public ApiHttpSession(ServletContext servletContext) { public ApiHttpSession(ServletContext servletContext) {
this(servletContext, null); this(servletContext, null);
@ -58,11 +58,9 @@ public class ApiHttpSession implements HttpSession, Serializable {
/** /**
* Create a new ApiHttpSession. * Create a new ApiHttpSession.
* *
* @param servletContext * @param servletContext the ServletContext that the session runs in
* the ServletContext that the session runs in * @param id a unique identifier for this session
* @param id
* a unique identifier for this session
*/ */
public ApiHttpSession(ServletContext servletContext, String id) { public ApiHttpSession(ServletContext servletContext, String id) {
this.servletContext = servletContext; this.servletContext = servletContext;
@ -108,14 +106,19 @@ public class ApiHttpSession implements HttpSession, Serializable {
return this.maxInactiveInterval; return this.maxInactiveInterval;
} }
/**
* @return
* @deprecated 已废弃不能使用
*/
@Override @Override
@Deprecated
public HttpSessionContext getSessionContext() { public HttpSessionContext getSessionContext() {
throw new UnsupportedOperationException("getSessionContext"); throw new UnsupportedOperationException("getSessionContext");
} }
@Override @Override
public Object getAttribute(String name) { public Object getAttribute(String name) {
Assert.notNull(name, "Attribute name must not be null"); Assert.notNull(name, ATTRIBUTE_NAME_MUST_NOT_BE_NULL);
return this.attributes.get(name); return this.attributes.get(name);
} }
@ -136,7 +139,7 @@ public class ApiHttpSession implements HttpSession, Serializable {
@Override @Override
public void setAttribute(String name, Object value) { public void setAttribute(String name, Object value) {
Assert.notNull(name, "Attribute name must not be null"); Assert.notNull(name, ATTRIBUTE_NAME_MUST_NOT_BE_NULL);
if (value != null) { if (value != null) {
this.attributes.put(name, value); this.attributes.put(name, value);
if (value instanceof HttpSessionBindingListener) { if (value instanceof HttpSessionBindingListener) {
@ -154,7 +157,7 @@ public class ApiHttpSession implements HttpSession, Serializable {
@Override @Override
public void removeAttribute(String name) { public void removeAttribute(String name) {
Assert.notNull(name, "Attribute name must not be null"); Assert.notNull(name, ATTRIBUTE_NAME_MUST_NOT_BE_NULL);
Object value = this.attributes.remove(name); Object value = this.attributes.remove(name);
if (value instanceof HttpSessionBindingListener) { if (value instanceof HttpSessionBindingListener) {
((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value));
@ -170,7 +173,7 @@ public class ApiHttpSession implements HttpSession, Serializable {
* Clear all of this session's attributes. * Clear all of this session's attributes.
*/ */
public void clearAttributes() { public void clearAttributes() {
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Object> entry = it.next(); Map.Entry<String, Object> entry = it.next();
String name = entry.getKey(); String name = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
@ -203,12 +206,12 @@ public class ApiHttpSession implements HttpSession, Serializable {
/** /**
* Serialize the attributes of this session into an object that can be * Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization. * turned into a byte array with standard Java serialization.
* *
* @return a representation of this session's serialized state * @return a representation of this session's serialized state
*/ */
public Serializable serializeState() { public Serializable serializeState() {
HashMap<String, Serializable> state = new HashMap<String, Serializable>(16); HashMap<String, Serializable> state = new HashMap<>(16);
for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Object> entry = it.next(); Map.Entry<String, Object> entry = it.next();
String name = entry.getKey(); String name = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
@ -229,9 +232,8 @@ public class ApiHttpSession implements HttpSession, Serializable {
/** /**
* Deserialize the attributes of this session from a state object created by * Deserialize the attributes of this session from a state object created by
* {@link #serializeState()}. * {@link #serializeState()}.
* *
* @param state * @param state a representation of this session's serialized state
* a representation of this session's serialized state
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void deserializeState(Serializable state) { public void deserializeState(Serializable state) {

@ -33,8 +33,7 @@ public class ApiSessionManager implements SessionManager {
return this.createSession(sessionId); return this.createSession(sessionId);
} }
try { try {
HttpSession session = cache.get(sessionId); return cache.get(sessionId);
return session;
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
throw ErrorEnum.AOP_UNKNOW_ERROR.getErrorMeta().getException(); throw ErrorEnum.AOP_UNKNOW_ERROR.getErrorMeta().getException();

@ -40,9 +40,9 @@ public class RedisHttpSession implements HttpSession, Serializable {
*/ */
private String id; private String id;
private ServletContext servletContext; private transient ServletContext servletContext;
private RedisTemplate redisTemplate; private transient RedisTemplate redisTemplate;
private RedisHttpSession() { private RedisHttpSession() {
} }
@ -160,7 +160,12 @@ public class RedisHttpSession implements HttpSession, Serializable {
return Integer.valueOf(String.valueOf(maxInactiveInterval)); return Integer.valueOf(String.valueOf(maxInactiveInterval));
} }
/**
* @deprecated 已废弃始终返回null
* @return
*/
@Override @Override
@Deprecated
public HttpSessionContext getSessionContext() { public HttpSessionContext getSessionContext() {
return null; return null;
} }

@ -44,6 +44,8 @@ end
*/ */
public class RedisLockUtil { public class RedisLockUtil {
private RedisLockUtil(){}
private static final Long SUCCESS = 1L; private static final Long SUCCESS = 1L;
/** 加锁脚本 */ /** 加锁脚本 */

@ -4,6 +4,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.Collections; import java.util.Collections;
@ -17,6 +18,8 @@ import java.util.Set;
*/ */
public class RequestUtil { public class RequestUtil {
private RequestUtil(){}
private static final String UTF8 = "UTF-8"; private static final String UTF8 = "UTF-8";
/** /**
@ -37,7 +40,7 @@ public class RequestUtil {
try { try {
params.put(paramArr[0], URLDecoder.decode(paramArr[1], UTF8)); params.put(paramArr[0], URLDecoder.decode(paramArr[1], UTF8));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); throw new RuntimeException(e);
} }
} else if (paramArr.length == 1) { } else if (paramArr.length == 1) {
params.put(paramArr[0], ""); params.put(paramArr[0], "");
@ -57,7 +60,7 @@ public class RequestUtil {
if(paramMap == null || paramMap.isEmpty()) { if(paramMap == null || paramMap.isEmpty()) {
return Collections.emptyMap(); return Collections.emptyMap();
} }
Map<String, Object> retMap = new HashMap<String, Object>(paramMap.size()); Map<String, Object> retMap = new HashMap<>(paramMap.size());
Set<Map.Entry<String, String[]>> entrySet = paramMap.entrySet(); Set<Map.Entry<String, String[]>> entrySet = paramMap.entrySet();
@ -76,7 +79,7 @@ public class RequestUtil {
return retMap; return retMap;
} }
public static String getText(HttpServletRequest request) throws Exception { public static String getText(HttpServletRequest request) throws IOException {
return IOUtils.toString(request.getInputStream(), UTF8); return IOUtils.toString(request.getInputStream(), UTF8);
} }

@ -20,6 +20,8 @@ import java.util.Set;
* @author tanghc * @author tanghc
*/ */
public class ResponseUtil { public class ResponseUtil {
private ResponseUtil(){}
public static final String UTF_8 = "UTF-8"; public static final String UTF_8 = "UTF-8";
private static Logger log = LoggerFactory.getLogger(ResponseUtil.class); private static Logger log = LoggerFactory.getLogger(ResponseUtil.class);
@ -46,7 +48,7 @@ public class ResponseUtil {
} }
private static String doMap2xml(JSONObject parameters) { private static String doMap2xml(JSONObject parameters) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
Set es = parameters.entrySet(); Set es = parameters.entrySet();
Iterator it = es.iterator(); Iterator it = es.iterator();
while (it.hasNext()) { while (it.hasNext()) {
@ -73,7 +75,7 @@ public class ResponseUtil {
} }
private static String buildItems(String key, JSONArray collection) { private static String buildItems(String key, JSONArray collection) {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < collection.size(); i++) { for (int i = 0; i < collection.size(); i++) {
Object jsonObject = collection.get(i); Object jsonObject = collection.get(i);
sb.append("<").append(key).append(">"); sb.append("<").append(key).append(">");
@ -87,19 +89,6 @@ public class ResponseUtil {
return sb.toString(); return sb.toString();
} }
public static void main(String[] args) {
Persion persion = new Persion();
persion.setId(1);
persion.setName("aaa");
String jsonString = JSON.toJSONString(persion);
JSONObject jsonObject = JSON.parseObject(jsonString);
String xml = mapToXml(jsonObject);
System.out.println(xml);
}
@Data @Data
public static class Persion { public static class Persion {
int id; int id;

@ -5,6 +5,8 @@ package com.gitee.sop.gatewaycommon.util;
*/ */
public class RouteUtil { public class RouteUtil {
private RouteUtil(){}
public static final String REGEX = "\\#"; public static final String REGEX = "\\#";
public static final String PROTOCOL_LOAD_BALANCE = "lb://"; public static final String PROTOCOL_LOAD_BALANCE = "lb://";

@ -36,7 +36,7 @@ public class ApiSigner extends AbstractSigner {
// 第一步:参数排序 // 第一步:参数排序
Set<String> keySet = param.keySet(); Set<String> keySet = param.keySet();
List<String> paramNames = new ArrayList<String>(keySet); List<String> paramNames = new ArrayList<>(keySet);
Collections.sort(paramNames); Collections.sort(paramNames);
// 第二步:把所有参数名和参数值串在一起 // 第二步:把所有参数名和参数值串在一起

@ -7,6 +7,7 @@ import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.param.ParamNames; import com.gitee.sop.gatewaycommon.param.ParamNames;
import com.gitee.sop.gatewaycommon.param.UploadContext; import com.gitee.sop.gatewaycommon.param.UploadContext;
import com.gitee.sop.gatewaycommon.secret.AppSecretManager; import com.gitee.sop.gatewaycommon.secret.AppSecretManager;
import com.gitee.sop.gatewaycommon.zuul.ZuulContext;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -39,17 +40,21 @@ public class ApiValidator implements Validator {
public void validate(ApiParam param) { public void validate(ApiParam param) {
ApiConfig apiConfig = ApiContext.getApiConfig(); ApiConfig apiConfig = ApiContext.getApiConfig();
if (apiConfig.isIgnoreValidate() || param.fetchIgnoreValidate()) { if (apiConfig.isIgnoreValidate() || param.fetchIgnoreValidate()) {
logger.debug("忽略所有验证(ignoreValidate=true), name:{}, version:{}", param.fetchName(), param.fetchVersion()); if (logger.isDebugEnabled()) {
logger.debug("忽略所有验证(ignoreValidate=true), name:{}, version:{}", param.fetchName(), param.fetchVersion());
}
return; return;
} }
if (param.fetchIgnoreSign()) { if (param.fetchIgnoreSign()) {
logger.debug("忽略签名验证, name:{}, version:{}", param.fetchName(), param.fetchVersion()); if (logger.isDebugEnabled()) {
logger.debug("忽略签名验证, name:{}, version:{}", param.fetchName(), param.fetchVersion());
}
} else { } else {
// 需要验证签名 // 需要验证签名
checkAppKey(param); checkAppKey(param);
checkSign(param); checkSign(param);
} }
// checkUploadFile(param); checkUploadFile(param);
checkTimeout(param); checkTimeout(param);
checkFormat(param); checkFormat(param);
} }
@ -59,28 +64,28 @@ public class ApiValidator implements Validator {
* *
* @param param * @param param
*/ */
// protected void checkUploadFile(ApiParam param) { protected void checkUploadFile(ApiParam param) {
// UploadContext uploadContext = ApiContext.getUploadContext(); UploadContext uploadContext = param.fetchApiUploadContext();
// if (uploadContext != null) { if (uploadContext != null) {
// try { try {
// List<MultipartFile> files = uploadContext.getAllFile(); List<MultipartFile> files = uploadContext.getAllFile();
// for (MultipartFile file : files) { for (MultipartFile file : files) {
// // 客户端传来的文件md5 // 客户端传来的文件md5
// String clientMd5 = param.getString(file.getName()); String clientMd5 = param.getString(file.getName());
// if (clientMd5 != null) { if (clientMd5 != null) {
// String fileMd5 = DigestUtils.md5Hex(file.getBytes()); String fileMd5 = DigestUtils.md5Hex(file.getBytes());
// if (!clientMd5.equals(fileMd5)) { if (!clientMd5.equals(fileMd5)) {
// throw ErrorEnum.ISV_UPLOAD_FAIL.getErrorMeta().getException(); throw ErrorEnum.ISV_UPLOAD_FAIL.getErrorMeta().getException();
// } }
// } }
// } }
// } catch (IOException e) { } catch (IOException e) {
// logger.error("验证上传文件MD5错误", e); logger.error("验证上传文件MD5错误", e);
// throw ErrorEnum.ISV_UPLOAD_FAIL.getErrorMeta().getException(); throw ErrorEnum.ISV_UPLOAD_FAIL.getErrorMeta().getException();
// } }
// } }
//
// } }
protected void checkTimeout(ApiParam param) { protected void checkTimeout(ApiParam param) {
int timeoutSeconds = ApiContext.getApiConfig().getTimeoutSeconds(); int timeoutSeconds = ApiContext.getApiConfig().getTimeoutSeconds();

@ -1,12 +1,9 @@
package com.gitee.sop.gatewaycommon.validate.alipay; package com.gitee.sop.gatewaycommon.validate.alipay;
import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.message.ErrorEnum; import com.gitee.sop.gatewaycommon.message.ErrorEnum;
import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.validate.Signer; import com.gitee.sop.gatewaycommon.validate.Signer;
import javax.servlet.http.HttpServletRequest;
/** /**
* 支付宝签名验证实现 * 支付宝签名验证实现
* *

@ -17,6 +17,8 @@ import java.io.Writer;
* @author runzhi * @author runzhi
*/ */
public class StreamUtil { public class StreamUtil {
private StreamUtil(){}
private static final int DEFAULT_BUFFER_SIZE = 8192; private static final int DEFAULT_BUFFER_SIZE = 8192;
public static void io(InputStream in, OutputStream out) throws IOException { public static void io(InputStream in, OutputStream out) throws IOException {

@ -6,7 +6,7 @@ package com.gitee.sop.gatewaycommon.validate.alipay;
* @author carver.gu * @author carver.gu
* @since 1.0, Sep 12, 2009 * @since 1.0, Sep 12, 2009
*/ */
public abstract class StringUtils { public class StringUtils {
private StringUtils() {} private StringUtils() {}
@ -155,7 +155,7 @@ public abstract class StringUtils {
} }
} }
private static String padding(int repeat, char padChar) throws IndexOutOfBoundsException { private static String padding(int repeat, char padChar) {
if (repeat < 0) { if (repeat < 0) {
throw new IndexOutOfBoundsException("Cannot pad a negative amount: " + repeat); throw new IndexOutOfBoundsException("Cannot pad a negative amount: " + repeat);
} else { } else {

@ -41,7 +41,7 @@ public class TaobaoSigner extends AbstractSigner {
// 第一步:参数排序 // 第一步:参数排序
Set<String> keySet = param.keySet(); Set<String> keySet = param.keySet();
List<String> paramNames = new ArrayList<String>(keySet); List<String> paramNames = new ArrayList<>(keySet);
Collections.sort(paramNames); Collections.sort(paramNames);
// 第二步:把所有参数名和参数值串在一起 // 第二步:把所有参数名和参数值串在一起

@ -2,11 +2,8 @@ package com.gitee.sop.gatewaycommon.zuul;
import com.gitee.sop.gatewaycommon.bean.ApiConfig; import com.gitee.sop.gatewaycommon.bean.ApiConfig;
import com.gitee.sop.gatewaycommon.bean.ApiContext; import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.param.UploadContext;
import com.netflix.zuul.context.RequestContext;
import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.session.SessionManager; import com.netflix.zuul.context.RequestContext;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -21,7 +18,6 @@ import java.util.Locale;
public class ZuulContext extends ApiContext { public class ZuulContext extends ApiContext {
private static final String ATTR_PARAM = "zuul.common.api.param"; private static final String ATTR_PARAM = "zuul.common.api.param";
private static final String ATTR_UPLOAD_CONTEXT = "zuul.common.api.upload_context";
private static void setAttr(String name, Object val) { private static void setAttr(String name, Object val) {
HttpServletRequest request = getRequest(); HttpServletRequest request = getRequest();
@ -39,7 +35,6 @@ public class ZuulContext extends ApiContext {
} }
/** /**
* 获取HttpServletRequest * 获取HttpServletRequest
* *
@ -64,10 +59,10 @@ public class ZuulContext extends ApiContext {
} }
/** /**
* 同getSessionId() * 同getSessionId()
* @return 返回accessToken,没有返回null *
* @return 返回accessToken, 没有返回null
*/ */
public static String getAccessToken() { public static String getAccessToken() {
return getSessionId(); return getSessionId();
@ -145,20 +140,9 @@ public class ZuulContext extends ApiContext {
return ctx; return ctx;
} }
/**
* 获取上传文件如果客户端有文件上传从这里取
* @return 如果没有文件上传返回null
*/
public static UploadContext getUploadContext() {
return (UploadContext) getAttr(ATTR_UPLOAD_CONTEXT);
}
public static void setUploadContext(UploadContext uploadCtx) {
setAttr(ATTR_UPLOAD_CONTEXT, uploadCtx);
}
/** /**
* 获取response * 获取response
*
* @return 返回response * @return 返回response
*/ */
public static HttpServletResponse getResponse() { public static HttpServletResponse getResponse() {

@ -1,9 +1,7 @@
package com.gitee.sop.gatewaycommon.zuul.configuration; package com.gitee.sop.gatewaycommon.zuul.configuration;
import com.gitee.sop.gatewaycommon.bean.ApiContext; import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.bean.TargetRoute;
import com.gitee.sop.gatewaycommon.manager.RouteManager; import com.gitee.sop.gatewaycommon.manager.RouteManager;
import com.gitee.sop.gatewaycommon.manager.RouteRepository;
import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext; import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext;
import com.gitee.sop.gatewaycommon.message.ErrorFactory; import com.gitee.sop.gatewaycommon.message.ErrorFactory;
import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter; import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter;
@ -11,7 +9,6 @@ import com.gitee.sop.gatewaycommon.zuul.filter.PostResultFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.PreValidateFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PreValidateFilter;
import com.gitee.sop.gatewaycommon.zuul.route.SopRouteLocator; import com.gitee.sop.gatewaycommon.zuul.route.SopRouteLocator;
import com.gitee.sop.gatewaycommon.zuul.route.ZuulRouteRepository; import com.gitee.sop.gatewaycommon.zuul.route.ZuulRouteRepository;
import com.gitee.sop.gatewaycommon.zuul.route.ZuulTargetRoute;
import com.gitee.sop.gatewaycommon.zuul.route.ZuulZookeeperRouteManager; import com.gitee.sop.gatewaycommon.zuul.route.ZuulZookeeperRouteManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;

@ -81,10 +81,6 @@ public abstract class BaseZuulFilter extends ZuulFilter {
requestContext.setResponseBody(JSON.toJSONString(result)); requestContext.setResponseBody(JSON.toJSONString(result));
} }
public static void main(String[] args) {
System.out.println(JSON.toJSONString(new ApiResult()));
}
/** /**
* to classify a filter by type. Standard types in Zuul are "pre" for pre-routing filtering, * to classify a filter by type. Standard types in Zuul are "pre" for pre-routing filtering,
* "routeDefinition" for routing to an origin, "post" for post-routing filters, "error" for error handling. * "routeDefinition" for routing to an origin, "post" for post-routing filters, "error" for error handling.

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

Loading…
Cancel
Save