优化feign拦截器代码
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user