This is an automated email from the ASF dual-hosted git repository.

ramyav 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 ddaab6b  [OLINGO-1446]Allow empty parameters for actions and action 
imports when there is no non binding parameter defined
ddaab6b is described below

commit ddaab6b0fa6778869f03edc8d10dcf933098242b
Author: ramya vasanth <[email protected]>
AuthorDate: Thu Apr 16 15:18:52 2020 +0530

    [OLINGO-1446]Allow empty parameters for actions and action imports when 
there is no non binding parameter defined
---
 lib/server-core/pom.xml                            |  1 -
 .../deserializer/json/ODataJsonDeserializer.java   | 26 ++++++++++++++++------
 .../ODataJsonDeserializerActionParametersTest.java |  6 +++--
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/lib/server-core/pom.xml b/lib/server-core/pom.xml
index a5f792c..dade12b 100644
--- a/lib/server-core/pom.xml
+++ b/lib/server-core/pom.xml
@@ -83,7 +83,6 @@
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
-      <scope>test</scope>
     </dependency>
   </dependencies>
 
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index 1be729e..ac29475 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -18,6 +18,8 @@
  */
 package org.apache.olingo.server.core.deserializer.json;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigDecimal;
@@ -32,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.olingo.commons.api.Constants;
 import org.apache.olingo.commons.api.IConstants;
 import org.apache.olingo.commons.api.constants.Constantsv00;
@@ -304,14 +307,23 @@ public class ODataJsonDeserializer implements 
ODataDeserializer {
   @Override
   public DeserializerResult actionParameters(final InputStream stream, final 
EdmAction edmAction)
       throws DeserializerException {
+         Map<String, Parameter> parameters = new HashMap<>();
+         ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
+         byte[] inputContent = null;
     try {
-      ObjectNode tree = parseJsonTree(stream);
-      Map<String, Parameter> parameters = consumeParameters(edmAction, tree);
-
-      if (tree.isObject()) {
-        removeAnnotations(tree);
-      }
-      assertJsonNodeIsEmpty(tree);
+       IOUtils.copy(stream, byteArrayOutputStream);
+       // copy the content of input stream to reuse it
+         inputContent = byteArrayOutputStream.toByteArray();
+         if (inputContent.length > 0) {
+               InputStream inputStream1 = new 
ByteArrayInputStream(inputContent);
+             ObjectNode tree = parseJsonTree(inputStream1);
+             parameters = consumeParameters(edmAction, tree);
+       
+             if (tree.isObject()) {
+               removeAnnotations(tree);
+             }
+             assertJsonNodeIsEmpty(tree);
+         }
       return 
DeserializerResultImpl.with().actionParameters(parameters).build();
 
     } catch (final IOException e) {
diff --git 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
index b1f020e..ba4462d 100644
--- 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
+++ 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
@@ -206,8 +206,10 @@ public class ODataJsonDeserializerActionParametersTest 
extends AbstractODataDese
 
   @Test
   public void noContent() throws Exception {
-    expectException("", "UARTTwoParam", null, 
MessageKeys.JSON_SYNTAX_EXCEPTION);
-    expectException("", "BAETAllPrimRT", "ETAllPrim", 
MessageKeys.JSON_SYNTAX_EXCEPTION);
+         Map<String, Parameter> parameters = deserialize("", "UARTTwoParam", 
null);
+         assertNotNull(parameters);
+         parameters = deserialize("", "BAETAllPrimRT", "ETAllPrim");
+         assertNotNull(parameters);
   }
 
   @Test

Reply via email to