In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to solve the content loss in the Feign remote call parameters". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the content loss in the Feign remote call parameters".
For example, the contents of Feign remote call parameters are lost.
Service A provides the following interface (note that the parameter url here is an address):
@ GetMapping ("/ getSample") public String getSample (@ RequestParam String url) {/ / omit logic here.}
Service B needs to invoke the interface of Service A, as follows:
SampleFeignClient.getSample ("http://www.xxx.com?name=dumas&age=18");"
Ask the question: after calling Service An interface at this time, the breakpoint will find that the later parameter age=18 will be lost in the method received by A service.
The cause of the problem: Feign remote calls use the HTTP protocol, which may be that when getting parameters, the contents of the parameter url are treated as parameters, so they are discarded directly.
Solution method
Before service B is invoked, use URLEncoder.encode (url, "UTF-8")
After service A gets the parameters, use URLDecoder.decode (url, "UTF-8")
Feign remote call details-lost data synchronization call
I only add Cookie in header, and of course I can iterate through header and add everything to the new request. The solution is similar to losing the request header in Gateway.
@ Configurationpublic class FeignConfiguration {/ / feign remote call missing request header @ Bean ("requestInterceptor") public RequestInterceptor requestInterceptor () {return template-> {ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes (); HttpServletRequest request = attributes.getRequest (); String cookie = request.getHeader ("Cookie"); template.header ("Cookie", cookie);};}} Asynchronous call
When we call openfeign asynchronously, the above code returns a null pointer and does not get the current request.
We first get the current request and then share it with the child thread.
RequestAttributes attributes = RequestContextHolder.getRequestAttributes (); CompletableFuture future = CompletableFuture.runAsync (()-> {RequestContextHolder.setRequestAttributes (attributes); feign.doService ();}, executor) Thank you for your reading, the above is the content of "how to solve the loss of the content in the Feign remote call parameters". After the study of this article, I believe you have a deeper understanding of how to solve the problem of the loss of the content in the Feign remote call parameters. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.