spring-cloud / spring-cloud/spring-cloud-openfeign
Confusing behaviour: empty URL not allowed with default Client, but possible with ApacheHttpClient
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.3k
- Forks
- 838
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 13
Description
My issue is related to https://github.com/spring-cloud/spring-cloud-openfeign/issues/517.
I found after some debugging that contrary to the situation described in that ticket, if ApacheHttpClient is on the classpath (in my case through a dependency on io.github.openfeign:feign-httpclient), it is very well possible to specify an empty String for the url in a @FeignClient (in my case, I did it like this: @FeignClient(name = "myfeignclient", url = "${my.url:}"), i.e. with an empty String as default value and the property being absent).
This allows the context to come up at least and will only result in an UnknownHostException when a request is actually attempted to be sent through that FeignClient.
For us, this is quite convenient though in a development environment where the destination is not known or when working on someone else's project so not all the required configuration needs to be known.
The crucial difference seems to be in the method loadBalance in FeignClientFactoryBean. Without the ApacheHttpClient being available as a bean, getOptional returns null, leading to the IllegalStateException.
A bean of type ApacheHttpClient seemingly becomes registered through FeignAutoConfiguration.HttpClientFeignConfiguration.
I'm thinking that if the Client.Default implementation was exposed as a bean, both situations would behave the same.
Would this be a reasonable change? I read @OlgaMaciaszek's point on the other ticket that it is intended to fail(?) by design, but why should it work then with ApacheHttpClient? (please don't take away that possibility though, like I said above, we like it 😉)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in FeignClientFactoryBean.loadBalance and compare the default Client path with the ApacheHttpClient bean registered by FeignAutoConfiguration.HttpClientFeignConfiguration. Determine the intended behavior for an empty @FeignClient URL and document or test the result so both configurations have an explicit, consistent outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100