Merge branch 'master' into registry-nacos

pull/1/head
tanghc 5 years ago
commit 01c4fda639
  1. 6
      changelog.md
  2. 2
      sop-admin/sop-admin-server/pom.xml
  3. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/result/IsvInfoVO.java
  4. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/result/IsvKeysVO.java
  5. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/result/RoleVO.java
  6. 14
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/service/result/ServiceInstanceVO.java
  7. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/GatewayPredicateDefinition.java
  8. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ServiceRouteInfo.java
  9. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/config/WebConfig.java
  10. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RoutePermissionService.java
  11. 2
      sop-common/pom.xml
  12. 4
      sop-common/sop-gateway-common/pom.xml
  13. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/BaseServiceRouteInfo.java
  14. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java
  15. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ErrorEntity.java
  16. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java
  17. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java
  18. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java
  19. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayServiceRouteInfo.java
  20. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java
  21. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java
  22. 1
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/WebappZuulConfiguration.java
  23. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulServiceRouteInfo.java
  24. 2
      sop-common/sop-registry-api/pom.xml
  25. 7
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/ServiceInstance.java
  26. 2
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/RegistryService.java
  27. 6
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceEureka.java
  28. 4
      sop-common/sop-service-common/pom.xml
  29. 12
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java
  30. 22
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java
  31. 5
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java
  32. 21
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ZookeeperTool.java
  33. 2
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/EasyopenDocSupportController.java
  34. 1
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/WebappServiceConfiguration.java
  35. 26
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/exception/ZookeeperOperationException.java
  36. 10
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/exception/ZookeeperPathNotExistException.java
  37. 68
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java
  38. 2
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/GatewayPredicateDefinition.java
  39. 17
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/ServiceRouteInfo.java
  40. 2
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/SwaggerSupport.java
  41. 2
      sop-example/sop-auth/pom.xml
  42. 2
      sop-example/sop-book/sop-book-web/pom.xml
  43. 2
      sop-example/sop-easyopen/pom.xml
  44. 2
      sop-example/sop-springmvc/pom.xml
  45. 2
      sop-example/sop-springmvc/src/main/java/com/gitee/app/config/EurekaInitAndRegisterListener.java
  46. 2
      sop-example/sop-story/sop-story-web/pom.xml
  47. 2
      sop-gateway/pom.xml
  48. 2
      sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java
  49. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestForm.java
  50. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestMethod.java
  51. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SdkConfig.java
  52. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SopSdkConstants.java
  53. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/exception/SdkException.java
  54. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/request/BaseRequest.java
  55. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java
  56. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/FileUtil.java
  57. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/HexUtil.java
  58. 2
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/MD5Util.java
  59. 2
      sop-website/website-server/pom.xml

@ -1,5 +1,11 @@
# changelog
## 1.13.4
- 修复admin服务列表最后更新时间不显示问题
- 优化上传路由配置逻辑
- 微服务可获得access_token, notify_url参数
## 1.13.3
- 优化参数绑定

@ -30,7 +30,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.3-SNAPSHOT</version>
<version>1.13.4-SNAPSHOT</version>
</dependency>
<!-- easyopen starter -->

