mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 17:42:20 +08:00
fix(FeignConfig.class): feign拦截器添加RequestAttributes是否为空的判断,MQ监听调用时为null
This commit is contained in:
parent
c7bb7d206f
commit
996fd7b328
@ -5,6 +5,7 @@ import feign.RequestInterceptor;
|
|||||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
@ -42,17 +43,19 @@ public class FeignConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public RequestInterceptor requestInterceptor() {
|
public RequestInterceptor requestInterceptor() {
|
||||||
return (template) -> {
|
return (template) -> {
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
|
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||||
.getRequestAttributes();
|
if (requestAttributes != null) {
|
||||||
HttpServletRequest request = attributes.getRequest();
|
ServletRequestAttributes attributes = (ServletRequestAttributes) requestAttributes;
|
||||||
//获取请求头
|
HttpServletRequest request = attributes.getRequest();
|
||||||
Enumeration<String> headerNames = request.getHeaderNames();
|
//获取请求头
|
||||||
if (headerNames != null) {
|
Enumeration<String> headerNames = request.getHeaderNames();
|
||||||
while (headerNames.hasMoreElements()) {
|
if (headerNames != null) {
|
||||||
String name = headerNames.nextElement();
|
while (headerNames.hasMoreElements()) {
|
||||||
String values = request.getHeader(name);
|
String name = headerNames.nextElement();
|
||||||
//将请求头保存到模板中
|
String values = request.getHeader(name);
|
||||||
template.header(name, values);
|
//将请求头保存到模板中
|
||||||
|
template.header(name, values);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user