[OLINGO-989] Consume entity in case of exception Signed-off-by: Christian Amend <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/51f7af4b Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/51f7af4b Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/51f7af4b Branch: refs/heads/master Commit: 51f7af4b9cd187dcb993b6fa09b629c32084949f Parents: 122a31f Author: Kanika Jashrapuria <[email protected]> Authored: Thu Apr 28 23:42:36 2016 +0530 Committer: Christian Amend <[email protected]> Committed: Wed Jul 27 15:04:33 2016 +0200 ---------------------------------------------------------------------- .../core/communication/request/AbstractODataRequest.java | 9 +++++---- .../core/communication/request/AsyncRequestWrapperImpl.java | 5 ++--- 2 files changed, 7 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51f7af4b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AbstractODataRequest.java ---------------------------------------------------------------------- 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 0528c66..4642db0 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); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51f7af4b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/AsyncRequestWrapperImpl.java ---------------------------------------------------------------------- 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 c084e24..6619a10 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<R extends ODataResponse> 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; }
