[OLINGO-989] Consume entity in case of exception

Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
Kanika Jashrapuria 2016-04-28 23:42:36 +05:30 committed by Christian Amend
parent 122a31ff63
commit 51f7af4b9c
2 changed files with 7 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -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;
}