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 2015/07/20 22:29:49 UTC
[4/4] olingo-odata2 git commit: [OLINGO-733] Improved BatchParser and
add more test cases
[OLINGO-733] Improved BatchParser and add more test cases
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/07b2e644
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/07b2e644
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/07b2e644
Branch: refs/heads/master
Commit: 07b2e644195ac73c107b7d385420cf9098eae353
Parents: e0311e1
Author: mibo <mi...@mirb.de>
Authored: Mon Jul 20 22:27:12 2015 +0200
Committer: mibo <mi...@mirb.de>
Committed: Mon Jul 20 22:27:12 2015 +0200
----------------------------------------------------------------------
.../olingo/odata2/core/batch/BatchHelper.java | 4 ----
.../odata2/core/batch/BatchRequestWriter.java | 8 +++----
.../odata2/core/batch/v2/BatchParserCommon.java | 22 ++++++++++----------
.../batch/v2/BatchRequestTransformator.java | 7 ++++---
.../core/batch/BatchRequestWriterITTest.java | 20 +++++++++---------
5 files changed, 29 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/07b2e644/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java
index 2f73216..835f47b 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHelper.java
@@ -90,10 +90,6 @@ public class BatchHelper {
return DEFAULT_CHARSET;
}
- private static String convertByteArray(byte[] entity, Charset charset) {
- return new String(entity, charset);
- }
-
/**
* Builder class to create the body and the header.
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/07b2e644/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java
index 3e7a1da..c050a1d 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchRequestWriter.java
@@ -80,18 +80,18 @@ public class BatchRequestWriter {
writer.append(CRLF).append("--").append(boundary).append("--").append(CRLF);
}
- private void appendRequestBodyPart(BatchQueryPart request) {
+ private void appendRequestBodyPart(final BatchQueryPart request) {
appendRequestBodyPart(request.getMethod(), request.getUri(), request.getHeaders(),
new BatchHelper.Body(), request.getContentId());
}
- private void appendRequestBodyPart(BatchChangeSetPart request) {
+ private void appendRequestBodyPart(final BatchChangeSetPart request) {
appendRequestBodyPart(request.getMethod(), request.getUri(), request.getHeaders(),
new BatchHelper.Body(request), request.getContentId());
}
- private void appendRequestBodyPart(String method, String uri,
- Map<String, String> headers, BatchHelper.Body body, String contentId) {
+ private void appendRequestBodyPart(final String method, final String uri, final Map<String, String> headers,
+ final BatchHelper.Body body, final String contentId) {
boolean isContentLengthPresent = false;
writer.append(HttpHeaders.CONTENT_TYPE).append(COLON).append(SP).append(HttpContentType.APPLICATION_HTTP)
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/07b2e644/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 2aa9311..66d4a2c 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
@@ -72,28 +72,28 @@ public class BatchParserCommon {
}
/**
- * Convert body of BatchQueryOperation into a InputStream.
- * The body will get via the charset set in ContentType and
+ * Convert body in form of List of Line items into a InputStream.
+ * The body is transformed with the charset set in ContentType and
* if no charset is set with Olingo default charset (see <code>BatchHelper.DEFAULT_CHARSET</code>).
*
* If content length is a positive value the content is trimmed to according length.
* Otherwise the whole content is written into the InputStream.
*
- * @param operation from which the content is written into the InputStream
+ * @param contentType content type value
+ * @param body content which is written into the InputStream
* @param contentLength if it is a positive value the content is trimmed to according length.
* Otherwise the whole content is written into the InputStream.
* @return Content of BatchQueryOperation as InputStream in according charset and length
* @throws BatchException if something goes wrong
*/
- public static InputStream convertToInputStream(BatchQueryOperation operation, int contentLength)
+ public static InputStream convertToInputStream(final String contentType, final List<Line> body, final int contentLength)
throws BatchException {
- String contentType = operation.getHeaders().getHeader(HttpHeaders.CONTENT_TYPE);
Charset charset = BatchHelper.extractCharset(contentType);
final String message;
if(contentLength <= -1) {
- message = lineListToString(operation.getBody());
+ message = lineListToString(body);
} else {
- message = trimLineListToLength(operation.getBody(), contentLength);
+ message = trimLineListToLength(body, contentLength);
}
return new ByteArrayInputStream(message.getBytes(charset));
}
@@ -126,21 +126,21 @@ public class BatchParserCommon {
}
}
- final int lineNumer = (message.size() > 0) ? message.get(0).getLineNumber() : 0;
+ final int lineNumber = (message.size() > 0) ? message.get(0).getLineNumber() : 0;
// Remove preamble
if (messageParts.size() > 0) {
messageParts.remove(0);
} else {
- throw new BatchException(BatchException.MISSING_BOUNDARY_DELIMITER.addContent(lineNumer));
+ throw new BatchException(BatchException.MISSING_BOUNDARY_DELIMITER.addContent(lineNumber));
}
if (!isEndReached) {
- throw new BatchException(BatchException.MISSING_CLOSE_DELIMITER.addContent(lineNumer));
+ throw new BatchException(BatchException.MISSING_CLOSE_DELIMITER.addContent(lineNumber));
}
if (messageParts.size() == 0) {
- throw new BatchException(BatchException.NO_MATCH_WITH_BOUNDARY_STRING.addContent(boundary).addContent(lineNumer));
+ throw new BatchException(BatchException.NO_MATCH_WITH_BOUNDARY_STRING.addContent(boundary).addContent(lineNumber));
}
return messageParts;
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/07b2e644/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
index a3b376b..dbe349d 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/v2/BatchRequestTransformator.java
@@ -88,13 +88,13 @@ public class BatchRequestTransformator implements BatchTransformator {
statusLine.validateHttpMethod(isChangeSet);
validateBody(statusLine, operation);
- InputStream bodyStrean = getBodyStream(operation, headers, statusLine);
+ InputStream bodyStream = getBodyStream(operation, headers, statusLine);
ODataRequestBuilder requestBuilder = ODataRequest.method(statusLine.getMethod())
.acceptableLanguages(getAcceptLanguageHeaders(headers))
.acceptHeaders(headers.getHeaders(HttpHeaders.ACCEPT))
.allQueryParameters(BatchParserCommon.parseQueryParameter(operation.getHttpStatusLine()))
- .body(bodyStrean)
+ .body(bodyStream)
.requestHeaders(headers.toMultiMap())
.pathInfo(statusLine.getPathInfo());
@@ -127,7 +127,8 @@ public class BatchRequestTransformator implements BatchTransformator {
return new ByteArrayInputStream(new byte[0]);
} else {
int contentLength = BatchTransformatorCommon.getContentLength(headers);
- return BatchParserCommon.convertToInputStream(operation, contentLength);
+ String contentType = headers.getHeader(HttpHeaders.CONTENT_TYPE);
+ return BatchParserCommon.convertToInputStream(contentType, operation.getBody(), contentLength);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/07b2e644/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java
index 6e1626e..49ea7ce 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterITTest.java
@@ -24,7 +24,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
-import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -43,7 +42,6 @@ import org.apache.olingo.odata2.core.PathInfoImpl;
import org.apache.olingo.odata2.core.batch.v2.BatchParser;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
public class BatchRequestWriterITTest {
@@ -128,14 +126,17 @@ public class BatchRequestWriterITTest {
assertEquals("application/json", oDataRequestPost.getRequestHeaderValue(HttpHeaders.CONTENT_TYPE));
}
- /**
- * BatchChangeSetPart can only handle utf-8 (DEFAULT_CHARSET for Olingo [BatchHelper.DEFAULT_ENCODING]).
- * Hence it is not relevant which charset is set in changeSetHeader
- *
- * @throws Exception
- */
@Test
public void testChangeSetIso() throws Exception {
+ testChangeSetWithCharset("iso-8859-1");
+ }
+
+ @Test
+ public void testChangeSetUtf8() throws Exception {
+ testChangeSetWithCharset("utf-8");
+ }
+
+ private void testChangeSetWithCharset(final String charset) throws Exception {
List<BatchPart> batch = new ArrayList<BatchPart>();
Map<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "application/json");
@@ -143,7 +144,6 @@ public class BatchRequestWriterITTest {
batch.add(request);
Map<String, String> changeSetHeaders = new HashMap<String, String>();
- String charset = "iso-8859-1";
changeSetHeaders.put("content-type", "application/json; charset=" + charset);
String body = "äöü/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA";
StringHelper.Stream stBody = StringHelper.toStream(body, charset);
@@ -178,7 +178,7 @@ public class BatchRequestWriterITTest {
assertEquals("Employees", oDataRequestGet.getPathInfo().getODataSegments().get(0).getPath());
assertEquals("111", oDataRequestPost.getRequestHeaderValue(BatchHelper.MIME_HEADER_CONTENT_ID));
StringHelper.Stream st = StringHelper.toStream(oDataRequestPost.getBody());
- assertEquals(body, st.asString("utf-8"));
+ assertEquals(body, st.asString(charset));
assertEquals("application/json; charset=" + charset,
oDataRequestPost.getRequestHeaderValue(HttpHeaders.CONTENT_TYPE));
}