Merge branch 'master' into eureka

eureka
tanghc 5 years ago
commit 248ff9f12c
  1. 5
      changelog.md
  2. 13
      doc/docs/files/90100_常见问题.md
  3. 2
      sop-auth/pom.xml
  4. 2
      sop-common/pom.xml
  5. 4
      sop-common/sop-gateway-common/pom.xml
  6. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java
  7. 7
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java
  8. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java
  9. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseServiceListener.java
  10. 17
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/RegistryMetadata.java
  11. 4
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java
  12. 4
      sop-common/sop-service-common/pom.xml
  13. 2
      sop-example/sop-book/sop-book-web/pom.xml
  14. 2
      sop-example/sop-easyopen/pom.xml
  15. 2
      sop-example/sop-springmvc/pom.xml
  16. 2
      sop-example/sop-story/sop-story-web/pom.xml
  17. 2
      sop-gateway/pom.xml
  18. 2
      sop-website/pom.xml
  19. 4
      sop-website/src/main/java/com/gitee/sop/websiteserver/listener/ServiceDocListener.java

@ -1,5 +1,10 @@
# changelog # changelog
## 2.5.9
- 优化获取context-path
- 修复结果返回产生的NPE问题
## 2.5.8 ## 2.5.8
- 优化参数绑定 - 优化参数绑定

@ -108,7 +108,18 @@ ribbon.ReadTimeout: 60000
微服务项目定义了`server.servlet.context-path=/story-service`,同时必须指定: 微服务项目定义了`server.servlet.context-path=/story-service`,同时必须指定:
```properties ```properties
spring.cloud.nacos.discovery.metadata.server.servlet.context-path=${server.servlet.context-path} spring.cloud.nacos.discovery.metadata.context-path=${server.servlet.context-path}
```
yml配置如下:
```yaml
spring:
cloud:
nacos:
discovery:
metadata:
context-path: ${server.servlet.context-path}
``` ```
不然网关无法拉取路由信息 不然网关无法拉取路由信息

@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
</dependency> </dependency>
<!-- sop相关配置 end--> <!-- sop相关配置 end-->

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>

@ -5,11 +5,11 @@
<parent> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-gateway-common</name> <name>sop-gateway-common</name>

