[OLINGO-989] Consume entity in case of exception
Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
parent
122a31ff63
commit
51f7af4b9c
|
@ -33,8 +33,8 @@ import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
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.impl.client.DecompressingHttpClient;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.apache.olingo.client.api.ODataClient;
|
import org.apache.olingo.client.api.ODataClient;
|
||||||
import org.apache.olingo.client.api.communication.header.ODataHeaders;
|
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.ODataRequest;
|
||||||
|
@ -250,15 +250,16 @@ public abstract class AbstractODataRequest extends AbstractRequest implements OD
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream rawExecute() {
|
public InputStream rawExecute() {
|
||||||
|
HttpEntity httpEntity = null;
|
||||||
try {
|
try {
|
||||||
final HttpEntity httpEntity = doExecute().getEntity();
|
httpEntity = doExecute().getEntity();
|
||||||
return httpEntity == null ? null : httpEntity.getContent();
|
return httpEntity == null ? null : httpEntity.getContent();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
HttpClientUtils.closeQuietly(httpClient);
|
EntityUtils.consumeQuietly(httpEntity);
|
||||||
throw new HttpClientException(e);
|
throw new HttpClientException(e);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
this.request.abort();
|
this.request.abort();
|
||||||
HttpClientUtils.closeQuietly(httpClient);
|
EntityUtils.consumeQuietly(httpEntity);
|
||||||
throw new HttpClientException(e);
|
throw new HttpClientException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,13 +246,12 @@ public class AsyncRequestWrapperImpl<R extends ODataResponse> extends AbstractRe
|
||||||
try {
|
try {
|
||||||
odataResponse = (R) ((AbstractODataRequest) odataRequest).getResponseTemplate().initFromEnclosedPart(res
|
odataResponse = (R) ((AbstractODataRequest) odataRequest).getResponseTemplate().initFromEnclosedPart(res
|
||||||
.getEntity().getContent());
|
.getEntity().getContent());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
HttpClientUtils.closeQuietly(res);
|
|
||||||
LOG.error("Error instantiating odata response", e);
|
LOG.error("Error instantiating odata response", e);
|
||||||
odataResponse = null;
|
odataResponse = null;
|
||||||
|
} finally {
|
||||||
|
HttpClientUtils.closeQuietly(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return odataResponse;
|
return odataResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue