增加feign config日志输出
This commit is contained in:
@ -21,11 +21,13 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过拦截器来为header注入token
|
* 通过拦截器来为header注入token
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
@ConfigurationProperties(prefix = "ebtp.cloud")
|
@ConfigurationProperties(prefix = "ebtp.cloud")
|
||||||
@ConditionalOnProperty(name = "ebtp.universal.feign.token.interceptor", havingValue = "true", matchIfMissing = true)
|
@ConditionalOnProperty(name = "ebtp.universal.feign.token.interceptor", havingValue = "true", matchIfMissing = true)
|
||||||
public class FeignConfig implements RequestInterceptor {
|
public class FeignConfig implements RequestInterceptor {
|
||||||
@ -80,11 +82,13 @@ public class FeignConfig implements RequestInterceptor {
|
|||||||
if (StringUtils.startsWith(header, TOKEN_PREFIX)) {
|
if (StringUtils.startsWith(header, TOKEN_PREFIX)) {
|
||||||
String authToken = RegExUtils.replaceAll(header, TOKEN_PREFIX, "");// 提取 token 信息
|
String authToken = RegExUtils.replaceAll(header, TOKEN_PREFIX, "");// 提取 token 信息
|
||||||
|
|
||||||
|
log.info("FeignConfig extract token {} from header", authToken);
|
||||||
template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, authToken));
|
template.header(AUTHORIZATION_HEADER, String.format("%s%s", TOKEN_PREFIX, authToken));
|
||||||
} else {// 检查cookie
|
} else {// 检查cookie
|
||||||
Optional.ofNullable(attributes.getRequest().getCookies()).ifPresent(cookies -> {
|
Optional.ofNullable(attributes.getRequest().getCookies()).ifPresent(cookies -> {
|
||||||
Stream.of(cookies).filter(item -> StringUtils.equals(item.getName(), COOKIE_TOKEN_CODE)).findFirst()
|
Stream.of(cookies).filter(item -> StringUtils.equals(item.getName(), COOKIE_TOKEN_CODE)).findFirst()
|
||||||
.ifPresent(token -> {
|
.ifPresent(token -> {
|
||||||
|
log.info("FeignConfig extract token {} from cookie", token);
|
||||||
template.header(AUTHORIZATION_HEADER,
|
template.header(AUTHORIZATION_HEADER,
|
||||||
String.format("%s%s", TOKEN_PREFIX, token.getValue()));
|
String.format("%s%s", TOKEN_PREFIX, token.getValue()));
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user