From 0074fe50616a49fcc6bafbfad71ce8bef0aed038 Mon Sep 17 00:00:00 2001 From: ajaxfan <909938737@qq.com> Date: Tue, 27 Apr 2021 15:48:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96feign=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/ebtp/common/config/FeignConfig.java | 3 +- .../ebtp/core/config/FeignSeataConfig.java | 31 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/FeignConfig.java b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/FeignConfig.java index ade3e58..1100836 100644 --- a/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/FeignConfig.java +++ b/uboot-common/src/main/java/com/chinaunicom/mall/ebtp/common/config/FeignConfig.java @@ -41,7 +41,7 @@ public class FeignConfig implements RequestInterceptor { public void apply(RequestTemplate template) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (null != attributes) { + if (Objects.nonNull(attributes)) { if (isNonExistsWhiteList(template.url())) { injectToken(template, attributes); } @@ -50,6 +50,7 @@ public class FeignConfig implements RequestInterceptor { // 检查请求头是否包含 currentRoleCode if (StringUtils.isNotEmpty(currentRoleCode)) { + template.removeHeader(CURRENT_ROLE_CODE); template.header(CURRENT_ROLE_CODE, currentRoleCode); } } diff --git a/uboot-core/src/main/java/com/chinaunicom/mall/ebtp/core/config/FeignSeataConfig.java b/uboot-core/src/main/java/com/chinaunicom/mall/ebtp/core/config/FeignSeataConfig.java index 1b05ef0..c705a67 100644 --- a/uboot-core/src/main/java/com/chinaunicom/mall/ebtp/core/config/FeignSeataConfig.java +++ b/uboot-core/src/main/java/com/chinaunicom/mall/ebtp/core/config/FeignSeataConfig.java @@ -1,26 +1,25 @@ package com.chinaunicom.mall.ebtp.core.config; -import com.chinaunicom.mall.ebtp.common.config.FeignConfig; -import feign.RequestTemplate; -import io.seata.core.context.RootContext; import org.apache.commons.lang.StringUtils; import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; + +import com.chinaunicom.mall.ebtp.common.config.FeignConfig; + +import feign.RequestTemplate; +import io.seata.core.context.RootContext; @Configuration public class FeignSeataConfig extends FeignConfig { - @Override - public void apply(RequestTemplate template) { - super.apply(template); + @Override + public void apply(RequestTemplate template) { + super.apply(template); + + String xid = RootContext.getXID(); + + if (StringUtils.isNotEmpty(xid)) { + template.header(RootContext.KEY_XID, xid); + } + } - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (null != attributes) { - String xid = RootContext.getXID(); - if (StringUtils.isNotEmpty(xid)) { - template.header(RootContext.KEY_XID, xid); - } - } - } }