You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/06/08 08:02:20 UTC
[3/3] git commit: [OLINGO-319] fix java.lang.IllegalStateException:
Content has been consumed
[OLINGO-319] fix java.lang.IllegalStateException: Content has been consumed
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/cf360e65
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/cf360e65
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/cf360e65
Branch: refs/heads/master
Commit: cf360e6573630cd432fec89ab00b87a606939392
Parents: 5959dfb
Author: challenh <ch...@microsoft.com>
Authored: Sun Jun 8 13:35:01 2014 +0800
Committer: challenh <ch...@microsoft.com>
Committed: Sun Jun 8 13:35:01 2014 +0800
----------------------------------------------------------------------
.../invoke/AbstractODataInvokeRequest.java | 24 ++++++++++++--------
1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cf360e65/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
index 5cf9308..361741b 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/invoke/AbstractODataInvokeRequest.java
@@ -204,16 +204,20 @@ public abstract class AbstractODataInvokeRequest<T extends ODataInvokeResult>
try {
if (ODataNoContent.class.isAssignableFrom(reference)) {
invokeResult = reference.cast(new ODataNoContent());
- } else if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
- invokeResult = reference.cast(odataClient.getReader().readEntitySet(res.getEntity().getContent(),
- ODataPubFormat.fromString(getContentType())));
- } else if (CommonODataEntity.class.isAssignableFrom(reference)) {
- invokeResult = reference.cast(odataClient.getReader().readEntity(res.getEntity().getContent(),
- ODataPubFormat.fromString(getContentType())));
- } else if (CommonODataProperty.class.isAssignableFrom(reference)) {
- invokeResult = reference.cast(odataClient.getReader().readProperty(res.getEntity().getContent(),
- ODataFormat.fromString(getContentType())));
- }
+ } else {
+ // avoid getContent() twice:IllegalStateException: Content has been consumed
+ InputStream responseStream = this.payload == null ? res.getEntity().getContent() : this.payload;
+ if (CommonODataEntitySet.class.isAssignableFrom(reference)) {
+ invokeResult = reference.cast(odataClient.getReader().readEntitySet(responseStream,
+ ODataPubFormat.fromString(getContentType())));
+ } else if (CommonODataEntity.class.isAssignableFrom(reference)) {
+ invokeResult = reference.cast(odataClient.getReader().readEntity(responseStream,
+ ODataPubFormat.fromString(getContentType())));
+ } else if (CommonODataProperty.class.isAssignableFrom(reference)) {
+ invokeResult = reference.cast(odataClient.getReader().readProperty(responseStream,
+ ODataFormat.fromString(getContentType())));
+ }
+ }
} catch (IOException e) {
throw new HttpClientException(e);
} finally {