I want to consume a REST service from the outside world behind a corporate proxy with authentication. How do I configure Spring Cloud Feign to use our proxy? Note: I'm using feign spring boot implementation, I do not need to make a builder for Feign "Feign.builder () ...", since it's built automatically by spring? I've been looking for this solution to make requests to addresses through the corporate proxy for quite a while and have not found anything at all.
Asked
Active
Viewed 1,343 times
1 Answers
0
It is possible to do something like this:
@FeignClient(url="${service.url}")
public interface MyClient {
@RequestMapping(method = RequestMethod.GET, value = "/item/{idItem}", consumes = "application/json",
headers="Authorization: Basic ${service.auth}")
public Item getItem(@PathVariable("idItem") int idItem);
}
as described here: https://github.com/spring-cloud/spring-cloud-netflix/issues/288
These are also relevant if you don't want to hard code headers and url:
Can I configure a @FeignClient url using a properties/yml file?
Using @Headers with dynamic values in Feign client + Spring Cloud (Brixton RC2)

humbaba
- 318
- 2
- 10
-
That way I can make requests to addresses outside my network even though I'm inside a network with a proxy? – Diego Cândido da Silva Apr 20 '18 at 12:53
-
Ah sorry, you also need to configure feign like this feign.okhttp.enabled=true. – humbaba Apr 20 '18 at 13:22
-
I did what you said but this is giving error here after inserting the option: headers = "Authorization: Basic http://proxy.com:8080". Now I can not start the system start, the following error was generated: String index out of range: -1 – Diego Cândido da Silva Apr 20 '18 at 13:51
-
headers = "Authorization: Basic proxy.com:8080" is not correct. You should put there (${service.auth}) your authentication token (not the url) if you use authentication. If you do not use authentication, just delete the "headers" part. – humbaba Apr 20 '18 at 14:08