当前位置:网站首页>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
边栏推荐
猜你喜欢

Spark 算子之filter使用

IronPDF for .NET 2022.4.5455

Intersection, union and difference sets of spark operators

腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上

How can poor areas without networks have money to build networks?

捡起MATLAB的第(4)天

C#,贝尔数(Bell Number)的计算方法与源程序

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

Distinct use of spark operator

Day (7) of picking up matlab
随机推荐
API IX JWT auth plug-in has an error. Risk announcement of information disclosure in response (cve-2022-29266)
Neodynamic Barcode Professional for WPF V11. 0
实现缺省页面
Intersection, union and difference sets of spark operators
Metalife established a strategic partnership with ESTV and appointed its CEO Eric Yoon as a consultant
linux上启动oracle服务
Coalesce and repartition of spark operators
Function summary of drawing object arrangement in R language
Spark 算子之coalesce与repartition
【自娱自乐】构造笔记 week 2
Upgrade MySQL 5.1 to 5.611
Pgpool II 4.3 Chinese Manual - introductory tutorial
5 minutes, turn your excel into an online database, the magic cube net table Excel database
捡起MATLAB的第(10)天
js正則判斷域名或者IP的端口路徑是否正確
PS为图片添加纹理
Codejock Suite Pro v20. three
捡起MATLAB的第(6)天
The principle and common methods of multithreading and the difference between thread and runnable
Nanny Anaconda installation tutorial