spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.48k stars 37.71k forks source link

RestClient ResponseSpec.body() when using Reactor Netty throws an exception instead of returning null if no response body is available #32805

Open r16turbo opened 1 month ago

r16turbo commented 1 month ago

Environment: Spring Web 6.1.6, Java 17

The situation is the same as in #31719, which occurs when using Reactor Netty.

The reason is that the following code throws an exception:

https://github.com/spring-projects/spring-framework/blob/v6.1.6/spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java#L85

I believe that null should also be returned when using Reactor Netty, please let me know about a better way to implement this.

Thanks

r16turbo commented 1 month ago

The server was the cause of the problem, not RestClient. I'm sorry for all the fuss.

r16turbo commented 1 week ago

It seems that the RestClient is still the cause of the problem, so we will reopen.

Example of fix (Java 11 or higher):

https://github.com/spring-projects/spring-framework/blob/v6.1.6/spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java#L85

    @Override
    public InputStream getBody() throws IOException {
        InputStream body = this.body;
        if (body != null) {
            return body;
        }

        body = this.connection.inbound().receive()
                .aggregate().asInputStream().block(this.readTimeout);
        if (body == null) {
            // throw new IOException("Could not receive body");
            body = InputStream.nullInputStream();
        }
        this.body = body;
        return body;
    }
bclozel commented 1 week ago

See comment in #32934

r16turbo commented 1 week ago

Sorry, I didn't know if reopen or repost was better. best regards.