@ -7,7 +7,7 @@ import java.util.Date;
import java.util.List;
/**
* @author thc
* @author tanghc
*/
@Data
public class IsvInfoVO {

@ -4,7 +4,7 @@ import com.gitee.easyopen.doc.annotation.ApiDocField;
import lombok.Data;
/**
* @author thc
* @author tanghc
*/
@Data
public class IsvKeysVO {

@ -6,7 +6,7 @@ import lombok.Data;
import java.util.Date;
/**
* @author thc
* @author tanghc
*/
@Data
public class RoleVO {

@ -1,11 +1,7 @@
package com.gitee.sop.adminserver.api.service.result;
import com.alibaba.fastjson.annotation.JSONField;
import com.gitee.easyopen.doc.annotation.ApiDocField;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import java.util.Date;
/**
* @author tanghc
@ -34,19 +30,11 @@ public class ServiceInstanceVO {
private String status;
@ApiDocField(description = "最后更新时间")
private String lastUpdatedTimestamp;
private String updateTime;
@ApiDocField(description = "parentId")
private Integer parentId;
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
public Date getUpdateTime() {
if (StringUtils.isBlank(lastUpdatedTimestamp)) {
return null;
}
return new Date(Long.valueOf(lastUpdatedTimestamp));
}
public String getIpPort() {
return ip != null && port > 0 ? ip + ":" + port : "";
}

@ -8,7 +8,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author thc
* @author tanghc
*/
@Data
public class GatewayPredicateDefinition {

@ -7,7 +7,7 @@ import java.util.Date;
import java.util.List;
/**
* @author thc
* @author tanghc
*/
@Data
public class ServiceRouteInfo {

@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletRequest;
/**
* @author thc
* @author tanghc
*/
@Configuration
public class WebConfig {

@ -26,7 +26,7 @@ import java.util.stream.Collectors;
/**
* 路由权限业务类
*
* @author thc
* @author tanghc
*/
@Service
@Slf4j

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

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

@ -6,7 +6,7 @@ import java.util.Collections;
import java.util.List;
/**
* @author thc
* @author tanghc
*/
@Data
public class BaseServiceRouteInfo<T extends BaseRouteDefinition> {

@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author thc
* @author tanghc
*/
@Data
public class ConfigLimitDto {

@ -7,7 +7,7 @@ import lombok.ToString;
import java.util.Objects;
/**
* @author thc
* @author tanghc
*/
@Getter
@Setter

@ -28,7 +28,7 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.O
/**
* 修改返回结果
* @author thc
* @author tanghc
*/
public class GatewayModifyResponseGatewayFilter implements GlobalFilter, Ordered {

@ -25,7 +25,7 @@ import java.util.List;
/**
* 统一异常处理
*
* @author thc
* @author tanghc
*/
public class GatewayExceptionHandler implements ErrorWebExceptionHandler {

@ -24,7 +24,7 @@ import static java.util.Collections.synchronizedMap;
/**
* 路由存储管理负责动态更新路由
*
* @author thc
* @author tanghc
*/
@Slf4j
public class GatewayRouteRepository implements ApplicationEventPublisherAware,

@ -1,12 +1,9 @@
package com.gitee.sop.gatewaycommon.gateway.route;
import com.gitee.sop.gatewaycommon.bean.BaseServiceRouteInfo;
import lombok.Data;
import java.util.List;
/**
* @author thc
* @author tanghc
*/
public class GatewayServiceRouteInfo extends BaseServiceRouteInfo<GatewayRouteDefinition> {
}

@ -3,7 +3,7 @@ package com.gitee.sop.gatewaycommon.message;
import lombok.Data;
/**
* @author thc
* @author tanghc
*/
@Data
public class ErrorImpl implements Error {

@ -39,7 +39,7 @@ public class ParamNames {
/** 请求参数的集合,最大长度不限,除公共参数外所有请求参数都必须放在这个参数中传递,具体参照各产品快速接入文档 */
public static String BIZ_CONTENT_NAME = "biz_content";
/** */
/** 时间戳格式 */
public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
/** 返回sign名称 */

@ -11,7 +11,6 @@ import com.gitee.sop.gatewaycommon.result.CustomDataNameBuilder;
public class WebappZuulConfiguration extends BaseZuulConfiguration {
static {
ApiConfig.getInstance().setIgnoreValidate(true);
ApiConfig.getInstance().setDataNameBuilder(new CustomDataNameBuilder());
ApiConfig.getInstance().setShowReturnSign(false);
}

@ -3,7 +3,7 @@ package com.gitee.sop.gatewaycommon.zuul.route;
import com.gitee.sop.gatewaycommon.bean.BaseServiceRouteInfo;
/**
* @author thc
* @author tanghc
*/
public class ZuulServiceRouteInfo extends BaseServiceRouteInfo<ZuulRouteDefinition> {
}

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.3-SNAPSHOT</version>
<version>1.13.4-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

@ -3,7 +3,7 @@ package com.gitee.sop.registryapi.bean;
import lombok.Data;
/**
* @author thc
* @author tanghc
*/
@Data
public class ServiceInstance {
@ -32,4 +32,9 @@ public class ServiceInstance {
*/
private String status;
/**
* 更新时间
*/
private String updateTime;
}

@ -9,6 +9,8 @@ import java.util.List;
* @author tanghc
*/
public interface RegistryService {
String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
/**
* 获取所有服务列表
*

@ -13,12 +13,14 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
@ -28,7 +30,7 @@ import java.util.List;
@Slf4j
public class RegistryServiceEureka implements RegistryService {
OkHttpClient client = new OkHttpClient();
private OkHttpClient client = new OkHttpClient();
@Value("${registry.eureka-server-addr:}")
private String eurekaUrl;
@ -56,6 +58,8 @@ public class RegistryServiceEureka implements RegistryService {
serviceInstance.setIp(eurekaInstance.getIpAddr());
serviceInstance.setPort(Integer.valueOf(eurekaInstance.fetchPort()));
serviceInstance.setStatus(eurekaInstance.getStatus());
Date updateTime = new Date(Long.valueOf(eurekaInstance.getLastUpdatedTimestamp()));
serviceInstance.setUpdateTime(DateFormatUtils.format(updateTime, TIMESTAMP_PATTERN));
serviceInfo.getInstances().add(serviceInstance);
}
}

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

@ -71,4 +71,16 @@ public interface OpenContext<T> {
*/
Date getTimestamp();
/**
* 返回token即access_token
* @return 返回token
*/
String appAuthToken();
/**
* 返回回调地址
* @return 返回回调地址
*/
String getNotifyUrl();
}

@ -1,16 +1,21 @@
package com.gitee.sop.servercommon.bean;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.time.DateUtils;
import java.text.ParseException;
import java.util.Date;
import static com.gitee.sop.servercommon.bean.ParamNames.API_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.APP_AUTH_TOKEN_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.APP_KEY_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.BIZ_CONTENT_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.CHARSET_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.FORMAT_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.NOTIFY_URL_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.SIGN_TYPE_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.TIMESTAMP_NAME;
import static com.gitee.sop.servercommon.bean.ParamNames.TIMESTAMP_PATTERN;
import static com.gitee.sop.servercommon.bean.ParamNames.VERSION_NAME;
/**
@ -73,6 +78,21 @@ public class OpenContextImpl<T> implements OpenContext<T> {
@Override
public Date getTimestamp() {
return rootJsonObject.getDate(TIMESTAMP_NAME);
String timestampStr = rootJsonObject.getString(TIMESTAMP_NAME);
try {
return DateUtils.parseDate(timestampStr, TIMESTAMP_PATTERN);
} catch (ParseException e) {
return null;
}
}
@Override
public String appAuthToken() {
return rootJsonObject.getString(APP_AUTH_TOKEN_NAME);
}
@Override
public String getNotifyUrl() {
return rootJsonObject.getString(NOTIFY_URL_NAME);
}
}

@ -12,6 +12,7 @@ package com.gitee.sop.servercommon.bean;
* sign String 344 商户请求参数的签名串详见签名 详见示例
* timestamp String 19 发送请求的时间格式"yyyy-MM-dd HH:mm:ss" 2014-07-24 03:07:50
* version String 3 调用的接口版本固定为1.0 1.0
* notify_url String 256 支付宝服务器主动通知商户服务器里指定的页面http/https路径 http://api.test.alipay.net/atinterface/receive_notify.htm
* app_auth_token String 40 详见应用授权概述
* biz_content String 请求参数的集合最大长度不限除公共参数外所有请求参数都必须放在这个参数中传递具体参照各产品快速接入文档
*
@ -34,12 +35,14 @@ public class ParamNames {
public static String TIMESTAMP_NAME = "timestamp";
/** 调用的接口版本 */
public static String VERSION_NAME = "version";
/** 开放平台主动通知商户服务器里指定的页面http/https路径 */
public static String NOTIFY_URL_NAME = "notify_url";
/** OAuth 2.0授权token */
public static String APP_AUTH_TOKEN_NAME = "app_auth_token";
/** 请求参数的集合,最大长度不限,除公共参数外所有请求参数都必须放在这个参数中传递,具体参照各产品快速接入文档 */
public static String BIZ_CONTENT_NAME = "biz_content";
/** */
/** 时间戳格式 */
public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";

@ -1,5 +1,7 @@
package com.gitee.sop.servercommon.bean;
import com.gitee.sop.servercommon.exception.ZookeeperOperationException;
import com.gitee.sop.servercommon.exception.ZookeeperPathNotExistException;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
@ -47,6 +49,25 @@ public class ZookeeperTool implements Closeable {
this.client = client;
}
/**
* 获取节点内容
*
* @param path
* @return 返回节点内容
* @throws ZookeeperPathNotExistException 节点不存在抛出异常
*/
public String getData(String path) throws ZookeeperPathNotExistException {
if (!isPathExist(path)) {
throw new ZookeeperPathNotExistException("path 不存在, path=" + path);
}
try {
byte[] data = getClient().getData().forPath(path);
return new String(data);
} catch (Exception e) {
throw new ZookeeperOperationException("getData error path=" + path, e);
}
}
public boolean isPathExist(String path) {
try {
return client.checkExists().forPath(path) != null;

@ -13,7 +13,7 @@ import java.util.Map;
/**
* 文档支持
* @author thc
* @author tanghc
*/
public abstract class EasyopenDocSupportController {

@ -10,6 +10,7 @@ public class WebappServiceConfiguration extends BaseServiceConfiguration {
static {
// 默认版本号为1.0
ServiceConfig.getInstance().setDefaultVersion("1.0");
ServiceConfig.getInstance().setIgnoreValidate(true);
ServiceConfig.getInstance().setWebappMode(true);
}
}

@ -0,0 +1,26 @@
package com.gitee.sop.servercommon.exception;
/**
* @author tanghc
*/
public class ZookeeperOperationException extends RuntimeException {
public ZookeeperOperationException() {
}
public ZookeeperOperationException(String message) {
super(message);
}
public ZookeeperOperationException(String message, Throwable cause) {
super(message, cause);
}
public ZookeeperOperationException(Throwable cause) {
super(cause);
}
public ZookeeperOperationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

@ -0,0 +1,10 @@
package com.gitee.sop.servercommon.exception;
/**
* @author tanghc
*/
public class ZookeeperPathNotExistException extends Exception {
public ZookeeperPathNotExistException(String message) {
super(message);
}
}

@ -2,8 +2,8 @@ package com.gitee.sop.servercommon.manager;
import com.alibaba.fastjson.JSON;
import com.gitee.sop.servercommon.bean.ServiceApiInfo;
import com.gitee.sop.servercommon.bean.ServiceConstants;
import com.gitee.sop.servercommon.bean.ZookeeperTool;
import com.gitee.sop.servercommon.exception.ZookeeperPathNotExistException;
import com.gitee.sop.servercommon.route.GatewayRouteDefinition;
import com.gitee.sop.servercommon.route.ServiceRouteInfo;
import lombok.Getter;
@ -12,11 +12,15 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.core.env.Environment;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 上传路由到zookeeper
@ -28,13 +32,10 @@ import java.util.List;
@Setter
public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
/**
* zookeeper存放接口路由信息的根目录
*/
public static final String SOP_SERVICE_ROUTE_PATH = ServiceConstants.SOP_SERVICE_ROUTE_PATH;
public static final String PATH_SPLIT = "/";
/** 网关对应的LoadBalance协议 */
private static final String PROTOCOL_LOAD_BALANCE = "lb://";
private final String routeRootPath = SOP_SERVICE_ROUTE_PATH;
private static final String PATH_SPLIT = "/";
private Environment environment;
@ -56,16 +57,16 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
/**
* 上传serviceId目录
*
* @param environment
* @param environment environment
*/
protected void uploadServiceId(Environment environment) {
try {
this.checkZookeeperNode(serviceId, "serviceId(" + serviceId + ")不能有斜杠字符'/'");
ServiceRouteInfo serviceRouteInfo = this.buildServiceRouteInfo();
// 保存路径
String savePath = routeRootPath + "/" + serviceId;
String savePath = serviceRouteInfo.getZookeeperPath();
String nodeData = JSON.toJSONString(serviceRouteInfo);
log.info("zookeeper创建serviceId路径,path:{}, nodeData:{}", savePath, nodeData);
log.info("serviceId:{}, zookeeper保存路径:{}", serviceId, savePath);
this.zookeeperTool.createPath(savePath, nodeData);
} catch (Exception e) {
throw new IllegalStateException("zookeeper操作失败");
@ -85,7 +86,7 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
/**
* 构建接口信息符合spring cloud gateway的格式
*
* @param serviceApiInfo
* @param serviceApiInfo 服务接口信息
* @return 返回服务路由信息
*/
protected ServiceRouteInfo buildServiceGatewayInfo(ServiceApiInfo serviceApiInfo) {
@ -97,9 +98,26 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
}
ServiceRouteInfo serviceRouteInfo = this.buildServiceRouteInfo();
serviceRouteInfo.setRouteDefinitionList(routeDefinitionList);
String md5 = buildMd5(routeDefinitionList);
serviceRouteInfo.setMd5(md5);
return serviceRouteInfo;
}
/**
* 构建路由id MD5
*
* @param routeDefinitionList 路由列表
* @return 返回MD5
*/
protected String buildMd5(List<GatewayRouteDefinition> routeDefinitionList) {
List<String> routeIdList = routeDefinitionList.stream()
.map(GatewayRouteDefinition::toString)
.sorted()
.collect(Collectors.toList());
String md5Source = org.apache.commons.lang3.StringUtils.join(routeIdList, "");
return DigestUtils.md5DigestAsHex(md5Source.getBytes(StandardCharsets.UTF_8));
}
protected ServiceRouteInfo buildServiceRouteInfo() {
ServiceRouteInfo serviceRouteInfo = new ServiceRouteInfo();
serviceRouteInfo.setServiceId(serviceId);
@ -110,9 +128,9 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
protected GatewayRouteDefinition buildGatewayRouteDefinition(ServiceApiInfo serviceApiInfo, ServiceApiInfo.ApiMeta apiMeta) {
GatewayRouteDefinition gatewayRouteDefinition = new GatewayRouteDefinition();
// 唯一id规则:接口名 + 版本号
String routeId = apiMeta.fetchNameVersion();
this.checkZookeeperNode(routeId, "接口定义(" + routeId + ")不能有斜杠字符'/'");
// 唯一id规则:接口名 + 版本号
BeanUtils.copyProperties(apiMeta, gatewayRouteDefinition);
gatewayRouteDefinition.setId(routeId);
gatewayRouteDefinition.setFilters(Collections.emptyList());
@ -124,7 +142,7 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
}
protected String buildUri(ServiceApiInfo serviceApiInfo, ServiceApiInfo.ApiMeta apiMeta) {
return "lb://" + serviceApiInfo.getServiceId();
return PROTOCOL_LOAD_BALANCE + serviceApiInfo.getServiceId();
}
protected String buildServletPath(ServiceApiInfo serviceApiInfo, ServiceApiInfo.ApiMeta apiMeta) {
@ -141,12 +159,23 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
/**
* 上传接口信息到zookeeper
*
* @param serviceRouteInfo
* @param serviceRouteInfo 路由服务信息
*/
protected void uploadServiceRouteInfoToZookeeper(ServiceRouteInfo serviceRouteInfo) {
String savePath = serviceRouteInfo.getZookeeperPath();
try {
String existServiceRouteInfoData = zookeeperTool.getData(savePath);
ServiceRouteInfo serviceRouteInfoExist = JSON.parseObject(existServiceRouteInfoData, ServiceRouteInfo.class);
String oldMD5 = serviceRouteInfoExist.getMd5();
String newMD5 = serviceRouteInfo.getMd5();
if (Objects.equals(oldMD5, newMD5)) {
log.info("接口没有改变,无需上传路由信息");
return;
}
} catch (ZookeeperPathNotExistException e) {
log.warn("服务路径不存在,path:{}", savePath);
}
try {
// 保存路径
String savePath = routeRootPath + "/" + serviceRouteInfo.getServiceId();
log.info("上传接口信息到zookeeper,path:{}, serviceId:{}, 接口数量:{}",
savePath,
serviceRouteInfo.getServiceId(),
@ -162,12 +191,12 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
/**
* 上传文件夹内容
*
* @param serviceRouteInfo
* @param serviceRouteInfo 路由服务信息
* @return 返回文件夹路径
*/
protected String uploadFolder(ServiceRouteInfo serviceRouteInfo) throws Exception {
// 保存路径
String savePath = routeRootPath + "/" + serviceRouteInfo.getServiceId();
String savePath = serviceRouteInfo.getZookeeperPath();
String serviceRouteInfoJson = JSON.toJSONString(serviceRouteInfo);
log.info("上传service目录到zookeeper,路径:{},内容:{}", savePath, serviceRouteInfoJson);
this.zookeeperTool.createOrUpdateData(savePath, serviceRouteInfoJson);
@ -177,7 +206,8 @@ public class ServiceZookeeperApiMetaManager implements ApiMetaManager {
/**
* 上传路由信息
*
* @param serviceRouteInfo
* @param serviceRouteInfo 路由服务
* @param parentPath 父节点
* @throws Exception
*/
protected void uploadRouteItems(ServiceRouteInfo serviceRouteInfo, String parentPath) throws Exception {

@ -8,7 +8,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author thc
* @author tanghc
*/
@Data
public class GatewayPredicateDefinition {

@ -1,16 +1,19 @@
package com.gitee.sop.servercommon.route;
import com.alibaba.fastjson.annotation.JSONField;
import com.gitee.sop.servercommon.bean.ServiceConstants;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @author thc
* @author tanghc
*/
@Data
public class ServiceRouteInfo {
private static final String SOP_SERVICE_ROUTE_PATH = ServiceConstants.SOP_SERVICE_ROUTE_PATH;
/** 服务名称,对应spring.application.name */
private String serviceId;
@ -22,6 +25,18 @@ public class ServiceRouteInfo {
private String description;
/** 路由信息md5,md5(sort(routeIdList)) */
private String md5;
@JSONField(serialize = false)
private List<GatewayRouteDefinition> routeDefinitionList;
/**
* 返回zookeeper路径
* @return 返回zookeeper路径
*/
@JSONField(serialize = false)
public String getZookeeperPath() {
return SOP_SERVICE_ROUTE_PATH + '/' + serviceId;
}
}

@ -11,7 +11,7 @@ import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
/**
* @author thc
* @author tanghc
*/
public abstract class SwaggerSupport {

@ -26,7 +26,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.3-SNAPSHOT</version>
<version>1.13.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

@ -24,7 +24,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.3-SNAPSHOT</version>
<version>1.13.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.3-SNAPSHOT</version>
<version>1.13.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

@ -20,7 +20,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.3-SNAPSHOT</version>
<version>1.13.4-SNAPSHOT</version>
</dependency>
<!-- eureka 服务发现 -->
<dependency>

@ -16,7 +16,7 @@ import java.net.UnknownHostException;
/**
* 初始化Eureka Client
* @author thc
* @author tanghc
*/
@Slf4j
public class EurekaInitAndRegisterListener implements ServletContextListener {

@ -24,7 +24,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.3-SNAPSHOT</version>
<version>1.13.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>

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

@ -14,7 +14,7 @@ import java.io.IOException;
/**
* 传统web开发入口
* @author thc
* @author tanghc
*/
@WebServlet(urlPatterns = "/rest/*")
public class RestServlet extends HttpServlet {

@ -8,7 +8,7 @@ import java.util.Map;
/**
* 请求form
* @author thc
* @author tanghc
*/
@Getter
@Setter

@ -2,7 +2,7 @@ package com.gitee.sop.sdk.common;
/**
* 请求方法枚举
* @author thc
* @author tanghc
*/
public enum RequestMethod {

@ -2,7 +2,7 @@ package com.gitee.sop.sdk.common;
/**
* @deprecated 已废弃使用com.gitee.sop.sdk.common.OpenConfig
* @author thc
* @author tanghc
*/
@Deprecated
public class SdkConfig {

@ -1,7 +1,7 @@
package com.gitee.sop.sdk.common;
/**
* @author thc
* @author tanghc
*/
public class SopSdkConstants {
public static String DATA_SUFFIX = "_response";

@ -1,7 +1,7 @@
package com.gitee.sop.sdk.exception;
/**
* @author thc
* @author tanghc
*/
public class SdkException extends RuntimeException {

@ -32,7 +32,7 @@ import java.util.Map;
*
* @param <T> 对应的Response对象
*
* @author thc
* @author tanghc
*/
public abstract class BaseRequest<T extends BaseResponse> {

@ -16,7 +16,7 @@ import lombok.Setter;
* },
* "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
* }
* @author thc
* @author tanghc
*/
@Setter
@Getter

@ -9,7 +9,7 @@ import java.io.InputStream;
/**
* 文件工具类
* @author thc
* @author tanghc
*/
public class FileUtil {

@ -2,7 +2,7 @@ package com.gitee.sop.sdk.util;
/**
* hex工具类
* @author thc
* @author tanghc
*/
public class HexUtil {
private static final String ZERO = "0";

@ -4,7 +4,7 @@ import java.security.MessageDigest;
/**
* MD5工具类
* @author thc
* @author tanghc
*/
public class MD5Util {

@ -25,7 +25,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.3-SNAPSHOT</version>
<version>1.13.4-SNAPSHOT</version>
</dependency>
<dependency>

Loading…
Cancel
Save