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/10/14 15:35:15 UTC

git commit: [OLINGO-436] Fix: blank lines must contain CRLF

Repository: olingo-odata2
Updated Branches:
  refs/heads/master 24119a786 -> 5a416b9e6


[OLINGO-436] Fix: blank lines must contain CRLF

Signed-off-by: Christian Amend <ch...@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/5a416b9e
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/5a416b9e
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/5a416b9e

Branch: refs/heads/master
Commit: 5a416b9e65d75655b1541f1f80af9459fa62aa2f
Parents: 24119a7
Author: Christian Holzer <c....@sap.com>
Authored: Tue Oct 14 15:06:02 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Tue Oct 14 15:34:27 2014 +0200

----------------------------------------------------------------------
 .../odata2/core/batch/v2/BatchParserCommon.java |  2 +-
 .../core/batch/BatchRequestParserTest.java      | 18 +++++-
 .../src/test/resources/batchLarge.batch         |  3 +
 .../olingo/odata2/fit/basic/BasicBatchTest.java | 66 ++++++++++----------
 .../apache/olingo/odata2/fit/ref/BatchTest.java |  4 +-
 .../odata2/testutil/helper/StringHelper.java    | 19 +++++-
 6 files changed, 74 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a416b9e/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 62f03c2..c2751ee 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
