From 88d588b29c7c0dce0c4418fe66c498fb630d4e24 Mon Sep 17 00:00:00 2001 From: Mauro Mugnaini Date: Wed, 22 Mar 2023 13:41:47 +0100 Subject: [PATCH] Fixed `getInputStream()` from connection if is not a success response (HTTP code not in `2xx` and `3xx`) --- .../common/gxrest/response/inbound/GXInboundResponse.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gxJRS/src/main/java/org/gcube/common/gxrest/response/inbound/GXInboundResponse.java b/gxJRS/src/main/java/org/gcube/common/gxrest/response/inbound/GXInboundResponse.java index f01cf73..02840b2 100644 --- a/gxJRS/src/main/java/org/gcube/common/gxrest/response/inbound/GXInboundResponse.java +++ b/gxJRS/src/main/java/org/gcube/common/gxrest/response/inbound/GXInboundResponse.java @@ -104,7 +104,7 @@ public class GXInboundResponse { // ContentUtils.toByteArray(connection.getInputStream()); if (this.contentType.equals(MediaType.TEXT_PLAIN) || this.contentType.equals(MediaType.APPLICATION_JSON)) { - this.body = ContentUtils.toString(ContentUtils.toByteArray(connection.getInputStream())); + this.body = ContentUtils.toString(ContentUtils.toByteArray(getInputStream())); logger.trace("Response's content: " + this.body); this.contentAlreadyConsumed = true; } @@ -250,7 +250,7 @@ public class GXInboundResponse { if(!this.contentAlreadyConsumed) { if (this.fromConnection) { contentAlreadyConsumed = true; - return connection.getInputStream(); + return isSuccessResponse() ? connection.getInputStream() : connection.getErrorStream(); } else if (this.fromResponse) { contentAlreadyConsumed = true; return (InputStream) source.getEntity();