From 6a08e46f765c42a5048849786a87abe1dad1984c Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 19 Nov 2018 12:57:48 -0500 Subject: [PATCH] Correctly handle response streams in JAX-RS client --- .../ca/uhn/fhir/jaxrs/client/JaxRsHttpResponse.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/client/JaxRsHttpResponse.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/client/JaxRsHttpResponse.java index 1212d6e7481..ea9069cf23b 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/client/JaxRsHttpResponse.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/client/JaxRsHttpResponse.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.jaxrs.client; -import java.io.IOException; +import java.io.*; /* * #%L @@ -22,9 +22,6 @@ import java.io.IOException; * #L% */ -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -34,9 +31,11 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import ca.uhn.fhir.rest.client.impl.BaseHttpResponse; +import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.rest.client.api.IHttpResponse; +import org.apache.commons.io.IOUtils; /** * A Http Response based on JaxRs. This is an adapter around the class {@link javax.ws.rs.core.Response Response} @@ -118,7 +117,11 @@ public class JaxRsHttpResponse extends BaseHttpResponse implements IHttpResponse @Override public InputStream readEntity() { - return myResponse.readEntity(java.io.InputStream.class); + if (!myBufferedEntity && !myResponse.hasEntity()) { + return new ByteArrayInputStream(new byte[0]); + } else { + return new ByteArrayInputStream(myResponse.readEntity(byte[].class)); + } } @Override