[OLINGO-1499]Support simple new lines in batch requests
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java
index 99d2b8c..a27e311 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReader.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -37,6 +37,7 @@
public static final String BOUNDARY = "boundary";
public static final String DOUBLE_DASH = "--";
public static final String CRLF = "\r\n";
+ public static final String LFS = "\n";
private Charset currentCharset = DEFAULT_CHARSET;
private String currentBoundary = null;
private ReadState readState = new ReadState();
@@ -95,8 +96,9 @@
private void updateCurrentCharset(final String currentLine) {
if (currentLine != null) {
if (currentLine.startsWith(HttpHeader.CONTENT_TYPE)) {
+ int cutOff = currentLine.endsWith(CRLF) ? 2 : currentLine.endsWith(LFS) ? 1 : 0;
final ContentType contentType = ContentType.parse(
- currentLine.substring(HttpHeader.CONTENT_TYPE.length() + 1, currentLine.length() - 2).trim());
+ currentLine.substring(HttpHeader.CONTENT_TYPE.length() + 1, currentLine.length() - cutOff).trim());
if (contentType != null) {
final String charsetString = contentType.getParameter(ContentType.PARAMETER_CHARSET);
currentCharset = charsetString == null ?
@@ -110,7 +112,7 @@
currentBoundary = DOUBLE_DASH + boundary;
}
}
- } else if (CRLF.equals(currentLine)) {
+ } else if (CRLF.equals(currentLine) || LFS.equals(currentLine)) {
readState.foundLinebreak();
} else if (isBoundary(currentLine)) {
readState.foundBoundary();
@@ -120,7 +122,9 @@
private boolean isBoundary(final String currentLine) {
return (currentBoundary + CRLF).equals(currentLine)
- || (currentBoundary + DOUBLE_DASH + CRLF).equals(currentLine);
+ || (currentBoundary + LFS).equals(currentLine)
+ || (currentBoundary + DOUBLE_DASH + CRLF).equals(currentLine)
+ || (currentBoundary + DOUBLE_DASH + LFS).equals(currentLine);
}
String readLine() throws IOException {
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReaderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReaderTest.java
index 810c743..7c8c01c 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReaderTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchLineReaderTest.java
@@ -256,6 +256,21 @@
}
@Test
+ public void specialCharactersInJsonWithNewline() throws Exception {
+ final String text = "\n"
+ + "Content-Type: application/json\n"
+ + "\n"
+ + "{\"text\": \"ä€ß\"}\n";
+ BatchLineReader reader = create(text);
+ reader.readLine();
+ reader.readLine();
+ reader.readLine();
+ assertEquals("{\"text\": \"ä€ß\"}\n", reader.readLine());
+ assertNull(reader.readLine());
+ reader.close();
+ }
+
+ @Test
public void rawBytes() throws Exception {
byte[] content = new byte[Byte.MAX_VALUE - Byte.MIN_VALUE + 1];
// binary content, not a valid UTF-8 representation of a string