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 2014/09/02 13:49:34 UTC

[14/50] [abbrv] git commit: [OLINGO-241] convenience method added

[OLINGO-241] convenience method added


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/242d9616
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/242d9616
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/242d9616

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 242d9616e686e19313d72ef66376642e061100d1
Parents: a30379e
Author: Stephan Klevenz <sk...@apache.org>
Authored: Mon Jun 23 15:53:47 2014 +0200
Committer: Stephan Klevenz <sk...@apache.org>
Committed: Mon Jun 23 15:53:47 2014 +0200

----------------------------------------------------------------------
 .../olingo/odata2/api/processor/ODataResponse.java | 14 ++++++++++++++
 .../olingo/odata2/core/ODataResponseTest.java      | 17 +++++++++++++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/242d9616/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java
index 345368e..57e41c6 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/processor/ODataResponse.java
@@ -19,9 +19,11 @@
 package org.apache.olingo.odata2.api.processor;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Set;
 
 import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.api.rt.RuntimeDelegate;
 
 /**
@@ -52,6 +54,18 @@ public abstract class ODataResponse {
   public abstract Object getEntity();
 
   /**
+   * @return a response entity as inputStream which becomes the body part of a response message
+   * @throws ODataException throws ODataException in case of entity is not a stream (internal ClassCastException) 
+   */
+  public InputStream getEntityAsStream() throws ODataException {
+    try {
+    return (InputStream) getEntity();
+    } catch (ClassCastException e) {
+      throw new ODataException(e);
+    }
+  }
+  
+  /**
    * Close the underlying entity input stream (if such a stream is available) and release all with this repsonse
    * associated resources.
    * 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/242d9616/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataResponseTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataResponseTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataResponseTest.java
index fb20afc..19cd6ed 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataResponseTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataResponseTest.java
@@ -20,15 +20,18 @@ package org.apache.olingo.odata2.core;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.ByteArrayInputStream;
 import java.util.Arrays;
 import java.util.HashSet;
 
 import org.apache.olingo.odata2.api.commons.HttpContentType;
 import org.apache.olingo.odata2.api.commons.HttpHeaders;
 import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.testutil.fit.BaseTest;
 import org.junit.Test;
@@ -52,6 +55,20 @@ public class ODataResponseTest extends BaseTest {
   }
 
   @Test
+  public void buildEntityAsStreamResponseTest() throws ODataException {
+    ODataResponse response = ODataResponse.entity(new ByteArrayInputStream("abc".getBytes())).build();
+    assertNull(response.getStatus());
+    assertNotNull(response.getEntityAsStream());
+  }
+
+  @Test(expected = ODataException.class)
+  public void buildEntityAsStreamResponseFailTest() throws ODataException {
+    ODataResponse response = ODataResponse.entity("abc").build();
+    assertNull(response.getStatus());
+    assertNotNull(response.getEntityAsStream());
+  }
+
+  @Test
   public void buildHeaderResponseTest() {
     ODataResponse response = ODataResponse
         .header("abc", "123")