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:55 UTC

[35/50] [abbrv] git commit: [OLINGO-379] Take line endings into account

[OLINGO-379] Take line endings into account


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: f1b9134c6835714fab0f7f05928be5af99c133ae
Parents: 6b73a91
Author: Christian Amend <ch...@apache.org>
Authored: Fri Jul 25 15:21:40 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Jul 25 15:21:40 2014 +0200

----------------------------------------------------------------------
 .../odata2/core/batch/BatchResponseParser.java  |  26 +-
 .../core/batch/BatchRequestParserTest.java      | 352 +++++++++----------
 .../core/batch/BatchResponseParserTest.java     | 341 ++++++++++--------
 .../BatchResponseWithAdditionalLineEnding.batch |  12 +
 .../BatchResponseWithLinesInBodyWin.batch       |  16 +
 5 files changed, 421 insertions(+), 326 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f1b9134c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java
index b488ce2..e44e2e6 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java
@@ -38,7 +38,7 @@ import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
 
 public class BatchResponseParser {
 
-  private static final String LF = "\n";
+  private static final String CRLF = "\r\n";
   private static final String REG_EX_OPTIONAL_WHITESPACE = "\\s?";
   private static final String REG_EX_ZERO_OR_MORE_WHITESPACES = "\\s*";
   private static final String ANY_CHARACTERS = ".*";
@@ -71,7 +71,7 @@ public class BatchResponseParser {
 
   public List<BatchSingleResponse> parse(final InputStream in) throws BatchException {
     Scanner scanner = new Scanner(in, BatchHelper.DEFAULT_ENCODING);
-    scanner.useDelimiter(LF);
+    scanner.useDelimiter(CRLF);
     List<BatchSingleResponse> responseList;
     try {
       responseList = Collections.unmodifiableList(parseBatchResponse(scanner));
@@ -199,10 +199,14 @@ public class BatchResponseParser {
 
       Map<String, String> headers = parseResponseHeaders(scanner);
       parseNewLine(scanner);
+      String body = parseBody(scanner);
       String contentLengthHeader = getHeaderValue(headers, HttpHeaders.CONTENT_LENGTH);
-      String body =
-          (contentLengthHeader != null) ? parseBody(scanner, Integer.parseInt(contentLengthHeader))
-              : parseBody(scanner);
+      if(contentLengthHeader != null){
+        int contentLength = Integer.parseInt(contentLengthHeader);
+        if(contentLength < body.length()){
+          body = body.substring(0, contentLength);
+        }
+      }
       response.setStatusCode(statusCode);
       response.setStatusInfo(statusInfo);
       response.setHeaders(headers);
@@ -280,14 +284,10 @@ public class BatchResponseParser {
   private String parseBody(final Scanner scanner) {
     StringBuilder body = null;
     while (scanner.hasNext() && !scanner.hasNext(REG_EX_ANY_BOUNDARY_STRING)) {
-      if (!scanner.hasNext(REG_EX_ZERO_OR_MORE_WHITESPACES)) {
-        if (body == null) {
-          body = new StringBuilder(scanner.next());
-        } else {
-          body.append(LF).append(scanner.next());
-        }
+      if (body == null) {
+        body = new StringBuilder(scanner.next());
       } else {
-        scanner.next();
+        body.append(CRLF).append(scanner.next());
       }
       currentLineNumber++;
     }
@@ -305,7 +305,7 @@ public class BatchResponseParser {
         if (body == null) {
           body = new StringBuilder(nextLine);
         } else {
-          body.append(LF).append(nextLine);
+          body.append(CRLF).append(nextLine);
         }
       } else {
         scanner.next();

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f1b9134c/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 e1315fb..f9b19b9 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
@@ -48,19 +48,19 @@ import org.junit.Test;
  */
 public class BatchRequestParserTest {
 
-  private static final String LF = "\r\n";
+  private static final String CRLF = "\r\n";
   private static final String CONTENT_ID_REFERENCE = "NewEmployee";
   private static final String PUT_MIME_HEADER_CONTENT_ID = "BBB_MIMEPART1";
   private static final String PUT_REQUEST_HEADER_CONTENT_ID = "BBB_REQUEST1";
   private static final String SERVICE_ROOT = "http://localhost/odata/";
   private static EntityProviderBatchProperties batchProperties;
   private static final String contentType = "multipart/mixed;boundary=batch_8194-cf13-1f56";
-  private static final String MIME_HEADERS = "Content-Type: application/http" + LF
-      + "Content-Transfer-Encoding: binary" + LF;
-  private static final String GET_REQUEST = MIME_HEADERS + LF
-      + "GET Employees('1')/EmployeeName HTTP/1.1" + LF
-      + LF
-      + LF;
+  private static final String MIME_HEADERS = "Content-Type: application/http" + CRLF
+      + "Content-Transfer-Encoding: binary" + CRLF;
+  private static final String GET_REQUEST = MIME_HEADERS + CRLF
+      + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
+      + CRLF
+      + CRLF;
 
   @BeforeClass
   public static void setProperties() throws URISyntaxException {
@@ -131,29 +131,29 @@ public class BatchRequestParserTest {
       throw new IOException("Requested file '" + fileName + "' was not found.");
     }
     String content = StringHelper.inputStreamToString(contentInputStream);
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "GET Employees?$filter=Age%20gt%2040 HTTP/1.1" + LF
-        + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + LF
-        + "MaxDataServiceVersion: 2.0" + LF
-        + LF
-        + LF
-        + "--batch_8194-cf13-1f56" + 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: 1" + LF
-        + LF
-        + "POST Employees HTTP/1.1" + LF
-        + "Content-length: 100000" + LF
-        + "Content-type: application/octet-stream" + LF
-        + LF
-        + content + LF
-        + LF
-        + "--changeset_f980-1cb6-94dd--" + LF
+        + CRLF
+        + "GET Employees?$filter=Age%20gt%2040 HTTP/1.1" + CRLF
+        + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF
+        + "MaxDataServiceVersion: 2.0" + CRLF
+        + CRLF
+        + CRLF
+        + "--batch_8194-cf13-1f56" + 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: 1" + CRLF
+        + CRLF
+        + "POST Employees HTTP/1.1" + CRLF
+        + "Content-length: 100000" + CRLF
+        + "Content-type: application/octet-stream" + CRLF
+        + CRLF
+        + content + CRLF
+        + CRLF
+        + "--changeset_f980-1cb6-94dd--" + CRLF
         + "--batch_8194-cf13-1f56--";
     List<BatchRequestPart> BatchRequestParts = parse(batch);
     for (BatchRequestPart object : BatchRequestParts) {
@@ -188,20 +188,20 @@ public class BatchRequestParserTest {
       throw new IOException("Requested file '" + fileName + "' was not found.");
     }
     StringHelper.inputStreamToString(contentInputStream);
-    String batch = LF
-        + "--batch_8194-cf13-1f56" + LF
-        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + LF
-        + LF
-        + "--changeset_f980-1cb6-94dd" + LF
+    String batch = CRLF
+        + "--batch_8194-cf13-1f56" + CRLF
+        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
+        + CRLF
+        + "--changeset_f980-1cb6-94dd" + CRLF
         + MIME_HEADERS
-        + LF
-        + "POST Employees('2') HTTP/1.1" + LF
-        + "Content-Length: 100" + LF
-        + "Content-Type: application/octet-stream" + LF
-        + LF
-        + LF
-        + "--changeset_f980-1cb6-94dd--" + LF
-        + LF
+        + CRLF
+        + "POST Employees('2') HTTP/1.1" + CRLF
+        + "Content-Length: 100" + CRLF
+        + "Content-Type: application/octet-stream" + CRLF
+        + CRLF
+        + CRLF
+        + "--changeset_f980-1cb6-94dd--" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     List<BatchRequestPart> batchRequestParts = parse(batch);
     for (BatchRequestPart object : batchRequestParts) {
@@ -221,7 +221,7 @@ public class BatchRequestParserTest {
   public void testBoundaryParameterWithQuotas() throws BatchException {
     String contentType = "multipart/mixed; boundary=\"batch_1.2+34:2j)0?\"";
 
-    String batch = "--batch_1.2+34:2j)0?" + LF
+    String batch = "--batch_1.2+34:2j)0?" + CRLF
         + GET_REQUEST
         + "--batch_1.2+34:2j)0?--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
@@ -235,7 +235,7 @@ public class BatchRequestParserTest {
   public void testBatchWithInvalidContentType() throws BatchException {
     String invalidContentType = "multipart;boundary=batch_1740-bb84-2f7f";
 
-    String batch = "--batch_1740-bb84-2f7f" + LF
+    String batch = "--batch_1740-bb84-2f7f" + CRLF
         + GET_REQUEST
         + "--batch_1740-bb84-2f7f--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
@@ -246,7 +246,7 @@ public class BatchRequestParserTest {
   @Test(expected = BatchException.class)
   public void testBatchWithoutBoundaryParameter() throws BatchException {
     String invalidContentType = "multipart/mixed";
-    String batch = "--batch_1740-bb84-2f7f" + LF
+    String batch = "--batch_1740-bb84-2f7f" + CRLF
         + GET_REQUEST
         + "--batch_1740-bb84-2f7f--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
@@ -257,7 +257,7 @@ public class BatchRequestParserTest {
   @Test(expected = BatchException.class)
   public void testBoundaryParameterWithoutQuota() throws BatchException {
     String invalidContentType = "multipart;boundary=batch_1740-bb:84-2f7f";
-    String batch = "--batch_1740-bb:84-2f7f" + LF
+    String batch = "--batch_1740-bb:84-2f7f" + CRLF
         + GET_REQUEST
         + "--batch_1740-bb:84-2f7f--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
@@ -267,7 +267,7 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testWrongBoundaryString() throws BatchException {
-    String batch = "--batch_8194-cf13-1f5" + LF
+    String batch = "--batch_8194-cf13-1f5" + CRLF
         + GET_REQUEST
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
@@ -275,9 +275,9 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testBoundaryWithoutHyphen() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + GET_REQUEST
-        + "batch_8194-cf13-1f56" + LF
+        + "batch_8194-cf13-1f56" + CRLF
         + GET_REQUEST
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
@@ -285,7 +285,7 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testNoBoundaryString() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + GET_REQUEST
         // + no boundary string
         + GET_REQUEST
@@ -295,54 +295,54 @@ public class BatchRequestParserTest {
 
   @Test(expected = BatchException.class)
   public void testBatchBoundaryEqualsChangeSetBoundary() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
-        + "Content-Type: multipart/mixed;boundary=batch_8194-cf13-1f56" + LF
-        + LF
-        + "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
+        + "Content-Type: multipart/mixed;boundary=batch_8194-cf13-1f56" + CRLF
+        + CRLF
+        + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "PUT Employees('2')/EmployeeName HTTP/1.1" + LF
-        + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + LF
-        + "Content-Type: application/json;odata=verbose" + LF
-        + "MaxDataServiceVersion: 2.0" + LF
-        + LF
-        + "{\"EmployeeName\":\"Frederic Fall MODIFIED\"}" + LF
-        + LF
+        + CRLF
+        + "PUT Employees('2')/EmployeeName HTTP/1.1" + CRLF
+        + "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF
+        + "Content-Type: application/json;odata=verbose" + CRLF
+        + "MaxDataServiceVersion: 2.0" + CRLF
+        + CRLF
+        + "{\"EmployeeName\":\"Frederic Fall MODIFIED\"}" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoContentType() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + LF
-        + "GET Employees('1')/EmployeeName HTTP/1.1" + LF
-        + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testMimeHeaderContentType() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
-        + "Content-Type: text/plain" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + LF
-        + "GET Employees('1')/EmployeeName HTTP/1.1" + LF
-        + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
+        + "Content-Type: text/plain" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testMimeHeaderEncoding() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: 8bit" + LF
-        + LF
-        + "GET Employees('1')/EmployeeName HTTP/1.1" + LF
-        + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: 8bit" + CRLF
+        + CRLF
+        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
@@ -350,113 +350,113 @@ public class BatchRequestParserTest {
   @Test(expected = BatchException.class)
   @Ignore("What should here throw an exception")
   public void testMimeHeaderContentId() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + "Content-ID: 1" + LF
-        + LF
-        + "GET Employees('1')/EmployeeName HTTP/1.1" + LF
-        + LF
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testInvalidMethodForBatch() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "POST Employees('1')/EmployeeName HTTP/1.1" + LF
-        + LF
+        + CRLF
+        + "POST Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoMethod() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + /* GET */"Employees('1')/EmployeeName HTTP/1.1" + LF
-        + LF
+        + CRLF
+        + /* GET */"Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testInvalidMethodForChangeset() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
-        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + LF
-        + LF
-        + "--changeset_f980-1cb6-94dd" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
+        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
+        + CRLF
+        + "--changeset_f980-1cb6-94dd" + CRLF
         + MIME_HEADERS
-        + LF
-        + "GET Employees('2')/EmployeeName HTTP/1.1" + LF
-        + "Content-Type: application/json;odata=verbose" + LF
-        + "MaxDataServiceVersion: 2.0" + LF
-        + LF
+        + CRLF
+        + "GET Employees('2')/EmployeeName HTTP/1.1" + CRLF
+        + "Content-Type: application/json;odata=verbose" + CRLF
+        + "MaxDataServiceVersion: 2.0" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testInvalidChangeSetBoundary() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
-        + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + LF
-        + LF
-        + "--changeset_f980-1cb6-94d"/* +"d" */+ LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
+        + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
+        + CRLF
+        + "--changeset_f980-1cb6-94d"/* +"d" */+ CRLF
         + MIME_HEADERS
-        + LF
-        + "POST Employees('2') HTTP/1.1" + LF
-        + "Content-Type: application/json;odata=verbose" + LF
-        + "MaxDataServiceVersion: 2.0" + LF
-        + LF
+        + CRLF
+        + "POST Employees('2') HTTP/1.1" + CRLF
+        + "Content-Type: application/json;odata=verbose" + CRLF
+        + "MaxDataServiceVersion: 2.0" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoCloseDelimiter() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + GET_REQUEST;
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoCloseDelimiter2() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "GET Employees('1')/EmployeeName HTTP/1.1" + LF;
+        + CRLF
+        + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF;
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testInvalidUri() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "GET http://localhost/aa/odata/Employees('1')/EmployeeName HTTP/1.1" + LF
-        + LF
-        + LF
+        + CRLF
+        + "GET http://localhost/aa/odata/Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testUriWithAbsolutePath() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "GET /odata/Employees('1')/EmployeeName HTTP/1.1" + LF
-        + LF
-        + LF
+        + CRLF
+        + "GET /odata/Employees('1')/EmployeeName HTTP/1.1" + CRLF
+        + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     parseInvalidBatchBody(batch);
   }
 
   @Test(expected = BatchException.class)
   public void testNoCloseDelimiter3() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF + GET_REQUEST + "--batch_8194-cf13-1f56-"/* no hash */;
+    String batch = "--batch_8194-cf13-1f56" + CRLF + GET_REQUEST + "--batch_8194-cf13-1f56-"/* no hash */;
     parseInvalidBatchBody(batch);
   }
 
@@ -464,20 +464,20 @@ public class BatchRequestParserTest {
   public void testAcceptHeaders() throws BatchException, URISyntaxException {
     String batch =
         "--batch_8194-cf13-1f56"
-            + LF
+            + CRLF
             + MIME_HEADERS
-            + LF
+            + CRLF
             + "GET Employees('2')/EmployeeName HTTP/1.1"
-            + LF
+            + CRLF
             + "Content-Length: 100000"
-            + LF
+            + CRLF
             + "Content-Type: application/json;odata=verbose"
-            + LF
+            + CRLF
             + "Accept: application/xml;q=0.3, application/atomsvc+xml;q=0.8, " +
             "application/json;odata=verbose;q=0.5, */*;q=0.001"
-            + LF
-            + LF
-            + LF
+            + CRLF
+            + CRLF
+            + CRLF
             + "--batch_8194-cf13-1f56--";
     List<BatchRequestPart> batchRequestParts = parse(batch);
     for (BatchRequestPart multipart : batchRequestParts) {
@@ -496,15 +496,15 @@ public class BatchRequestParserTest {
 
   @Test
   public void testAcceptHeaders2() throws BatchException, URISyntaxException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "GET Employees('2')/EmployeeName HTTP/1.1" + LF
-        + "Content-Length: 100000" + LF
-        + "Content-Type: application/json;odata=verbose" + LF
-        + "Accept: */*;q=0.5, application/json;odata=verbose;q=1.0,application/atom+xml" + LF
-        + LF
-        + LF
+        + CRLF
+        + "GET Employees('2')/EmployeeName HTTP/1.1" + CRLF
+        + "Content-Length: 100000" + CRLF
+        + "Content-Type: application/json;odata=verbose" + CRLF
+        + "Accept: */*;q=0.5, application/json;odata=verbose;q=1.0,application/atom+xml" + CRLF
+        + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     List<BatchRequestPart> batchRequestParts = parse(batch);
     for (BatchRequestPart multipart : batchRequestParts) {
@@ -524,15 +524,15 @@ public class BatchRequestParserTest {
 
   @Test
   public void testAcceptHeaders3() throws BatchException, URISyntaxException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "GET Employees('2')/EmployeeName HTTP/1.1" + LF
-        + "Content-Length: 100000" + LF
-        + "Content-Type: application/json;odata=verbose" + LF
-        + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + LF
-        + LF
-        + LF
+        + CRLF
+        + "GET Employees('2')/EmployeeName HTTP/1.1" + CRLF
+        + "Content-Length: 100000" + CRLF
+        + "Content-Type: application/json;odata=verbose" + CRLF
+        + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + CRLF
+        + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     List<BatchRequestPart> batchRequestParts = parse(batch);
     for (BatchRequestPart multipart : batchRequestParts) {
@@ -554,36 +554,36 @@ public class BatchRequestParserTest {
 
   @Test
   public void testContentId() throws BatchException {
-    String batch = "--batch_8194-cf13-1f56" + LF
+    String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
-        + LF
-        + "GET Employees HTTP/1.1" + LF
-        + "accept: */*,application/atom+xml,application/atomsvc+xml,application/xml" + LF
-        + "Content-Id: BBB" + LF
-        + LF + LF
-        + "--batch_8194-cf13-1f56" + LF
-        + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + LF
-        + LF
-        + "--changeset_f980-1cb6-94dd" + LF
+        + CRLF
+        + "GET Employees HTTP/1.1" + CRLF
+        + "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
+        + "--changeset_f980-1cb6-94dd" + CRLF
         + MIME_HEADERS
-        + "Content-Id: " + CONTENT_ID_REFERENCE + LF
-        + LF
-        + "POST Employees HTTP/1.1" + LF
-        + "Content-type: application/octet-stream" + LF
-        + LF
-        + "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA" + LF
-        + LF
-        + "--changeset_f980-1cb6-94dd" + LF
+        + "Content-Id: " + CONTENT_ID_REFERENCE + CRLF
+        + CRLF
+        + "POST Employees HTTP/1.1" + CRLF
+        + "Content-type: application/octet-stream" + CRLF
+        + CRLF
+        + "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAA" + CRLF
+        + CRLF
+        + "--changeset_f980-1cb6-94dd" + CRLF
         + MIME_HEADERS
-        + "Content-ID: " + PUT_MIME_HEADER_CONTENT_ID + LF
-        + LF
-        + "PUT $" + CONTENT_ID_REFERENCE + "/EmployeeName HTTP/1.1" + LF
-        + "Content-Type: application/json;odata=verbose" + LF
-        + "Content-Id:" + PUT_REQUEST_HEADER_CONTENT_ID + LF
-        + LF
-        + "{\"EmployeeName\":\"Peter Fall\"}" + LF
-        + "--changeset_f980-1cb6-94dd--" + LF
-        + LF
+        + "Content-ID: " + PUT_MIME_HEADER_CONTENT_ID + CRLF
+        + CRLF
+        + "PUT $" + CONTENT_ID_REFERENCE + "/EmployeeName HTTP/1.1" + CRLF
+        + "Content-Type: application/json;odata=verbose" + CRLF
+        + "Content-Id:" + PUT_REQUEST_HEADER_CONTENT_ID + CRLF
+        + CRLF
+        + "{\"EmployeeName\":\"Peter Fall\"}" + CRLF
+        + "--changeset_f980-1cb6-94dd--" + CRLF
+        + CRLF
         + "--batch_8194-cf13-1f56--";
     InputStream in = new ByteArrayInputStream(batch.getBytes());
     BatchRequestParser parser = new BatchRequestParser(contentType, batchProperties);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f1b9134c/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
index 592c054..87d8cac 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
@@ -29,25 +29,28 @@ import org.apache.olingo.odata2.api.batch.BatchException;
 import org.apache.olingo.odata2.api.client.batch.BatchSingleResponse;
 import org.apache.olingo.odata2.api.commons.HttpContentType;
 import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
 import org.junit.Test;
 
 public class BatchResponseParserTest {
 
-  private static final String LF = "\r\n";
+  private static final String CRLF = "\r\n";
+  private static final String LF = "\n";
+
 
   @Test
   public void testSimpleBatchResponse() throws BatchException {
-    String getResponse = "--batch_123" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + "Content-ID: 1" + LF
-        + LF
-        + "HTTP/1.1 200 OK" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + "Content-Type: text/plain;charset=utf-8" + LF
-        + "Content-length: 22" + LF
-        + LF
-        + "Frederic Fall MODIFIED" + LF
+    String getResponse = "--batch_123" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "HTTP/1.1 200 OK" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + "Content-Type: text/plain;charset=utf-8" + CRLF
+        + "Content-length: 22" + CRLF
+        + CRLF
+        + "Frederic Fall MODIFIED" + CRLF
         + "--batch_123--";
 
     InputStream in = new ByteArrayInputStream(getResponse.getBytes());
@@ -84,20 +87,20 @@ public class BatchResponseParserTest {
 
   @Test
   public void testResponseToChangeSet() throws BatchException {
-    String putResponse = "--batch_123" + LF
-        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
-        + LF
-        + "--changeset_12ks93js84d" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + "Content-ID: 1" + LF
-        + LF
-        + "HTTP/1.1 204 No Content" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + LF
-        + LF
-        + "--changeset_12ks93js84d--" + LF
-        + LF
+    String putResponse = "--batch_123" + CRLF
+        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "HTTP/1.1 204 No Content" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d--" + CRLF
+        + CRLF
         + "--batch_123--";
 
     InputStream in = new ByteArrayInputStream(putResponse.getBytes());
@@ -112,19 +115,19 @@ public class BatchResponseParserTest {
 
   @Test(expected = BatchException.class)
   public void testInvalidMimeHeader() throws BatchException {
-    String putResponse = "--batch_123" + LF
-        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
-        + LF
-        + "--changeset_12ks93js84d" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: 7bit" + LF // Content-Transfer-Encoding must be binary
-        + LF
-        + "HTTP/1.1 No Content" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + LF
-        + LF
-        + "--changeset_12ks93js84d--" + LF
-        + LF
+    String putResponse = "--batch_123" + CRLF
+        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: 7bit" + CRLF // Content-Transfer-Encoding must be binary
+        + CRLF
+        + "HTTP/1.1 No Content" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d--" + CRLF
+        + CRLF
         + "--batch_123--";
 
     parseInvalidBatchResponseBody(putResponse);
@@ -132,17 +135,17 @@ public class BatchResponseParserTest {
 
   @Test(expected = BatchException.class)
   public void testMissingMimeHeader() throws BatchException {
-    String putResponse = "--batch_123" + LF
-        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
-        + LF
-        + "--changeset_12ks93js84d" + LF
-        + LF
-        + "HTTP/1.1 No Content" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + LF
-        + LF
-        + "--changeset_12ks93js84d--" + LF
-        + LF
+    String putResponse = "--batch_123" + CRLF
+        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d" + CRLF
+        + CRLF
+        + "HTTP/1.1 No Content" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d--" + CRLF
+        + CRLF
         + "--batch_123--";
 
     parseInvalidBatchResponseBody(putResponse);
@@ -150,19 +153,19 @@ public class BatchResponseParserTest {
 
   @Test(expected = BatchException.class)
   public void testInvalidContentType() throws BatchException {
-    String putResponse = "--batch_123" + LF
-        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + LF // Missing boundary parameter
-        + LF
-        + "--changeset_12ks93js84d" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + LF
-        + "HTTP/1.1 No Content" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + LF
-        + LF
-        + "--changeset_12ks93js84d--" + LF
-        + LF
+    String putResponse = "--batch_123" + CRLF
+        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + CRLF // Missing boundary parameter
+        + CRLF
+        + "--changeset_12ks93js84d" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "HTTP/1.1 No Content" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d--" + CRLF
+        + CRLF
         + "--batch_123--";
 
     parseInvalidBatchResponseBody(putResponse);
@@ -170,19 +173,19 @@ public class BatchResponseParserTest {
 
   @Test(expected = BatchException.class)
   public void testInvalidStatusLine() throws BatchException {
-    String putResponse = "--batch_123" + LF
-        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
-        + LF
-        + "--changeset_12ks93js84d" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + LF
-        + "HTTP/1.1 No Content" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + LF
-        + LF
-        + "--changeset_12ks93js84d--" + LF
-        + LF
+    String putResponse = "--batch_123" + CRLF
+        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "HTTP/1.1 No Content" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d--" + CRLF
+        + CRLF
         + "--batch_123--";
 
     parseInvalidBatchResponseBody(putResponse);
@@ -191,84 +194,148 @@ public class BatchResponseParserTest {
 
   @Test(expected = BatchException.class)
   public void testMissingCloseDelimiter() throws BatchException {
-    String putResponse = "--batch_123" + LF
-        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
-        + LF
-        + "--changeset_12ks93js84d" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + LF
-        + "HTTP/1.1 204 No Content" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + LF
-        + LF
-        + "--changeset_12ks93js84d--" + LF
-        + LF;
+    String putResponse = "--batch_123" + CRLF
+        + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "HTTP/1.1 204 No Content" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + CRLF
+        + CRLF
+        + "--changeset_12ks93js84d--" + CRLF
+        + CRLF;
 
     parseInvalidBatchResponseBody(putResponse);
 
   }
 
-  @Test(expected = BatchException.class)
-  public void testInvalidEnteredContentLength() throws BatchException {
-    String getResponse = "--batch_123" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + "Content-ID: 1" + LF
-        + LF
-        + "HTTP/1.1 200 OK" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + "Content-Type: text/plain;charset=utf-8" + LF
-        + "Content-length: 100" + LF
-        + LF
-        + "Frederic Fall" + LF
-        + LF
+  @Test
+  public void tooBigContentLegthDoesNotResultInException() throws BatchException {
+    String getResponse = "--batch_123" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "HTTP/1.1 200 OK" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + "Content-Type: text/plain;charset=utf-8" + CRLF
+        + "Content-Length: 100" + CRLF
+        + CRLF
+        + "Frederic Fall" + CRLF
         + "--batch_123--";
 
-    parseInvalidBatchResponseBody(getResponse);
+    InputStream in = new ByteArrayInputStream(getResponse.getBytes());
+    List<BatchSingleResponse> batchResponse =
+        EntityProvider.parseBatchResponse(in, "multipart/mixed;boundary=batch_123");
+    BatchSingleResponse response = batchResponse.get(0);
+    assertEquals("100", response.getHeader("Content-Length"));
+    assertEquals("Frederic Fall", response.getBody());
   }
 
   @Test(expected = BatchException.class)
   public void testInvalidBoundary() throws BatchException {
-    String getResponse = "--batch_321" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + "Content-ID: 1" + LF
-        + LF
-        + "HTTP/1.1 200 OK" + LF
-        + "DataServiceVersion: 2.0" + LF
-        + "Content-Type: text/plain;charset=utf-8" + LF
-        + LF
-        + "Frederic Fall" + LF
-        + LF
+    String getResponse = "--batch_321" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + "Content-ID: 1" + CRLF
+        + CRLF
+        + "HTTP/1.1 200 OK" + CRLF
+        + "DataServiceVersion: 2.0" + CRLF
+        + "Content-Type: text/plain;charset=utf-8" + CRLF
+        + CRLF
+        + "Frederic Fall" + CRLF
+        + CRLF
         + "--batch_123--";
 
     parseInvalidBatchResponseBody(getResponse);
   }
 
-  @Test(expected = BatchException.class)
-  public void testInvalidBoundary2() throws BatchException {
-    String getResponse = "--batch_123" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + LF
-        + "HTTP/1.1 200 OK" + LF
-        + "Content-Type: text/plain;charset=utf-8" + LF
-        + "Content-Length: 13" + LF
-        + LF
-        + "Frederic Fall" + LF
-        + LF
-        + "batch_123" + LF
-        + "Content-Type: application/http" + LF
-        + "Content-Transfer-Encoding: binary" + LF
-        + LF
-        + "HTTP/1.1 200 OK" + LF
-        + "Content-Type: text/plain;charset=utf-8" + LF
-        + LF
-        + "Walter Winter" + LF
-        + LF
+  @Test
+  public void boundaryInBodyMustBeIgnored() throws BatchException {
+    String getResponse = "--batch_123" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "HTTP/1.1 200 OK" + CRLF
+        + "Content-Type: text/plain;charset=utf-8" + CRLF
+        + "Content-Length: 13" + CRLF
+        + CRLF
+        + "Frederic Fall" + CRLF
+        + CRLF
+        + "batch_123" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "HTTP/1.1 200 OK" + CRLF
+        + "Content-Type: text/plain;charset=utf-8" + CRLF
+        + CRLF
+        + "Walter Winter" + CRLF
+        + CRLF
         + "--batch_123--";
-    parseInvalidBatchResponseBody(getResponse);
+    InputStream in = new ByteArrayInputStream(getResponse.getBytes());
+    List<BatchSingleResponse> batchResponse =
+        EntityProvider.parseBatchResponse(in, "multipart/mixed;boundary=batch_123");
+    BatchSingleResponse response = batchResponse.get(0);
+    assertEquals("13", response.getHeader("Content-Length"));
+    assertEquals("Frederic Fall", response.getBody());
+  }
+
+  @Test
+  public void parseWithAdditionalLineEndingAtTheEnd() throws Exception {
+    InputStream stream = getFileAsStream("BatchResponseWithAdditionalLineEnding.batch");
+    BatchSingleResponse response =
+        EntityProvider.parseBatchResponse(stream, "multipart/mixed;boundary=batch_123").get(0);
+    assertEquals("This is the body we need to parse. The trailing line ending is part of the body." + CRLF, response
+        .getBody());
+
+  }
+
+  @Test
+  public void parseWithWindowsLineEndingsInBody() throws Exception {
+    InputStream stream = getFileAsStream("BatchResponseWithLinesInBodyWin.batch");
+    BatchSingleResponse response =
+        EntityProvider.parseBatchResponse(stream, "multipart/mixed;boundary=batch_123").get(0);
+    String body =
+        "This is the body we need to parse. The line spaces in the body " + CRLF + CRLF + CRLF + "are " + CRLF + CRLF
+            + "part of the body and must not be ignored or filtered.";
+
+    assertEquals(body, response.getBody());
+  }
+  
+  @Test
+  public void parseWithUnixLineEndingsInBody() throws Exception {
+    String body =
+        "This is the body we need to parse. The line spaces in the body " + LF + LF + LF + "are " + LF + LF
+        + "part of the body and must not be ignored or filtered.";
+    String responseString = "--batch_123" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Length: 234" + CRLF
+        + "content-transfer-encoding: binary" + CRLF
+        + CRLF 
+        + "HTTP/1.1 500 Internal Server Error" + CRLF
+        + "Content-Type: application/xml;charset=utf-8" + CRLF
+        + "Content-Length: 125" + CRLF
+        + CRLF
+        + body
+        + CRLF
+        + "--batch_123--"
+        ;
+    InputStream stream = new ByteArrayInputStream(responseString.getBytes());
+    BatchSingleResponse response =
+        EntityProvider.parseBatchResponse(stream, "multipart/mixed;boundary=batch_123").get(0);
+
+    assertEquals(body, response.getBody());
+  }
+
+  private InputStream getFileAsStream(final String filename) throws IOException {
+    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
+    if (in == null) {
+      throw new IOException("Requested file '" + filename + "' was not found.");
+    }
+    return in;
   }
 
   private void parseInvalidBatchResponseBody(final String putResponse) throws BatchException {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f1b9134c/odata2-lib/odata-core/src/test/resources/BatchResponseWithAdditionalLineEnding.batch
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/resources/BatchResponseWithAdditionalLineEnding.batch b/odata2-lib/odata-core/src/test/resources/BatchResponseWithAdditionalLineEnding.batch
new file mode 100644
index 0000000..9cd6c46
--- /dev/null
+++ b/odata2-lib/odata-core/src/test/resources/BatchResponseWithAdditionalLineEnding.batch
@@ -0,0 +1,12 @@
+--batch_123
+Content-Type: application/http
+Content-Length: 185
+content-transfer-encoding: binary
+
+HTTP/1.1 500 Internal Server Error
+Content-Type: application/xml;charset=utf-8
+Content-Length: 82
+
+This is the body we need to parse. The trailing line ending is part of the body.
+
+--batch_123--
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f1b9134c/odata2-lib/odata-core/src/test/resources/BatchResponseWithLinesInBodyWin.batch
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/resources/BatchResponseWithLinesInBodyWin.batch b/odata2-lib/odata-core/src/test/resources/BatchResponseWithLinesInBodyWin.batch
new file mode 100644
index 0000000..0d03643
--- /dev/null
+++ b/odata2-lib/odata-core/src/test/resources/BatchResponseWithLinesInBodyWin.batch
@@ -0,0 +1,16 @@
+--batch_123
+Content-Type: application/http
+Content-Length: 234
+content-transfer-encoding: binary
+
+HTTP/1.1 500 Internal Server Error
+Content-Type: application/xml;charset=utf-8
+Content-Length: 130
+
+This is the body we need to parse. The line spaces in the body 
+
+
+are 
+
+part of the body and must not be ignored or filtered.
+--batch_123--
\ No newline at end of file