From de22c333d0d72b85d2501c71a19c9ff138c5934a Mon Sep 17 00:00:00 2001 From: tanghc Date: Wed, 17 Mar 2021 15:51:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:serviceId=E5=A4=A7=E5=B0=8F=E5=86=99?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gatewaycommon/route/ServiceRouteListener.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java index 68a1f07f..c029a1cc 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java @@ -45,13 +45,25 @@ public class ServiceRouteListener extends BaseServiceListener { ResponseEntity responseEntity = getRestTemplate().getForEntity(url, String.class); if (responseEntity.getStatusCode() == HttpStatus.OK) { String body = responseEntity.getBody(); - ServiceRouteInfo serviceRouteInfo = JSON.parseObject(body, ServiceRouteInfo.class); + ServiceRouteInfo serviceRouteInfo; + try { + serviceRouteInfo = this.parseServiceRouteInfo(body); + } catch (Exception e) { + log.error("解析路由配置错误,body:{}", body, e); + return; + } gatewayRouteCache.load(serviceRouteInfo, callback -> routesProcessor.saveRoutes(serviceRouteInfo, instance)); } else { log.error("拉取路由配置异常,url: {}, status: {}, body: {}", url, responseEntity.getStatusCodeValue(), responseEntity.getBody()); } } + private ServiceRouteInfo parseServiceRouteInfo(String body) { + ServiceRouteInfo serviceRouteInfo = JSON.parseObject(body, ServiceRouteInfo.class); + serviceRouteInfo.setServiceId(serviceRouteInfo.getServiceId().toLowerCase()); + return serviceRouteInfo; + } + protected HttpEntity getHttpEntity() { HttpHeaders headers = new HttpHeaders(); return new HttpEntity<>(headers);