From 51f7af4b9cd187dcb993b6fa09b629c32084949f Mon Sep 17 00:00:00 2001 From: Kanika Jashrapuria Date: Thu, 28 Apr 2016 23:42:36 +0530 Subject: [PATCH] [OLINGO-989] Consume entity in case of exception Signed-off-by: Christian Amend --- .../core/communication/request/AbstractODataRequest.java | 9 +++++---- .../communication/request/AsyncRequestWrapperImpl.java | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java index 0528c6627..4642db0bb 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java @@ -33,8 +33,8 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.DecompressingHttpClient; +import org.apache.http.util.EntityUtils; import org.apache.olingo.client.api.ODataClient; import org.apache.olingo.client.api.communication.header.ODataHeaders; import org.apache.olingo.client.api.communication.request.ODataRequest; @@ -250,15 +250,16 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD @Override public InputStream rawExecute() { + HttpEntity httpEntity = null; try { - final HttpEntity httpEntity = doExecute().getEntity(); + httpEntity = doExecute().getEntity(); return httpEntity == null ? null : httpEntity.getContent(); } catch (IOException e) { - HttpClientUtils.closeQuietly(httpClient); + EntityUtils.consumeQuietly(httpEntity); throw new HttpClientException(e); } catch (RuntimeException e) { this.request.abort(); - HttpClientUtils.closeQuietly(httpClient); + EntityUtils.consumeQuietly(httpEntity); throw new HttpClientException(e); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java index c084e2490..6619a108c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java @@ -246,13 +246,12 @@ public class AsyncRequestWrapperImpl extends AbstractRe try { odataResponse = (R) ((AbstractODataRequest) odataRequest).getResponseTemplate().initFromEnclosedPart(res .getEntity().getContent()); - } catch (Exception e) { - HttpClientUtils.closeQuietly(res); LOG.error("Error instantiating odata response", e); odataResponse = null; + } finally { + HttpClientUtils.closeQuietly(res); } - return odataResponse; }