diff --git a/changelog.md b/changelog.md index 48bf34a5..251584a7 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # changelog +## 1.13.4 + +- 修复admin服务列表最后更新时间不显示问题 +- 优化上传路由配置逻辑 +- 微服务可获得access_token, notify_url参数 + ## 1.13.3 - 优化参数绑定 diff --git a/sop-common/pom.xml b/sop-common/pom.xml index a9236684..b504064c 100644 --- a/sop-common/pom.xml +++ b/sop-common/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT pom diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml index cfc97ff7..69d81f49 100644 --- a/sop-common/sop-gateway-common/pom.xml +++ b/sop-common/sop-gateway-common/pom.xml @@ -5,11 +5,11 @@ com.gitee.sop sop-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT ../pom.xml sop-gateway-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT jar sop-gateway-common diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/BaseServiceRouteInfo.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/BaseServiceRouteInfo.java index 189af4da..b5d46aa1 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/BaseServiceRouteInfo.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/BaseServiceRouteInfo.java @@ -6,7 +6,7 @@ import java.util.Collections; import java.util.List; /** - * @author thc + * @author tanghc */ @Data public class BaseServiceRouteInfo { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java index 8b514b2f..2b2b72be 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ConfigLimitDto.java @@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; /** - * @author thc + * @author tanghc */ @Data public class ConfigLimitDto { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ErrorEntity.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ErrorEntity.java index 976b37ea..8fb02324 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ErrorEntity.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/ErrorEntity.java @@ -7,7 +7,7 @@ import lombok.ToString; import java.util.Objects; /** - * @author thc + * @author tanghc */ @Getter @Setter diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java index 59fdbae5..ca3d5a9e 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/GatewayModifyResponseGatewayFilter.java @@ -28,7 +28,7 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.O /** * 修改返回结果 - * @author thc + * @author tanghc */ public class GatewayModifyResponseGatewayFilter implements GlobalFilter, Ordered { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java index be8331e7..f3620103 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/handler/GatewayExceptionHandler.java @@ -25,7 +25,7 @@ import java.util.List; /** * 统一异常处理 * - * @author thc + * @author tanghc */ public class GatewayExceptionHandler implements ErrorWebExceptionHandler { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java index f3beb109..d9235d2f 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayRouteRepository.java @@ -24,7 +24,7 @@ import static java.util.Collections.synchronizedMap; /** * 路由存储管理,负责动态更新路由 * - * @author thc + * @author tanghc */ @Slf4j public class GatewayRouteRepository implements ApplicationEventPublisherAware, diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayServiceRouteInfo.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayServiceRouteInfo.java index 291ae649..9ab17d6e 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayServiceRouteInfo.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/route/GatewayServiceRouteInfo.java @@ -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 { } \ No newline at end of file diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java index 110f9eec..e1eb6838 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/message/ErrorImpl.java @@ -3,7 +3,7 @@ package com.gitee.sop.gatewaycommon.message; import lombok.Data; /** - * @author thc + * @author tanghc */ @Data public class ErrorImpl implements Error { diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java index 5167423e..c375ee99 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java @@ -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名称 */ diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/WebappZuulConfiguration.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/WebappZuulConfiguration.java index 916ba2ed..ff16de63 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/WebappZuulConfiguration.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/WebappZuulConfiguration.java @@ -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); } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulServiceRouteInfo.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulServiceRouteInfo.java index 792767c3..7e22c1f9 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulServiceRouteInfo.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/route/ZuulServiceRouteInfo.java @@ -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 { } \ No newline at end of file diff --git a/sop-common/sop-registry-api/pom.xml b/sop-common/sop-registry-api/pom.xml index 1cf666bb..f3bfcbe7 100644 --- a/sop-common/sop-registry-api/pom.xml +++ b/sop-common/sop-registry-api/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-registry-api - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT UTF-8 diff --git a/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/ServiceInstance.java b/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/ServiceInstance.java index c039ef6d..9025aa62 100644 --- a/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/ServiceInstance.java +++ b/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/ServiceInstance.java @@ -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; + } \ No newline at end of file diff --git a/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/RegistryService.java b/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/RegistryService.java index 45526adb..829b9a5a 100644 --- a/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/RegistryService.java +++ b/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/RegistryService.java @@ -9,6 +9,8 @@ import java.util.List; * @author tanghc */ public interface RegistryService { + String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss"; + /** * 获取所有服务列表 * diff --git a/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceEureka.java b/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceEureka.java index 64eada4e..f6a1c774 100644 --- a/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceEureka.java +++ b/sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/service/impl/RegistryServiceEureka.java @@ -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); } } diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml index 02d5ddd5..2be58d1f 100644 --- a/sop-common/sop-service-common/pom.xml +++ b/sop-common/sop-service-common/pom.xml @@ -6,11 +6,11 @@ com.gitee.sop sop-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT ../pom.xml sop-service-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT jar sop-service-common diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java index 20134dfd..ffb6ccac 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContext.java @@ -71,4 +71,16 @@ public interface OpenContext { */ Date getTimestamp(); + /** + * 返回token,即access_token + * @return 返回token + */ + String appAuthToken(); + + /** + * 返回回调地址 + * @return 返回回调地址 + */ + String getNotifyUrl(); + } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java index 56aefeec..94e8ef6d 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java @@ -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 implements OpenContext { @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); } } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java index 8694daf2..d717f627 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java @@ -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"; diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ZookeeperTool.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ZookeeperTool.java index 4d39a3f9..dbf4615b 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ZookeeperTool.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ZookeeperTool.java @@ -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; diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/EasyopenDocSupportController.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/EasyopenDocSupportController.java index 7aa4d8ea..5e49208f 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/EasyopenDocSupportController.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/EasyopenDocSupportController.java @@ -13,7 +13,7 @@ import java.util.Map; /** * 文档支持 - * @author thc + * @author tanghc */ public abstract class EasyopenDocSupportController { diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/WebappServiceConfiguration.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/WebappServiceConfiguration.java index 7e8054d9..db42e8d1 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/WebappServiceConfiguration.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/WebappServiceConfiguration.java @@ -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); } } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/exception/ZookeeperOperationException.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/exception/ZookeeperOperationException.java new file mode 100644 index 00000000..64823412 --- /dev/null +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/exception/ZookeeperOperationException.java @@ -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); + } +} diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/exception/ZookeeperPathNotExistException.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/exception/ZookeeperPathNotExistException.java new file mode 100644 index 00000000..2b82263e --- /dev/null +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/exception/ZookeeperPathNotExistException.java @@ -0,0 +1,10 @@ +package com.gitee.sop.servercommon.exception; + +/** + * @author tanghc + */ +public class ZookeeperPathNotExistException extends Exception { + public ZookeeperPathNotExistException(String message) { + super(message); + } +} diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java index 09a01b63..9591b79f 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/manager/ServiceZookeeperApiMetaManager.java @@ -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 routeDefinitionList) { + List 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 { diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/GatewayPredicateDefinition.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/GatewayPredicateDefinition.java index 08107e88..598e9825 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/GatewayPredicateDefinition.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/GatewayPredicateDefinition.java @@ -8,7 +8,7 @@ import java.util.LinkedHashMap; import java.util.Map; /** - * @author thc + * @author tanghc */ @Data public class GatewayPredicateDefinition { diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/ServiceRouteInfo.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/ServiceRouteInfo.java index 4f1d1e8a..78c920a9 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/ServiceRouteInfo.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/route/ServiceRouteInfo.java @@ -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 routeDefinitionList; + + /** + * 返回zookeeper路径 + * @return 返回zookeeper路径 + */ + @JSONField(serialize = false) + public String getZookeeperPath() { + return SOP_SERVICE_ROUTE_PATH + '/' + serviceId; + } } \ No newline at end of file diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/SwaggerSupport.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/SwaggerSupport.java index bb385e57..a5e2bd80 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/SwaggerSupport.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/SwaggerSupport.java @@ -11,7 +11,7 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; /** - * @author thc + * @author tanghc */ public abstract class SwaggerSupport { diff --git a/sop-example/sop-auth/pom.xml b/sop-example/sop-auth/pom.xml index 6b44d096..c16a2a0d 100644 --- a/sop-example/sop-auth/pom.xml +++ b/sop-example/sop-auth/pom.xml @@ -26,7 +26,7 @@ com.gitee.sop sop-service-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml index 992a4668..04be1bc8 100644 --- a/sop-example/sop-book/sop-book-web/pom.xml +++ b/sop-example/sop-book/sop-book-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml index 67a58e39..d7422ed6 100644 --- a/sop-example/sop-easyopen/pom.xml +++ b/sop-example/sop-easyopen/pom.xml @@ -29,7 +29,7 @@ com.gitee.sop sop-service-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-springmvc/pom.xml b/sop-example/sop-springmvc/pom.xml index d840982e..4652ae4f 100644 --- a/sop-example/sop-springmvc/pom.xml +++ b/sop-example/sop-springmvc/pom.xml @@ -20,7 +20,7 @@ com.gitee.sop sop-service-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT diff --git a/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/EurekaInitAndRegisterListener.java b/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/EurekaInitAndRegisterListener.java index b42fc11a..0db182e8 100644 --- a/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/EurekaInitAndRegisterListener.java +++ b/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/EurekaInitAndRegisterListener.java @@ -16,7 +16,7 @@ import java.net.UnknownHostException; /** * 初始化Eureka Client - * @author thc + * @author tanghc */ @Slf4j public class EurekaInitAndRegisterListener implements ServletContextListener { diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml index 590fbd13..254cbf45 100644 --- a/sop-example/sop-story/sop-story-web/pom.xml +++ b/sop-example/sop-story/sop-story-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT com.gitee.sop diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml index 63f0c304..43c550e8 100644 --- a/sop-gateway/pom.xml +++ b/sop-gateway/pom.xml @@ -23,7 +23,7 @@ com.gitee.sop sop-gateway-common - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java index 756020bb..963fbd03 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java @@ -14,7 +14,7 @@ import java.io.IOException; /** * 传统web开发入口 - * @author thc + * @author tanghc */ @WebServlet(urlPatterns = "/rest/*") public class RestServlet extends HttpServlet { diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestForm.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestForm.java index 0bd71713..ec76b046 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestForm.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestForm.java @@ -8,7 +8,7 @@ import java.util.Map; /** * 请求form - * @author thc + * @author tanghc */ @Getter @Setter diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestMethod.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestMethod.java index ada6a822..4c15c1f9 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestMethod.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/RequestMethod.java @@ -2,7 +2,7 @@ package com.gitee.sop.sdk.common; /** * 请求方法枚举 - * @author thc + * @author tanghc */ public enum RequestMethod { diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SdkConfig.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SdkConfig.java index 18598a81..e2c07ea6 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SdkConfig.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SdkConfig.java @@ -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 { diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SopSdkConstants.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SopSdkConstants.java index 16cbf156..f32f4139 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SopSdkConstants.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/common/SopSdkConstants.java @@ -1,7 +1,7 @@ package com.gitee.sop.sdk.common; /** - * @author thc + * @author tanghc */ public class SopSdkConstants { public static String DATA_SUFFIX = "_response"; diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/exception/SdkException.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/exception/SdkException.java index dd18f4ca..6b2bf1c7 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/exception/SdkException.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/exception/SdkException.java @@ -1,7 +1,7 @@ package com.gitee.sop.sdk.exception; /** - * @author thc + * @author tanghc */ public class SdkException extends RuntimeException { diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/request/BaseRequest.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/request/BaseRequest.java index 5b5089de..36794c6b 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/request/BaseRequest.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/request/BaseRequest.java @@ -32,7 +32,7 @@ import java.util.Map; * * @param 对应的Response对象 * - * @author thc + * @author tanghc */ public abstract class BaseRequest { diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java index 080d2ed3..efc376fc 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java @@ -16,7 +16,7 @@ import lombok.Setter; * }, * "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE" * } - * @author thc + * @author tanghc */ @Setter @Getter diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/FileUtil.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/FileUtil.java index c2db17ec..4a807bb7 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/FileUtil.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/FileUtil.java @@ -9,7 +9,7 @@ import java.io.InputStream; /** * 文件工具类 - * @author thc + * @author tanghc */ public class FileUtil { diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/HexUtil.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/HexUtil.java index 9d42eddc..bccfe974 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/HexUtil.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/HexUtil.java @@ -2,7 +2,7 @@ package com.gitee.sop.sdk.util; /** * hex工具类 - * @author thc + * @author tanghc */ public class HexUtil { private static final String ZERO = "0"; diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/MD5Util.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/MD5Util.java index 3b17b22b..40873af7 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/MD5Util.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/MD5Util.java @@ -4,7 +4,7 @@ import java.security.MessageDigest; /** * MD5工具类 - * @author thc + * @author tanghc */ public class MD5Util { diff --git a/sop-website/website-server/pom.xml b/sop-website/website-server/pom.xml index bd580499..c9e62cf7 100644 --- a/sop-website/website-server/pom.xml +++ b/sop-website/website-server/pom.xml @@ -25,7 +25,7 @@ com.gitee.sop sop-registry-api - 1.13.3-SNAPSHOT + 1.13.4-SNAPSHOT