@@ -193,7 +193,7 @@ public class BatchParserCommon {
 
   public static void consumeBlankLine(final List<Line> remainingMessage, final boolean isStrict)
       throws BatchException {
-    if (remainingMessage.size() > 0 && "".equals(remainingMessage.get(0).toString().trim())) {
+    if (remainingMessage.size() > 0 && remainingMessage.get(0).toString().matches("\\s*\r\n\\s*")) {
       remainingMessage.remove(0);
     } else {
       if (isStrict) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a416b9e/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 1a374a5..447049e 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
@@ -389,7 +389,21 @@ public class BatchRequestParserTest {
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
-
+  
+  @Test(expected = BatchException.class)
+  public void testGetRequestMissingCRLF() throws BatchException {
+    String batch = "--batch_8194-cf13-1f56" + CRLF
+        + MIME_HEADERS
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        //+ CRLF  // Belongs to the GET request
+        + CRLF    //Belongs to the 
+        + "--batch_8194-cf13-1f56--";
+    
+    parseInvalidBatchBody(batch);
+  }
+  
   @Test(expected = BatchException.class)
   public void testInvalidMethodForBatch() throws BatchException {
     String batch = "--batch_8194-cf13-1f56" + CRLF
@@ -961,6 +975,7 @@ public class BatchRequestParserTest {
         + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + CRLF
         + "Content-Id: BBB" + CRLF
         + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
         + CRLF
@@ -1074,6 +1089,7 @@ public class BatchRequestParserTest {
         + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + CRLF
         + "Content-Id: BBB" + CRLF
         + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
         + CRLF

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a416b9e/odata2-lib/odata-core/src/test/resources/batchLarge.batch
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/resources/batchLarge.batch b/odata2-lib/odata-core/src/test/resources/batchLarge.batch
index 6d0fc6e..faadea1 100644
--- a/odata2-lib/odata-core/src/test/resources/batchLarge.batch
+++ b/odata2-lib/odata-core/src/test/resources/batchLarge.batch
@@ -12,6 +12,7 @@ Content-Type: application/atom+xml
 Accept-Encoding: gzip,deflate
 Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
 
+
 --batch_8194-cf13-1f56
 Content-Type: application/http
 Content-Transfer-Encoding: binary
@@ -26,6 +27,7 @@ Content-Type: application/atom+xml
 Accept-Encoding: gzip,deflate
 Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
 
+
 --batch_8194-cf13-1f56
 Content-Type: application/http
 Content-Transfer-Encoding: binary
@@ -40,6 +42,7 @@ Content-Type: application/atom+xml
 Accept-Encoding: gzip,deflate
 Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
 
+
 --batch_8194-cf13-1f56
 Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a416b9e/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
index d440635..b57e1e6 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
@@ -70,44 +70,44 @@ public class BasicBatchTest extends AbstractBasicTest {
     super(servletType);
   }
 
-  private static final String LF = "\n";
+  private static final String CRLF = "\r\n";
   private static final String REG_EX_BOUNDARY =
       "(([a-zA-Z0-9_\\-\\.'\\+]{1,70})|\"([a-zA-Z0-9_\\-\\.'\\+\\s\\(\\),/:=\\?]" +
           "{1,69}[a-zA-Z0-9_\\-\\.'\\+\\(\\),/:=\\?])\")";
   private static final String REG_EX = "multipart/mixed;\\s*boundary=" + REG_EX_BOUNDARY + "\\s*";
 
   private static final String REQUEST_PAYLOAD =
-      "--batch_98c1-8b13-36bb" + LF
-          + "Content-Type: application/http" + LF
-          + "Content-Transfer-Encoding: binary" + LF
-          + "Content-Id: mimeHeaderContentId1" + LF
-          + LF
-          + "GET Employees('1')/EmployeeName HTTP/1.1" + LF
-          + "Host: localhost:19000" + LF
-          + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + LF
-          + "Accept-Language: en" + LF
-          + "MaxDataServiceVersion: 2.0" + LF
-          + "Content-Id: requestHeaderContentId1" + LF
-          + LF
-          + LF
-          + "--batch_98c1-8b13-36bb" + LF
-          + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + LF
-          + LF
-          + "--changeset_f980-1cb6-94dd" + LF
-          + "Content-Type: application/http" + LF
-          + "Content-Transfer-Encoding: binary" + LF
-          + "Content-Id: mimeHeaderContentId2" + LF
-          + LF
-          + "PUT Employees('1')/EmployeeName HTTP/1.1" + LF
-          + "Host: localhost:19000" + LF
-          + "Content-Type: application/json;odata=verbose" + LF
-          + "MaxDataServiceVersion: 2.0" + LF
-          + "Content-Id: requestHeaderContentId2" + LF
-          + LF
-          + "{\"EmployeeName\":\"Walter Winter MODIFIED\"}" + LF
-          + LF
-          + "--changeset_f980-1cb6-94dd--" + LF
-          + LF
+      "--batch_98c1-8b13-36bb" + CRLF
+          + "Content-Type: application/http" + CRLF
+          + "Content-Transfer-Encoding: binary" + CRLF
+          + "Content-Id: mimeHeaderContentId1" + CRLF
+          + CRLF
+          + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
+          + "Host: localhost:19000" + CRLF
+          + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF
+          + "Accept-Language: en" + CRLF
+          + "MaxDataServiceVersion: 2.0" + CRLF
+          + "Content-Id: requestHeaderContentId1" + CRLF
+          + CRLF
+          + CRLF
+          + "--batch_98c1-8b13-36bb" + CRLF
+          + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
+          + CRLF
+          + "--changeset_f980-1cb6-94dd" + CRLF
+          + "Content-Type: application/http" + CRLF
+          + "Content-Transfer-Encoding: binary" + CRLF
+          + "Content-Id: mimeHeaderContentId2" + CRLF
+          + CRLF
+          + "PUT Employees('1')/EmployeeName HTTP/1.1" + CRLF
+          + "Host: localhost:19000" + CRLF
+          + "Content-Type: application/json;odata=verbose" + CRLF
+          + "MaxDataServiceVersion: 2.0" + CRLF
+          + "Content-Id: requestHeaderContentId2" + CRLF
+          + CRLF
+          + "{\"EmployeeName\":\"Walter Winter MODIFIED\"}" + CRLF
+          + CRLF
+          + "--changeset_f980-1cb6-94dd--" + CRLF
+          + CRLF
           + "--batch_98c1-8b13-36bb--";
 
   @Test
@@ -138,7 +138,7 @@ public class BasicBatchTest extends AbstractBasicTest {
   public void testBatchInvalidContentTypeForPut() throws Exception {
     final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + "$batch"));
     post.setHeader("Content-Type", "multipart/mixed;boundary=batch_98c1-8b13-36bb");
-    String replacedEntity = REQUEST_PAYLOAD.replace("Content-Type: application/json;odata=verbose" + LF, "");
+    String replacedEntity = REQUEST_PAYLOAD.replace("Content-Type: application/json;odata=verbose" + CRLF, "");
     HttpEntity entity = new StringEntity(replacedEntity);
     post.setEntity(entity);
     HttpResponse response = getHttpClient().execute(post);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a416b9e/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java
index f4e81f0..de5f291 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java
@@ -130,7 +130,7 @@ public class BatchTest extends AbstractRefTest {
   private String execute(final String batchResource) throws Exception {
     HttpResponse response = execute(batchResource, "batch_123");
 
-    String responseBody = StringHelper.inputStreamToString(response.getEntity().getContent(), true);
+    String responseBody = StringHelper.inputStreamToStringCRLFLineBreaks(response.getEntity().getContent());
     return responseBody;
   }
 
@@ -139,7 +139,7 @@ public class BatchTest extends AbstractRefTest {
     final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + "$batch"));
     post.setHeader("Content-Type", "multipart/mixed;boundary=" + boundary);
 
-    String body = StringHelper.inputStreamToString(this.getClass().getResourceAsStream(batchResource), true);
+    String body = StringHelper.inputStreamToStringCRLFLineBreaks(this.getClass().getResourceAsStream(batchResource));
     HttpEntity entity = new StringEntity(body);
     post.setEntity(entity);
     HttpResponse response = getHttpClient().execute(post);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/5a416b9e/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/helper/StringHelper.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/helper/StringHelper.java b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/helper/StringHelper.java
index f47bde6..2fd6f8a 100644
--- a/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/helper/StringHelper.java
+++ b/odata2-lib/odata-testutil/src/main/java/org/apache/olingo/odata2/testutil/helper/StringHelper.java
@@ -77,7 +77,7 @@ public class StringHelper {
       BufferedReader br = new BufferedReader(new StringReader(asString()));
       StringBuilder sb = new StringBuilder(br.readLine());
       String line = br.readLine();
-      while(line != null) {
+      while (line != null) {
         sb.append(separator).append(line);
         line = br.readLine();
       }
@@ -143,6 +143,23 @@ public class StringHelper {
     return result;
   }
 
+  public static String inputStreamToStringCRLFLineBreaks(final InputStream in) throws IOException {
+    final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
+    final StringBuilder stringBuilder = new StringBuilder();
+    String line = null;
+
+    while ((line = bufferedReader.readLine()) != null) {
+      stringBuilder.append(line);
+      stringBuilder.append("\r\n");
+    }
+
+    bufferedReader.close();
+
+    final String result = stringBuilder.toString();
+
+    return result;
+  }
+
   public static int countLines(final String content) {
     return countLines(content, "\r\n");
   }