当前位置:网站首页>Openfegin remote call lost request header problem
Openfegin remote call lost request header problem
2022-07-25 05:20:00 【Study hard and love you hard!】
reason
Interceptor called
Solution configuration ( Non asynchronous )
package com.jhj.gulimall.product.config;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
@Configuration
public class GuliFeginConfig {
@Bean("requestInterceptor")
public RequestInterceptor requestInterceptor(){
return new RequestInterceptor() {
@Override
public void apply(RequestTemplate requestTemplate) {
// Get the original request information that just came in Bottom utilization threadlocal So the problem will reappear again when asynchronous
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request=requestAttributes.getRequest();
// Synchronization request header data for example Cookie requestTemplate Is a new request to send
if(request != null){
String cookie = request.getHeader("Cookie");
requestTemplate.header("Cookie",cookie);
}
}
};
}
}
Resolve asynchrony
Need to combine Non asynchronous configuration
// Get before the asynchronous method executes request
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
CompletableFuture.runAsync(()->{
// When the asynchronous method executes, it writes request
RequestContextHolder.setRequestAttributes(requestAttributes)
System.out.println(" Current thread "+Thread.currentThread().getId());
int i=10/2;
System.out.println(" Running results "+i);
},executor);
Author's statement
If there is a problem , Welcome to correct !
边栏推荐
- "Niuke | daily question" inverse Polish expression
- Summary and Prospect of aut, the transport layer protocol of sound network -- dev for dev column
- 2022-07-24: what is the output of the following go language code? A:[]int{}; B:[]int(nil); C:panic; D: Compilation error. package main import ( “fmt“ ) f
- LCP插件创建对等VLAN接口
- 服务器防护的七个建议
- Execution process of NPM run XX
- [untitled]
- The third day of rhcsa summer vacation
- Use getifaddrs to obtain the IP address of the local network interface
- Wechat applet related operation examples
猜你喜欢

When we talk about immutable infrastructure, what are we talking about

rhcsa暑假第三天

Preliminary understanding of Panda3D particle system

Pikachu vulnerability platform exercise

Redis cluster setup (Windows)

微信小程序相关操作示例

Project management tools - project developer tools

"Niuke | daily question" inverse Polish expression

Forwarding and sharing function of wechat applet

Implementation principle of epoll
随机推荐
Unity LOD
[untitled]
unity 3D物体添加 点击事件
panda3d 键盘移动场景
Build keyword driven automated testing framework
Zhanrui's first 5g baseband chip was officially released and successfully ranked among the first tier of 5g!
Ping command
OpenFegin远程调用丢失请求头问题
绕过 Web 应用程序中的 XSS 过滤器
Add transition layer to JS page
Luogu p4281 [ahoi2008] emergency gathering / gathering solution
I have seven schemes to realize web real-time message push, seven!
Dragon Dragon community released the first Anolis OS Security Guide to escort users' business systems
RHCE first day
Why does the official not recommend using UUID as MySQL primary key
Implement is by yourself_ convertible
Add click event to unity 3D object
JWT(json web token)
I will write some Q & A blogs recently, mainly focusing on the points that are easy to have doubts.
STM32 development note 117: generate IIR low-pass filter coefficients using MATLAB