From 9dd1423594e4ff24c680a867aa9e07896b52e60b Mon Sep 17 00:00:00 2001 From: skyehtzhang Date: Sat, 2 Apr 2022 11:22:46 +0800 Subject: [PATCH] fix:fix fetching wrong PEER_SERVICE in SCG filter. --- .../filter/gateway/MetadataFirstScgFilter.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstScgFilter.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstScgFilter.java index ab6afe8d5..ab02b3b98 100644 --- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstScgFilter.java +++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/filter/gateway/MetadataFirstScgFilter.java @@ -63,7 +63,14 @@ public class MetadataFirstScgFilter implements GlobalFilter, Ordered { // TODO The peer namespace is temporarily the same as the local namespace metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_NAMESPACE, MetadataContext.LOCAL_NAMESPACE); - metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE, route.getId()); + if (route != null) { + metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE, + route.getUri().getAuthority()); + } + else { + metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_SERVICE, + exchange.getRequest().getURI().getAuthority()); + } metadataContext.putSystemMetadata(MetadataConstant.SystemMetadataKey.PEER_PATH, exchange.getRequest().getURI().getPath()); @@ -71,5 +78,4 @@ public class MetadataFirstScgFilter implements GlobalFilter, Ordered { return chain.filter(exchange); } - }