-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document that SimpleClientHttpRequestFactory
(and URLConnection
which it uses) is not suitable for the WebMVC gateway server.
#3451
Comments
We have hit this bug also - we have a backend we expect to be returning a 404, but after upgrading to 4.1.4 that 404 produces a 500 error to the client instead. Following the flow of the code it looks like HttpURLConnection throws a FileNotFound exception on 404, which due to this line of code is now throwing in a different place than it previously would have, and the exception isn't handled from here correctly: This is a blocker for upgrading for us, and I hope it can be addressed soon. For now we'll stay on the older version. |
Here is a minimal reproducable example:
Gateway Application: @SpringBootApplication
public class GatewayDemoApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayDemoApplication.class, args);
}
@Bean
public RouterFunction<ServerResponse> getRoute() {
return route().GET("/status/*", http("https://httpbin.org/")).build();
}
} Example request resulting in http status code 500 instead of correct response code:
Stacktrace:
|
Any update on this? Am stuck here for some time, maybe downgrading to an older version? |
The default client in Spring Cloud Gateway WebMVC is the jdk HttpClient, not HttpURLConnection |
@spencergibb I've forked the latest version of branch 4.1.x to test the changes so that I can continue testing my gateway.
So the Maybe the following might help: When executing it again in the debugger console: I can even parse the error message: Is there any alternative till this issue is resolved? |
@mendiCap I don't get a |
Ah, I'm testing 404 specifically. |
Currently I'm testing a 409. Do you know of a previous version this would work? |
@spencergibb
This returns the correct status code and error body for the downstream backend. However, I'm not sure it's a good fix because I couldn't use an P.s: I used |
I don't think we can arbitrarily catch |
This is the default config, I haven't explicity used that. |
@Mendistern it is not the default. The jdk http client is the default unless you set |
@spencergibb I've removed the
I tried setting
Also doesn't work. Here's my application.properties:
Other than that I haven't customized anything besides the Oauth |
I did manage to make it work with the apache http 5 module. Is this compatible with the gateway? |
@Mendistern yes it is. |
Alright! Thank you for your help |
After discussion with the team, I've reverted the original change for the |
SimpleClientHttpRequestFactory
(and URLConnection
which it uses) is not suitable for the WebMVC gateway server.
Okay, thank you very much for clarifying this matter. I misunderstood the actual purpose and impact of |
Describe the bug
With the changes of #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 anorg.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:
The text was updated successfully, but these errors were encountered: