当前位置:网站首页>通过Feign在服务之间传递header请求头信息
通过Feign在服务之间传递header请求头信息
2022-04-23 15:57:00 【aserendipper】
问题背景
paas服务发生异常日志报警时,需要在paas服务中把对应header信息打印出来,由于接口请求的是saas服务,所以saas调用paas时需要把hearer传递过去。
解决办法
新增Feign的配置类,实现RequestInterceptor接口中的apply方法。
@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://blog.csdn.net/qq_39234967/article/details/116995505
边栏推荐
- Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)
- Compile, connect -- Notes
- PS为图片添加纹理
- The biggest winner is China Telecom. Why do people dislike China Mobile and China Unicom?
- Load Balancer
- One brush 313 sword finger offer 06 Print linked list from end to end (E)
- 【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope
- 负载均衡器
- Jour (9) de ramassage de MATLAB
- 5分钟,把你的Excel变成在线数据库,神奇的魔方网表excel数据库
猜你喜欢

Neodynamic Barcode Professional for WPF V11.0

IronPDF for . NET 2022.4.5455

【现代电子装联期末复习要点】

【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope

C语言自编字符串处理函数——字符串分割、字符串填充等

matplotlib教程05---操作图像

Unity Shader学习

Metalife established a strategic partnership with ESTV and appointed its CEO Eric Yoon as a consultant

5 minutes, turn your excel into an online database, the magic cube net table Excel database

Why is IP direct connection prohibited in large-scale Internet
随机推荐
新动态:SmartMesh和MeshBox的合作新动向
ESP32编译环境的搭建
Upgrade MySQL 5.1 to 5.611
Pgpool II 4.3 Chinese Manual - introductory tutorial
Cap theorem
Meaning and usage of volatile
Do we media make money now? After reading this article, you will understand
Groupby use of spark operator
Merging of Shanzhai version [i]
捡起MATLAB的第(9)天
R语言中绘制ROC曲线方法二:pROC包
负载均衡器
Modèle de Cluster MySQL et scénario d'application
Master vscode remote GDB debugging
vim指定行注释和解注释
utils. Deprecated in35 may be cancelled due to upgrade. What should I do
Distinct use of spark operator
One brush 313 sword finger offer 06 Print linked list from end to end (E)
VIM specifies the line comment and reconciliation comment
捡起MATLAB的第(5)天