You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ApacheHttpClient does not respect already encoded QueryMap(encoded = true) #637
val objectMapper =ObjectMapper()
val builder =Feign.builder()
.encoder(JacksonEncoder(objectMapper))
.decoder(JacksonDecoder(objectMapper))
val client = builder.target(MyService::class.java, "http://somewhere.org")
Calling service like this
val result = client.getConnection(mapOf("foo" to "/some/value"))
Call the service with the following url: http://somewhere.org/something?foo=/some/value which is what I wanted.
I tried to use ApacheHttpClient
val objectMapper =ObjectMapper()
val builder =Feign.builder()
.client(ApacheHttpClient())
....
With this client, the url got is http://somewhere.org/something?foo=%2Fsome%2Fvalue
How can I maintain the @QueryMap(encoded = true) ?
@antechrestos This appears to be a bug. Let's classify it as such. The documentation of @QueryMap does appear to indicate that when encoded = false the map values should not be encoded.
It looks like Apache Http Client is encoding the query parameters. Feign is using the RequestBuilder (Apache) to build the HttpUriRequest before making a request. build method within the RequestBuilder has the below code block handling the request parameters:
If you check the new URIBuilder(uriNotNull)).setCharset(this.charset).addParameters(this.parameters).build()
addParameters mehod is handling the url encoding and there doesn't seem to be a way of changing this behaviour on the URIBuilder or RequestBuilder classes.
A stackoverflow answer mentions using BasicHttpRequest instead of HttpUriRequest but I need to dig deeper to see if this is a viable solution.
Activity
kdavisk6 commentedon Mar 8, 2018
@antechrestos This appears to be a bug. Let's classify it as such. The documentation of
@QueryMapdoes appear to indicate that whenencoded = falsethe map values should not be encoded.kdavisk6 commentedon Mar 9, 2018
I think I found the issue
feign/httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java
Lines 105 to 108 in 861bb80
In the
ApacheHttpClientit appears it is encoding all parameters all the time. I'll do some more research.antechrestos commentedon Mar 9, 2018
Thank you very much @kdavisk6
fdirlikli commentedon Mar 10, 2018
It looks like Apache Http Client is encoding the query parameters. Feign is using the RequestBuilder (Apache) to build the HttpUriRequest before making a request.
buildmethod within the RequestBuilder has the below code block handling the request parameters:If you check the
new URIBuilder(uriNotNull)).setCharset(this.charset).addParameters(this.parameters).build()addParameters mehod is handling the url encoding and there doesn't seem to be a way of changing this behaviour on the URIBuilder or RequestBuilder classes.
A stackoverflow answer mentions using BasicHttpRequest instead of HttpUriRequest but I need to dig deeper to see if this is a viable solution.
kdavisk6 commentedon Dec 5, 2018
This should be fixed via #778, but if this comes again, please feel free to re-open.
hendryluk commentedon Jul 31, 2019
This is still happening, v10.2.3