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