diff --git a/sermant-plugins/sermant-router/spring-router-plugin/src/main/java/com/huaweicloud/sermant/router/spring/interceptor/FeignClientInterceptor.java b/sermant-plugins/sermant-router/spring-router-plugin/src/main/java/com/huaweicloud/sermant/router/spring/interceptor/FeignClientInterceptor.java index f7c785ceb6..e383528759 100644 --- a/sermant-plugins/sermant-router/spring-router-plugin/src/main/java/com/huaweicloud/sermant/router/spring/interceptor/FeignClientInterceptor.java +++ b/sermant-plugins/sermant-router/spring-router-plugin/src/main/java/com/huaweicloud/sermant/router/spring/interceptor/FeignClientInterceptor.java @@ -22,6 +22,7 @@ import com.huaweicloud.sermant.core.utils.StringUtils; import com.huaweicloud.sermant.router.common.request.RequestData; import com.huaweicloud.sermant.router.common.request.RequestHeader; +import com.huaweicloud.sermant.router.common.utils.CollectionUtils; import com.huaweicloud.sermant.router.common.utils.FlowContextUtils; import com.huaweicloud.sermant.router.common.utils.ReflectUtils; import com.huaweicloud.sermant.router.common.utils.ThreadLocalUtils; @@ -64,7 +65,8 @@ public ExecuteContext before(ExecuteContext context) { Request request = (Request) argument; Map> headers = getHeaders(request.headers()); setHeaders(request, headers); - ThreadLocalUtils.setRequestData(new RequestData(decodeTags(headers), getPath(request.url()), request.method())); + ThreadLocalUtils.setRequestData(new RequestData(decodeTags(headers), getPath(request.url()), + request.method())); } return context; } @@ -146,18 +148,16 @@ private Optional getRequestHeader() { } private Map> decodeTags(Map> headers) { - if (StringUtils.isBlank(FlowContextUtils.getTagName())) { + if (StringUtils.isBlank(FlowContextUtils.getTagName()) || CollectionUtils.isEmpty(headers)) { return headers; } Map> newHeaders = new HashMap<>(headers); - if (headers != null && headers.size() > 0) { - List list = headers.get(FlowContextUtils.getTagName()); - if (list != null && list.size() > 0) { - String tagStr = list.get(0); - Map> stringListMap = FlowContextUtils.decodeTags(tagStr); - newHeaders.putAll(stringListMap); - return Collections.unmodifiableMap(newHeaders); - } + List list = headers.get(FlowContextUtils.getTagName()); + if (CollectionUtils.isEmpty(list)) { + String tagStr = list.get(0); + Map> stringListMap = FlowContextUtils.decodeTags(tagStr); + newHeaders.putAll(stringListMap); + return Collections.unmodifiableMap(newHeaders); } return headers; }