olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [06/33] olingo-odata2 git commit: [OLINGO-469] Fix: Batch boundary content type with multiple parameters
Date Wed, 10 Dec 2014 19:30:55 GMT
[OLINGO-469] Fix: Batch boundary content type with multiple parameters

Signed-off-by: Christian Amend <chrisam@apache.org>


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 7df31f5578f5cf922df4803ec5c534b0cf62cd5a
Parents: 9dd4de7
Author: Christian Holzer <c.holzer@sap.com>
Authored: Mon Oct 27 17:25:16 2014 +0100
Committer: Christian Amend <chrisam@apache.org>
Committed: Tue Oct 28 10:19:20 2014 +0100

----------------------------------------------------------------------
 .../odata2/core/batch/v2/BatchBodyPart.java     |  2 +-
 .../odata2/core/batch/v2/BatchParserCommon.java | 32 +++++++++++---------
 .../core/batch/v2/BatchTransformatorCommon.java |  2 +-
 .../core/batch/BatchRequestParserTest.java      | 15 ++++++++-
 .../olingo/odata2/core/batch/HeaderTest.java    |  4 +--
 5 files changed, 36 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7df31f55/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchBodyPart.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchBodyPart.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchBodyPart.java
index d60c29a..bfadac9 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchBodyPart.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchBodyPart.java
@@ -70,7 +70,7 @@ public class BatchBodyPart implements BatchPart {
   }
 
   private boolean isContentTypeMultiPartMixed(final String contentType) {
-    return BatchParserCommon.PATTERN_MULTIPART_BOUNDARY.matcher(contentType).matches();
+    return BatchParserCommon.PATTERN_MULTIPART_MIXED.matcher(contentType).matches();
   }
 
   private List<BatchQueryOperation> consumeRequest(final List<Line> remainingMessage)
