当前位置:网站首页>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
边栏推荐
- homwbrew安装、常用命令以及安装路径
- vim指定行注释和解注释
- Neodynamic Barcode Professional for WPF V11.0
- Fastjon2 here he is, the performance is significantly improved, and he can fight for another ten years
- Codejock Suite Pro v20.3.0
- Config组件学习笔记
- MySQL Cluster Mode and application scenario
- TIA博图——基本操作
- Cap theorem
- MySQL - execution process of MySQL query statement
猜你喜欢
Use bitnami PostgreSQL docker image to quickly set up stream replication clusters
Why disable foreign key constraints
Spark 算子之groupBy使用
Temporal model: long-term and short-term memory network (LSTM)
Intersection, union and difference sets of spark operators
One brush 314 sword finger offer 09 Implement queue (E) with two stacks
Jour (9) de ramassage de MATLAB
volatile的含义以及用法
Pgpool II 4.3 Chinese Manual - introductory tutorial
MySQL - MySQL查询语句的执行过程
随机推荐
5分钟,把你的Excel变成在线数据库,神奇的魔方网表excel数据库
How can poor areas without networks have money to build networks?
Fastjon2他来了,性能显著提升,还能再战十年
Load Balancer
[key points of final review of modern electronic assembly]
Method 2 of drawing ROC curve in R language: proc package
捡起MATLAB的第(6)天
Codejock Suite Pro v20. three
leetcode-374 猜数字大小
Neodynamic Barcode Professional for WPF V11.0
ES常用查询、排序、聚合语句
Treatment of idempotency
Config组件学习笔记
Go concurrency and channel
JS regular détermine si le nom de domaine ou le chemin de port IP est correct
一文读懂串口及各种电平信号含义
捡起MATLAB的第(2)天
Config learning notes component
Spark 算子之sortBy使用
The length of the last word of the string