当前位置:网站首页>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
边栏推荐
- MySQL - execution process of MySQL query statement
- Named in pytoch_ parameters、named_ children、named_ Modules function
- Accumulation of applet knowledge points
- R语言中绘制ROC曲线方法二:pROC包
- Spark 算子之groupBy使用
- Day (10) of picking up matlab
- Spark 算子之partitionBy
- 一文读懂串口及各种电平信号含义
- Win11/10家庭版禁用Edge的inprivate浏览功能
- IronPDF for . NET 2022.4.5455
猜你喜欢
Spark 算子之groupBy使用
Master vscode remote GDB debugging
One brush 314 sword finger offer 09 Implement queue (E) with two stacks
Load Balancer
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
MySQL - MySQL查询语句的执行过程
Spark 算子之filter使用
Meaning and usage of volatile
Website pressure measurement tools Apache AB, webbench, Apache jemeter
Spark 算子之distinct使用
随机推荐
shell_2
Unity shader learning
vim指定行注释和解注释
一文掌握vscode远程gdb调试
捡起MATLAB的第(2)天
Config learning notes component
Timing model: gated cyclic unit network (Gru)
Filter usage of spark operator
Grbl learning (II)
Open source project recommendation: 3D point cloud processing software paraview, based on QT and VTK
Cap theorem
One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
捡起MATLAB的第(9)天
Leetcode-374 guess the size of the number
MySQL optimistic lock to solve concurrency conflict
ESP32_Arduino
JVM - Chapter 2 - class loader subsystem
【第5节 if和for】
Multi level cache usage
Upgrade MySQL 5.1 to 5.69