throws BatchException {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7df31f55/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
index c2751ee..b36f873 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchParserCommon.java
@@ -45,10 +45,9 @@ public class BatchParserCommon {
       "([a-zA-Z0-9_\\-\\.'\\+]{1,70})|\"([a-zA-Z0-9_\\-\\.'\\+\\s\\" +
           "(\\),/:=\\?]{1,69}[a-zA-Z0-9_\\-\\.'\\+\\(\\),/:=\\?])\""; // See RFC 2046
 
-  private static final String REX_EX_MULTIPART_BOUNDARY = "multipart/mixed;\\s*boundary=(.+)";
-  private static final String REG_EX_APPLICATION_HTTP = "application/http";
-  public static final Pattern PATTERN_MULTIPART_BOUNDARY = Pattern.compile(REX_EX_MULTIPART_BOUNDARY,
-      Pattern.CASE_INSENSITIVE);
+  public static final Pattern PATTERN_MULTIPART_MIXED = Pattern
+      .compile("multipart/mixed(.*)", Pattern.CASE_INSENSITIVE);
+  final static String REG_EX_APPLICATION_HTTP = "application/http";
   public static final Pattern PATTERN_HEADER_LINE = Pattern.compile("([a-zA-Z\\-]+):\\s?(.*)\\s*");
   public static final Pattern PATTERN_CONTENT_TYPE_APPLICATION_HTTP = Pattern.compile(REG_EX_APPLICATION_HTTP,
       Pattern.CASE_INSENSITIVE);
@@ -204,18 +203,23 @@ public class BatchParserCommon {
   }
 
   public static String getBoundary(final String contentType, final int line) throws BatchException
{
-    final Matcher boundaryMatcher = PATTERN_MULTIPART_BOUNDARY.matcher(contentType);
+    if (contentType.toLowerCase(Locale.ENGLISH).startsWith("multipart/mixed")) {
+      final String[] parameter = contentType.split(";");
+
+      for (final String pair : parameter) {
+
+        final String[] attrValue = pair.split("=");
+        if (attrValue.length == 2 && "boundary".equals(attrValue[0].trim().toLowerCase(Locale.ENGLISH)))
{
+          if (attrValue[1].matches(REG_EX_BOUNDARY)) {
+            return trimQuota(attrValue[1].trim());
+          } else {
+            throw new BatchException(BatchException.INVALID_BOUNDARY.addContent(line));
+          }
+        }
 
-    if (boundaryMatcher.matches()) {
-      final String boundary = boundaryMatcher.group(1);
-      if (boundary.matches(REG_EX_BOUNDARY)) {
-        return trimQuota(boundary);
-      } else {
-        throw new BatchException(BatchException.INVALID_BOUNDARY.addContent(line));
       }
-    } else {
-      throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(HttpContentType.MULTIPART_MIXED));
     }
+    throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(HttpContentType.MULTIPART_MIXED));
   }
 
   private static String trimQuota(String boundary) {
@@ -225,7 +229,7 @@ public class BatchParserCommon {
 
     return boundary;
   }
-  
+
   public static Map<String, List<String>> parseQueryParameter(final Line httpRequest)
{
     Map<String, List<String>> queryParameter = new HashMap<String, List<String>>();
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7df31f55/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
index c07c06f..a0e05c5 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchTransformatorCommon.java
@@ -47,7 +47,7 @@ public class BatchTransformatorCommon {
     if (contentTypes.size() == 0) {
       throw new BatchException(BatchException.MISSING_CONTENT_TYPE);
     }
-    if (!headers.isHeaderMatching(HttpHeaders.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY)
+    if (!headers.isHeaderMatching(HttpHeaders.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_MIXED)
       & !headers.isHeaderMatching(HttpHeaders.CONTENT_TYPE, BatchParserCommon.PATTERN_CONTENT_TYPE_APPLICATION_HTTP))
{
       throw new BatchException(BatchException.INVALID_CONTENT_TYPE.addContent(
           HttpContentType.MULTIPART_MIXED + " or " + HttpContentType.APPLICATION_HTTP));

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7df31f55/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
index 447049e..69ca695 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestParserTest.java
@@ -354,7 +354,20 @@ public class BatchRequestParserTest {
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
-
+  
+  @Test
+  public void testContentTypeCharset() throws BatchException {
+    final String contentType = "multipart/mixed; charset=UTF-8;boundary=batch_14d1-b293-b99a";
+    final String batch = ""
+                    + "--batch_14d1-b293-b99a" + CRLF
+                    + GET_REQUEST
+                    + "--batch_14d1-b293-b99a--";
+    final BatchParser parser = new BatchParser(contentType, batchProperties, true);
+    final List<BatchRequestPart> parts = parser.parseBatchRequest(new ByteArrayInputStream(batch.getBytes()));
+    
+    assertEquals(1, parts.size());
+  }
+  
   @Test(expected = BatchException.class)
   public void testNoContentType() throws BatchException {
     String batch = "--batch_8194-cf13-1f56" + CRLF

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/7df31f55/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/HeaderTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/HeaderTest.java
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/HeaderTest.java
index 9561567..e630a54 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/HeaderTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/HeaderTest.java
@@ -76,7 +76,7 @@ public class HeaderTest {
     Header header = new Header(1);
     header.addHeader(HttpHeaders.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + ";boundary=123",
1);
 
-    assertTrue(header.isHeaderMatching(HttpHeaders.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY));
+    assertTrue(header.isHeaderMatching(HttpHeaders.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_MIXED));
   }
 
   @Test
@@ -110,7 +110,7 @@ public class HeaderTest {
   public void testMatcherNoHeader() {
     Header header = new Header(1);
 
-    assertFalse(header.isHeaderMatching(HttpHeaders.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY));
+    assertFalse(header.isHeaderMatching(HttpHeaders.CONTENT_TYPE,  BatchParserCommon.PATTERN_MULTIPART_MIXED));
   }
 
   @Test


Mime
View raw message