@ -24,6 +24,8 @@ public class SopConstants {
public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path"; public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path";
public static final String METADATA_SERVER_CONTEXT_PATH_COMPATIBILITY = "context-path";
/** /**
* 在拦截器中调用获取参数 * 在拦截器中调用获取参数
* String cachedBody = (String)exchange.getAttribute(SopConstants.CACHE_REQUEST_BODY_OBJECT_KEY); * String cachedBody = (String)exchange.getAttribute(SopConstants.CACHE_REQUEST_BODY_OBJECT_KEY);

@ -11,6 +11,7 @@ import com.gitee.sop.gatewaycommon.bean.NacosConfigs;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo; import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import com.gitee.sop.gatewaycommon.bean.SopConstants; import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.bean.TargetRoute; import com.gitee.sop.gatewaycommon.bean.TargetRoute;
import com.gitee.sop.gatewaycommon.route.RegistryMetadata;
import com.gitee.sop.gatewaycommon.route.RegistryListener; import com.gitee.sop.gatewaycommon.route.RegistryListener;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -39,7 +40,7 @@ import java.util.Objects;
*/ */
@Deprecated @Deprecated
@Slf4j @Slf4j
public class ServiceRoutesLoader<T extends TargetRoute> { public class ServiceRoutesLoader<T extends TargetRoute> implements RegistryMetadata {
private static final String SOP_ROUTES_PATH = "/sop/routes"; private static final String SOP_ROUTES_PATH = "/sop/routes";
@ -140,7 +141,7 @@ public class ServiceRoutesLoader<T extends TargetRoute> {
* @param instance 服务实例 * @param instance 服务实例
* @return 返回最终url * @return 返回最终url
*/ */
private static String getRouteRequestUrl(Instance instance) { private String getRouteRequestUrl(Instance instance) {
Map<String, String> metadata = instance.getMetadata(); Map<String, String> metadata = instance.getMetadata();
String customPath = metadata.get(METADATA_SOP_ROUTES_PATH); String customPath = metadata.get(METADATA_SOP_ROUTES_PATH);
String homeUrl; String homeUrl;
@ -158,7 +159,7 @@ public class ServiceRoutesLoader<T extends TargetRoute> {
} else { } else {
// 默认处理 // 默认处理
homeUrl = getHomeUrl(instance); homeUrl = getHomeUrl(instance);
String contextPath = metadata.getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, ""); String contextPath = this.getContextPath(metadata);
servletPath = contextPath + SOP_ROUTES_PATH; servletPath = contextPath + SOP_ROUTES_PATH;
} }
if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) { if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) {

@ -261,7 +261,7 @@ public abstract class BaseExecutorAdapter<T, R> implements ResultExecutor<T, R>
return null; return null;
} }
Isv isvInfo = isvManager.getIsv(appKey); Isv isvInfo = isvManager.getIsv(appKey);
String privateKeyPlatform = isvInfo.getPrivateKeyPlatform(); String privateKeyPlatform = isvInfo == null ? null : isvInfo.getPrivateKeyPlatform();
if (StringUtils.isEmpty(privateKeyPlatform)) { if (StringUtils.isEmpty(privateKeyPlatform)) {
return null; return null;
} }

@ -8,7 +8,7 @@ import org.springframework.web.client.RestTemplate;
/** /**
* @author tanghc * @author tanghc
*/ */
public abstract class BaseServiceListener implements ServiceListener { public abstract class BaseServiceListener implements ServiceListener, RegistryMetadata {
private static final String SECRET = "a3d9sf!1@odl90zd>fkASwq"; private static final String SECRET = "a3d9sf!1@odl90zd>fkASwq";

@ -0,0 +1,17 @@
package com.gitee.sop.gatewaycommon.route;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
import java.util.Map;
/**
* @author tanghc
*/
public interface RegistryMetadata {
default String getContextPath(Map<String, String> metadata) {
return metadata.getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH
, metadata.getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH_COMPATIBILITY, ""));
}
}

@ -70,7 +70,7 @@ public class ServiceRouteListener extends BaseServiceListener {
* @param instance 服务实例 * @param instance 服务实例
* @return 返回最终url * @return 返回最终url
*/ */
private static String getRouteRequestUrl(InstanceDefinition instance) { private String getRouteRequestUrl(InstanceDefinition instance) {
Map<String, String> metadata = instance.getMetadata(); Map<String, String> metadata = instance.getMetadata();
String customPath = metadata.get(METADATA_SOP_ROUTES_PATH); String customPath = metadata.get(METADATA_SOP_ROUTES_PATH);
String homeUrl; String homeUrl;
@ -88,7 +88,7 @@ public class ServiceRouteListener extends BaseServiceListener {
} else { } else {
// 默认处理 // 默认处理
homeUrl = getHomeUrl(instance); homeUrl = getHomeUrl(instance);
String contextPath = metadata.getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, ""); String contextPath = this.getContextPath(metadata);
servletPath = contextPath + SOP_ROUTES_PATH; servletPath = contextPath + SOP_ROUTES_PATH;
} }
if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) { if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) {

@ -6,11 +6,11 @@
<parent> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-service-common</name> <name>sop-service-common</name>

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
</dependency> </dependency>
<!-- 使用nacos注册中心 <!-- 使用nacos注册中心

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

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
</dependency> </dependency>
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ --> <!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->

@ -35,7 +35,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.8-SNAPSHOT</version> <version>2.5.9-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

@ -44,9 +44,9 @@ public class ServiceDocListener extends BaseServiceListener {
} }
} }
private static String getRouteRequestUrl(InstanceDefinition instance) { private String getRouteRequestUrl(InstanceDefinition instance) {
String query = buildQuery(SECRET); String query = buildQuery(SECRET);
String contextPath = instance.getMetadata().getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, ""); String contextPath = this.getContextPath(instance.getMetadata());
return "http://" + instance.getIp() + ":" + instance.getPort() + contextPath + "/v2/api-docs" + query; return "http://" + instance.getIp() + ":" + instance.getPort() + contextPath + "/v2/api-docs" + query;
} }
} }

Loading…
Cancel
Save