olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sklev...@apache.org
Subject [4/6] git commit: [OLINGO-328] improve multi valued headers of ODataRequest
Date Fri, 27 Jun 2014 15:39:03 GMT
[OLINGO-328] improve multi valued headers of ODataRequest


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

Branch: refs/heads/olingo-328
Commit: af3f998b7f40b8ff1d22b4d4463b2f3a222776a4
Parents: 97222fa
Author: Stephan Klevenz <stephan.klevenz@sap.com>
Authored: Thu Jun 26 08:53:18 2014 +0200
Committer: Stephan Klevenz <stephan.klevenz@sap.com>
Committed: Thu Jun 26 08:53:18 2014 +0200

----------------------------------------------------------------------
 .../apache/olingo/server/api/ODataRequest.java  | 23 +++++++++++---
 .../olingo/server/api/ODataRequestTest.java     | 33 ++++++++++++++++----
 2 files changed, 45 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af3f998b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataRequest.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataRequest.java
index 85883f0..5be8b96 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataRequest.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/ODataRequest.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.server.api;
 
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -44,14 +45,26 @@ public class ODataRequest {
   }
 
   /**
-   * Add header to request where name handled as case insensitive key.
+   * Add header to request where name handled as case insensitive key. If a header already
exists then the list of
+   * values will just be extended.
    * @param name case insensitive header name
    * @param values
    */
   public void addHeader(String name, List<String> values) {
-    headers.put(name.toUpperCase(), values);
+    String key = name.toUpperCase();
+    if (headers.containsKey(key)) {
+      List<String> oldValues = headers.get(key);
+      
+      List<String> newValues = new ArrayList<String>();
+      newValues.addAll(oldValues);
+      newValues.addAll(values);
+
+      headers.put(name.toUpperCase(), newValues);
+    } else {
+      headers.put(name.toUpperCase(), values);
+    }
   }
-  
+
   /**
    * Returns header value for name where name is a case insensitive key.
    * @return the header value or null if not found
@@ -59,7 +72,7 @@ public class ODataRequest {
   public List<String> getHeader(String name) {
     return headers.get(name.toUpperCase());
   }
-  
+
   public InputStream getBody() {
     return body;
   }
@@ -94,7 +107,7 @@ public class ODataRequest {
 
   public void setRawODataPath(String rawODataPath) {
     this.rawODataPath = rawODataPath;
-    
+
   }
 
   public void setRawBaseUri(String rawBaseUri) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af3f998b/lib/server-test/src/test/java/org/apache/olingo/server/api/ODataRequestTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/api/ODataRequestTest.java
b/lib/server-test/src/test/java/org/apache/olingo/server/api/ODataRequestTest.java
index f256798..d740731 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/api/ODataRequestTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/api/ODataRequestTest.java
@@ -25,21 +25,42 @@ import java.util.Arrays;
 import org.junit.Test;
 
 public class ODataRequestTest {
-  
+
   @Test
   public void testHeader() {
     ODataRequest r = new ODataRequest();
-    
+
     r.addHeader("aa", Arrays.asList("cc"));
-    
+
     assertEquals("cc", r.getHeader("aa").get(0));
     assertEquals("cc", r.getHeader("aA").get(0));
     assertEquals("cc", r.getHeader("AA").get(0));
-    
+
+  }
+
+  @Test
+  public void testHeader2() {
+    ODataRequest r = new ODataRequest();
     r.addHeader("AA", Arrays.asList("dd"));
-    
+
     assertEquals("dd", r.getHeader("aa").get(0));
     assertEquals("dd", r.getHeader("aA").get(0));
-    assertEquals("dd", r.getHeader("AA").get(0));   
+    assertEquals("dd", r.getHeader("AA").get(0));
+  }
+
+  @Test
+  public void testMultiValueHeader() {
+    ODataRequest r = new ODataRequest();
+
+    r.addHeader("aa", Arrays.asList("a", "b"));
+
+    assertEquals("a", r.getHeader("aa").get(0));
+    assertEquals("b", r.getHeader("aA").get(1));
+
+    r.addHeader("Aa", Arrays.asList("c"));
+
+    assertEquals("a", r.getHeader("aa").get(0));
+    assertEquals("b", r.getHeader("aA").get(1));
+    assertEquals("c", r.getHeader("aA").get(2));
   }
 }


Mime
View raw message