Consistently throw IOException from ReactorNettyClientResponse
Aligned with ReactorNettyClientRequest. See gh-32952
This commit is contained in:
parent
524da905db
commit
e5be10d53d
|
@ -42,6 +42,7 @@ import org.springframework.util.StreamUtils;
|
||||||
* Created via the {@link ReactorNettyClientRequestFactory}.
|
* Created via the {@link ReactorNettyClientRequestFactory}.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Juergen Hoeller
|
||||||
* @since 6.1
|
* @since 6.1
|
||||||
*/
|
*/
|
||||||
final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest {
|
final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest {
|
||||||
|
@ -101,18 +102,8 @@ final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) { // Exceptions.ReactiveException is package private
|
catch (RuntimeException ex) {
|
||||||
Throwable cause = ex.getCause();
|
throw convertException(ex);
|
||||||
|
|
||||||
if (cause instanceof UncheckedIOException uioEx) {
|
|
||||||
throw uioEx.getCause();
|
|
||||||
}
|
|
||||||
else if (cause instanceof IOException ioEx) {
|
|
||||||
throw ioEx;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IOException(ex.getMessage(), cause);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +127,21 @@ final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static IOException convertException(RuntimeException ex) {
|
||||||
|
// Exceptions.ReactiveException is package private
|
||||||
|
Throwable cause = ex.getCause();
|
||||||
|
|
||||||
|
if (cause instanceof UncheckedIOException uioEx) {
|
||||||
|
return uioEx.getCause();
|
||||||
|
}
|
||||||
|
else if (cause instanceof IOException ioEx) {
|
||||||
|
return ioEx;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new IOException(ex.getMessage(), cause);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class ByteBufMapper implements OutputStreamPublisher.ByteMapper<ByteBuf> {
|
private static final class ByteBufMapper implements OutputStreamPublisher.ByteMapper<ByteBuf> {
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.springframework.util.StreamUtils;
|
||||||
* {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client.
|
* {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Juergen Hoeller
|
||||||
* @since 6.1
|
* @since 6.1
|
||||||
*/
|
*/
|
||||||
final class ReactorNettyClientResponse implements ClientHttpResponse {
|
final class ReactorNettyClientResponse implements ClientHttpResponse {
|
||||||
|
@ -79,8 +80,13 @@ final class ReactorNettyClientResponse implements ClientHttpResponse {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
body = this.connection.inbound().receive()
|
try {
|
||||||
.aggregate().asInputStream().block(this.readTimeout);
|
body = this.connection.inbound().receive().aggregate().asInputStream().block(this.readTimeout);
|
||||||
|
}
|
||||||
|
catch (RuntimeException ex) {
|
||||||
|
throw ReactorNettyClientRequest.convertException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
throw new IOException("Could not receive body");
|
throw new IOException("Could not receive body");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue