当前位置:网站首页>Passing header request header information between services through feign
Passing header request header information between services through feign
2022-04-23 15:58:00 【aserendipper】
The problem background
paas When an exception log alarm occurs in the service , Need to be in paas Correspondence in service header Print out the information , Because the interface requests saas service , therefore saas call paas You need to put hearer Pass on the past .
terms of settlement
newly added Feign Configuration class , Realization RequestInterceptor Interface apply Method .
@Slf4j
public class FeignConfig implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
HttpServletRequest httpServletRequest = this.getHttpServletRequest();
log.info("RequestTemplate.headers:" + JSON.toJSONString(requestTemplate.headers()));
if (null != httpServletRequest) {
Map<String, String> headers = getHeaders(httpServletRequest);
for (Map.Entry<String, String> entry : headers.entrySet()) {
requestTemplate.header(entry.getKey(), entry.getValue());
}
}
}
private HttpServletRequest getHttpServletRequest() {
try {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private Map<String, String> getHeaders(HttpServletRequest request) {
Map<String, String> map = new LinkedHashMap<>();
Enumeration<String> enumeration = request.getHeaderNames();
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement();
String value = request.getHeader(key);
map.put(key, value);
}
}
return map;
}
}
版权声明
本文为[aserendipper]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231557110905.html
边栏推荐
- Accumulation of applet knowledge points
- Cap theorem
- Neodynamic Barcode Professional for WPF V11. 0
- Intersection, union and difference sets of spark operators
- Do we media make money now? After reading this article, you will understand
- homwbrew安装、常用命令以及安装路径
- R语言中绘制ROC曲线方法二:pROC包
- JS regular determines whether the port path of the domain name or IP is correct
- Distinct use of spark operator
- 【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope
猜你喜欢
一文掌握vscode远程gdb调试
Neodynamic Barcode Professional for WPF V11. 0
Read the meaning of serial port and various level signals
Load Balancer
How can poor areas without networks have money to build networks?
Grbl learning (I)
CVPR 2022 quality paper sharing
多线程原理和常用方法以及Thread和Runnable的区别
Spark 算子之coalesce与repartition
C语言自编字符串处理函数——字符串分割、字符串填充等
随机推荐
【自娱自乐】构造笔记 week 2
TIA博图——基本操作
volatile的含义以及用法
One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
Read the meaning of serial port and various level signals
Date date calculation in shell script
Fastjon2 here he is, the performance is significantly improved, and he can fight for another ten years
Neodynamic Barcode Professional for WPF V11.0
Website pressure measurement tools Apache AB, webbench, Apache jemeter
Accumulation of applet knowledge points
Fastjon2他来了,性能显著提升,还能再战十年
Grbl learning (II)
Day (7) of picking up matlab
homwbrew安装、常用命令以及安装路径
Upgrade MySQL 5.1 to 5.611
Upgrade MySQL 5.1 to 5.69
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
Named in pytoch_ parameters、named_ children、named_ Modules function
R语言中实现作图对象排列的函数总结
Do we media make money now? After reading this article, you will understand