spring-cloud / spring-cloud/spring-cloud-gateway
Document that `SimpleClientHttpRequestFactory` (and `URLConnection` which it uses) is not suitable for the WebMVC gateway server.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Describe the bug
With the changes of https://github.com/spring-cloud/spring-cloud-gateway/issues/3405 (introduced in version 4.1.4) the error handling does not work properly any more when using DefaultRestClient.
When the client returns any error status code (e.g. 400), the DefaultRestClient raises an org.springframework.web.client.ResourceAccessException when trying to read the response body which happens RestClientProxyExchange.
However the ResourceAccessException does not provide any accessible information about the status code other than the message text. Therefore we cannot handle it properly and only respond with 500 Internal Server Error by default.
A workaround is to use a different http client. But actually I would expect Spring Cloud Gateway to work out of the box with Spring's default client. However, you may have other opinions on this.
Sample
I'm about half an hour before my three week holiday starts, so unfortunately I'm not able to provide a reproducable example any more. I can do that when I get back, if that helps. All I can do for now is to provide the error stack trace:
2024-07-11T16:00:53.232+02:00 WARN 249503 --- [api-outages-proxy] [omcat-handler-0] d.e.a.p.e.ErrorEntityExceptionHandler : I/O error on POST request for "http://localhost:11112/api/outages": Server returned HTTP response code: 400 for URL: http://localhost:11112/api/outages
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:11112/api/outages": Server returned HTTP response code: 400 for URL: http://localhost:11112/api/outages
at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.createResourceAccessException(DefaultRestClient.java:575) ~[spring-web-6.1.10.jar:6.1.10]
at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:498) ~[spring-web-6.1.10.jar:6.1.10]
at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchange(DefaultRestClient.java:465) ~[spring-web-6.1.10.jar:6.1.10]
at org.springframework.cloud.gateway.server.mvc.handler.RestClientProxyExchange.exchange(RestClientProxyExchange.java:42) ~[spring-cloud-gateway-server-mvc-4.1.4.jar:4.1.4]
at org.springframework.cloud.gateway.server.mvc.handler.ProxyExchangeHandlerFunction.handle(ProxyExchangeHandlerFunction.java:120) ~[spring-cloud-gateway-server-mvc-4.1.4.jar:4.1.4]
at org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions$LookupProxyExchangeHandlerFunction.handle(HandlerFunctions.java:107) ~[spring-cloud-gateway-server-mvc-4.1.4.jar:4.1.4]
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 with RestClientProxyExchange.exchange and the DefaultRestClient stack trace named in the report, then verify how SimpleClientHttpRequestFactory and URLConnection handle error responses. Document that this client is unsuitable for the WebMVC gateway server and identify the alternative-client workaround described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100