You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2020/12/14 14:56:33 UTC
[olingo-odata4] branch master updated: Close http result on
exceptions and when Odata Result closed
This is an automated email from the ASF dual-hosted git repository.
mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git
The following commit(s) were added to refs/heads/master by this push:
new c0eeb34 Close http result on exceptions and when Odata Result closed
c0eeb34 is described below
commit c0eeb34f3ff62d507ea80b0bc84f35623b0afcb7
Author: Vlad Kozyr <vk...@intellective.com>
AuthorDate: Thu May 7 13:33:15 2020 +0300
Close http result on exceptions and when Odata Result closed
---
.gitignore | 1 +
.../request/AbstractODataRequest.java | 35 ++++++++++++++--------
.../response/AbstractODataResponse.java | 14 ++++++++-
3 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/.gitignore b/.gitignore
index 81878c2..b54ef11 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
.idea
target
bin
+*.iml
*.bak
classes
.DS_Store
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 342c4c8..835feb6 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
@@ -18,34 +18,34 @@
*/
package org.apache.olingo.client.core.communication.request;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Constructor;
-import java.net.URI;
-import java.nio.charset.Charset;
-import java.util.Collection;
-
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
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;
-import org.apache.olingo.client.api.communication.request.ODataStreamer;
import org.apache.olingo.client.api.communication.response.ODataResponse;
import org.apache.olingo.client.api.http.HttpClientException;
import org.apache.olingo.commons.api.ex.ODataRuntimeException;
-import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.commons.api.http.HttpMethod;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.nio.charset.Charset;
+import java.util.Collection;
+
/**
* Abstract representation of an OData request. Get instance by using factories.
*
@@ -112,7 +112,7 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
public URI getURI() {
return uri;
}
-
+
@Override
public HttpUriRequest getHttpRequest() {
return request;
@@ -315,6 +315,7 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
try {
checkResponse(odataClient, response, getAccept());
} catch (ODataRuntimeException e) {
+ closeHttpResponse(response);
odataClient.getConfiguration().getHttpClientFactory().close(httpClient);
throw e;
}
@@ -322,7 +323,17 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
return response;
}
- /**
+ private void closeHttpResponse(HttpResponse response) {
+ if (response instanceof CloseableHttpResponse) {
+ try {
+ ((CloseableHttpResponse) response).close();
+ } catch (IOException e) {
+ LOG.warn("Unable to close response: {}", response, e);
+ }
+ }
+ }
+
+ /**
* Gets an empty response that can be initialized by a stream.
* <br/>
* This method has to be used to build response items about a batch request.
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java
index 0cf342a..8557f36 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/response/AbstractODataResponse.java
@@ -32,6 +32,7 @@ import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.client.api.communication.request.batch.ODataBatchLineIterator;
@@ -103,7 +104,7 @@ public abstract class AbstractODataResponse implements ODataResponse {
* Batch info (if to be batched).
*/
protected ODataBatchController batchInfo = null;
-
+
private byte[] inputContent = null;
public AbstractODataResponse(
@@ -244,6 +245,7 @@ public abstract class AbstractODataResponse implements ODataResponse {
@Override
public void close() {
+ closeHttpResponse();
odataClient.getConfiguration().getHttpClientFactory().close(httpClient);
if (batchInfo != null) {
@@ -251,6 +253,16 @@ public abstract class AbstractODataResponse implements ODataResponse {
}
}
+ protected void closeHttpResponse() {
+ if(res != null && res instanceof CloseableHttpResponse) {
+ try {
+ ((CloseableHttpResponse) res).close();
+ } catch (IOException e) {
+ LOG.debug("Unable to close response: {}", res, e);
+ }
+ }
+ }
+
@Override
public InputStream getRawResponse() {