You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2020/12/09 05:34:02 UTC
[olingo-odata2] branch master updated: [OLINGO-1498]Support simple
new lines in batch requests
This is an automated email from the ASF dual-hosted git repository.
ramyav pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git
The following commit(s) were added to refs/heads/master by this push:
new 97ffa7f [OLINGO-1498]Support simple new lines in batch requests
97ffa7f is described below
commit 97ffa7f14ffbf7ca70226dc5864e7c0cabee0f3c
Author: ramya vasanth <ra...@sap.com>
AuthorDate: Wed Dec 9 11:03:50 2020 +0530
[OLINGO-1498]Support simple new lines in batch requests
---
.../odata2/core/batch/v2/BatchLineReader.java | 11 ++++--
.../odata2/core/batch/v2/BatchLineReaderTest.java | 44 +++++++++++++++++++---
2 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java
index a418ffb..878e315 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReader.java
@@ -40,6 +40,7 @@ public class BatchLineReader {
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();
@@ -98,7 +99,8 @@ public class BatchLineReader {
private void updateCurrentCharset(String currentLine) {
if(currentLine != null) {
if(isContentTypeHeaderLine(currentLine)) {
- currentLine = currentLine.substring(13, currentLine.length() - 2).trim();
+ int cutOff = currentLine.endsWith(CRLF) ? 2 : currentLine.endsWith(LFS) ? 1 : 0;
+ currentLine = currentLine.substring(13, currentLine.length() - cutOff).trim();
ContentType ct = ContentType.parse(currentLine);
if (ct != null) {
String charsetString = ct.getParameters().get(ContentType.PARAMETER_CHARSET);
@@ -117,7 +119,7 @@ public class BatchLineReader {
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();
@@ -130,9 +132,10 @@ public class BatchLineReader {
}
private boolean isBoundary(String currentLine) {
- if((currentBoundary + CRLF).equals(currentLine)) {
+ if((currentBoundary + CRLF).equals(currentLine) || (currentBoundary + LFS).equals(currentLine)) {
return true;
- } else if((currentBoundary + DOUBLE_DASH + CRLF).equals(currentLine)) {
+ } else if((currentBoundary + DOUBLE_DASH + CRLF).equals(currentLine)
+ || (currentBoundary + DOUBLE_DASH + LFS).equals(currentLine)) {
return true;
}
return false;
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.java
index f97b013..7a6238f 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/v2/BatchLineReaderTest.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
@@ -227,7 +227,41 @@ public class BatchLineReaderTest {
reader.close();
}
+ @Test
+ public void specialCharacters() throws Exception {
+ final String text = "\r\n"
+ + "Content-Type: text/plain; charset=UTF-8\r\n"
+ + "\r\n"
+ + "ä€\r\n"
+ + "\uFDFC\r\n" // RIAL SIGN
+ // Unicode characters outside the Basic Multilingual Plane are stored
+ // in a Java String in two surrogate characters.
+ + String.valueOf(Character.toChars(0x1F603));
+ BatchLineReader reader = create(text);
+ reader.readLine();
+ reader.readLine();
+ reader.readLine();
+ assertEquals("ä€\r\n", reader.readLine());
+ assertEquals("\uFDFC\r\n", reader.readLine());
+ assertEquals(String.valueOf(Character.toChars(0x1F603)), reader.readLine());
+ assertNull(reader.readLine());
+ reader.close();
+ }
+ @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(expected = IllegalArgumentException.class)
public void testFailBufferSizeZero() throws IOException {
@@ -276,7 +310,7 @@ public class BatchLineReaderTest {
throws UnsupportedEncodingException {
return new BatchLineReader(new ByteArrayInputStream(inputString.getBytes("UTF-8")), bufferSize);
}
-
+
@Test
public void rawBytes() throws Exception {
byte[] content = new byte[Byte.MAX_VALUE - Byte.MIN_VALUE + 1];
@@ -292,7 +326,7 @@ public class BatchLineReaderTest {
assertNull(reader.readLine());
reader.close();
}
-
+
@Test
public void imageTest() throws Exception {
byte[] data = getImageData("/Employee_1.png");
@@ -302,7 +336,7 @@ public class BatchLineReaderTest {
for (Line content : contentString) {
finalContent += content.toString();
}
-
+
assertArrayEquals(data, finalContent.getBytes(Charset.forName("ISO-8859-1")));
reader.close();
}