Merge pull request 'Fixed `getInputStream()` in a `GXInboundResponse` created from a connection, if is not a success response (HTTP code not in `2xx` and `3xx`)' (!1) from mauro.mugnaini/gx-rest:master into master

Reviewed-on: #1
Reviewed-by: Luca Frosini <luca.frosini@isti.cnr.it>
This commit is contained in:
Luca Frosini 2024-05-14 15:48:08 +02:00
commit eec32da4d7
1 changed files with 2 additions and 2 deletions

View File

@ -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();