当前位置:网站首页>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
边栏推荐
- Multi level cache usage
- Fastjon2 here he is, the performance is significantly improved, and he can fight for another ten years
- 捡起MATLAB的第(3)天
- PS add texture to picture
- homwbrew安装、常用命令以及安装路径
- Algorithem_ ReverseLinkedList
- C#,贝尔数(Bell Number)的计算方法与源程序
- 【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope
- Upgrade MySQL 5.1 to 5.69
- Read the meaning of serial port and various level signals
猜你喜欢

Codejock Suite Pro v20.3.0

Matplotlib tutorial 05 --- operating images

王启亨谈Web3.0与价值互联网“通证交换”

实现缺省页面

One brush 314 sword finger offer 09 Implement queue (E) with two stacks

ESP32编译环境的搭建

C language self compiled string processing function - string segmentation, string filling, etc

JVM - Chapter 2 - class loader subsystem

Temporal model: long-term and short-term memory network (LSTM)

新动态:SmartMesh和MeshBox的合作新动向
随机推荐
ES常用查询、排序、聚合语句
Day (8) of picking up matlab
Unity Shader学习
安装Redis并部署Redis高可用集群
Modèle de Cluster MySQL et scénario d'application
Go concurrency and channel
JS regular détermine si le nom de domaine ou le chemin de port IP est correct
Pgpool II 4.3 Chinese Manual - introductory tutorial
Application case of GPS Beidou high precision satellite time synchronization system
s16. One click installation of containerd script based on image warehouse
Grbl learning (II)
homwbrew安装、常用命令以及安装路径
Spark 算子之groupBy使用
Ice -- source code analysis
CVPR 2022 quality paper sharing
MySQL Cluster Mode and application scenario
linux上启动oracle服务
Config组件学习笔记
How do you think the fund is REITs? Is it safe to buy the fund through the bank
Open source project recommendation: 3D point cloud processing software paraview, based on QT and VTK