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/08/15 09:31:57 UTC
olingo-odata4 git commit: [OLINGO-750] Fixed (some) major issues
Repository: olingo-odata4
Updated Branches:
refs/heads/master cd11add7c -> e6d1b964f
[OLINGO-750] Fixed (some) major issues
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/e6d1b964
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/e6d1b964
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/e6d1b964
Branch: refs/heads/master
Commit: e6d1b964f9cdeb3fb77b7b2b692017d7e03bc7ef
Parents: cd11add
Author: mibo <mi...@apache.org>
Authored: Sat Aug 15 09:19:29 2015 +0200
Committer: mibo <mi...@apache.org>
Committed: Sat Aug 15 09:19:38 2015 +0200
----------------------------------------------------------------------
.../olingo/commons/api/format/TypeUtil.java | 2 +-
.../deserializer/batch/BatchParserCommon.java | 12 ++++--
.../batch/BatchRequestTransformator.java | 26 +++++++++++--
.../serializer/BatchResponseSerializer.java | 6 +--
.../serializer/utils/ContextURLBuilder.java | 10 +++--
.../core/serializer/utils/ContextURLHelper.java | 2 +
.../olingo/server/core/uri/UriInfoImpl.java | 40 ++++++++++----------
7 files changed, 62 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e6d1b964/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
index 1ba15c5..d1e7a1a 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
@@ -23,7 +23,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
-class TypeUtil {
+final class TypeUtil {
static final String MEDIA_TYPE_WILDCARD = "*";
static final String PARAMETER_Q = "q";
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e6d1b964/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
index c826bd3..256e05e 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
@@ -20,6 +20,7 @@ package org.apache.olingo.server.core.deserializer.batch;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -43,6 +44,8 @@ public class BatchParserCommon {
protected static final String BOUNDARY = "boundary";
public static final String BINARY_ENCODING = "binary";
+ private BatchParserCommon() { /* private ctor for helper class */}
+
public static String getBoundary(final String contentType, final int line) throws BatchDeserializerException {
final ContentType type = parseContentType(contentType, ContentType.MULTIPART_MIXED, line);
final Map<String, String> parameters = type.getParameters();
@@ -198,10 +201,10 @@ public class BatchParserCommon {
}
}
- public static InputStream convertLineListToInputStream(final List<Line> messageList) {
+ public static InputStream convertLineListToInputStream(final List<Line> messageList, final Charset charset) {
final String message = lineListToString(messageList);
- return new ByteArrayInputStream(message.getBytes());
+ return new ByteArrayInputStream(message.getBytes(charset));
}
private static String lineListToString(final List<Line> messageList) {
@@ -221,9 +224,10 @@ public class BatchParserCommon {
return (lastIndex > 0) ? message.substring(0, lastIndex) : "";
}
- public static InputStream convertLineListToInputStream(final List<Line> list, final int length) {
+ public static InputStream convertLineListToInputStream(final List<Line> list, final Charset charset,
+ final int length) {
final String message = trimLineListToLength(list, length);
- return new ByteArrayInputStream(message.getBytes());
+ return new ByteArrayInputStream(message.getBytes(charset));
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e6d1b964/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestTransformator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestTransformator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestTransformator.java
index ce46839..4e5ef9d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestTransformator.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestTransformator.java
@@ -20,6 +20,7 @@ package org.apache.olingo.server.core.deserializer.batch;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -33,6 +34,7 @@ import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
public class BatchRequestTransformator {
+ private static final Charset DEFAULT_CHARSET = Charset.forName("utf-8");
private final String baseUri;
private final String rawServiceResolutionUri;
@@ -104,7 +106,8 @@ public class BatchRequestTransformator {
statusLine.validateHttpMethod(isChangeSet);
validateBody(statusLine, operation);
- InputStream bodyStrean = getBodyStream(operation, statusLine);
+ Charset charset = getCharset(operation);
+ InputStream bodyStrean = getBodyStream(operation, statusLine, charset);
validateForbiddenHeader(operation);
@@ -124,6 +127,20 @@ public class BatchRequestTransformator {
return request;
}
+ private Charset getCharset(BatchQueryOperation operation) {
+ String ct = operation.getHeaders().getHeader(HttpHeader.CONTENT_TYPE);
+ if(ct != null) {
+ ContentType contentType = ContentType.parse(ct);
+ if(contentType != null) {
+ String charsetValue = contentType.getParameter(ContentType.PARAMETER_CHARSET);
+ if(charsetValue != null) {
+ return Charset.forName(charsetValue);
+ }
+ }
+ }
+ return DEFAULT_CHARSET;
+ }
+
private void validateForbiddenHeader(final BatchQueryOperation operation) throws BatchDeserializerException {
final Header header = operation.getHeaders();
@@ -135,7 +152,8 @@ public class BatchRequestTransformator {
}
}
- private InputStream getBodyStream(final BatchQueryOperation operation, final HttpRequestStatusLine statusLine)
+ private InputStream getBodyStream(final BatchQueryOperation operation, final HttpRequestStatusLine statusLine,
+ final Charset charset)
throws BatchDeserializerException {
if (statusLine.getMethod().equals(HttpMethod.GET)) {
return new ByteArrayInputStream(new byte[0]);
@@ -143,9 +161,9 @@ public class BatchRequestTransformator {
int contentLength = BatchTransformatorCommon.getContentLength(operation.getHeaders());
if (contentLength == -1) {
- return BatchParserCommon.convertLineListToInputStream(operation.getBody());
+ return BatchParserCommon.convertLineListToInputStream(operation.getBody(), charset);
} else {
- return BatchParserCommon.convertLineListToInputStream(operation.getBody(), contentLength);
+ return BatchParserCommon.convertLineListToInputStream(operation.getBody(), charset, contentLength);
}
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e6d1b964/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
index 4af94f9..8cd47068 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
@@ -176,8 +176,8 @@ public class BatchResponseSerializer {
/**
* Builder class to create the body and the header.
*/
- private class BodyBuilder {
- private final Charset CHARSET_ISO_8859_1 = Charset.forName("iso-8859-1");
+ private static class BodyBuilder {
+ private static final Charset CHARSET_ISO_8859_1 = Charset.forName("iso-8859-1");
private ByteBuffer buffer = ByteBuffer.allocate(8192);
private boolean isClosed = false;
@@ -219,7 +219,7 @@ public class BatchResponseSerializer {
}
public String toString() {
- return new String(buffer.array(), 0, buffer.position());
+ return new String(buffer.array(), 0, buffer.position(), CHARSET_ISO_8859_1);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e6d1b964/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
index 3cc7744..8c7a8d5 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java
@@ -31,6 +31,8 @@ import org.apache.olingo.commons.core.Encoder;
*/
public final class ContextURLBuilder {
+ private ContextURLBuilder() { /* private ctor for helper class */ }
+
public static URI create(final ContextURL contextURL) {
StringBuilder result = new StringBuilder();
if (contextURL.getServiceRoot() != null) {
@@ -76,10 +78,10 @@ public final class ContextURLBuilder {
throw new IllegalArgumentException("ContextURL: $ref with Entity Set");
}
if (contextURL.isCollection()) {
- result.append('#');
- result.append("Collection(")
- .append(ContextURL.Suffix.REFERENCE.getRepresentation())
- .append(")");
+ result.append('#')
+ .append("Collection(")
+ .append(ContextURL.Suffix.REFERENCE.getRepresentation())
+ .append(")");
} else {
result.append('#').append(ContextURL.Suffix.REFERENCE.getRepresentation());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e6d1b964/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
index f6c2ae3..22a2301 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java
@@ -38,6 +38,8 @@ import org.apache.olingo.server.api.uri.queryoption.SelectOption;
public final class ContextURLHelper {
+ private ContextURLHelper() { /* private ctor for helper class */ }
+
/**
* Builds a list of selected Properties for the ContextURL,
* taking care to preserve the order as defined in the EDM;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e6d1b964/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java
index 525da75..15a70be 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java
@@ -65,7 +65,7 @@ public class UriInfoImpl implements UriInfo {
private List<CustomQueryOptionImpl> customQueryOptions = new ArrayList<CustomQueryOptionImpl>();
private Map<String, String> aliasToValue = new HashMap<String, String>();
- Map<SystemQueryOptionKind, SystemQueryOption> systemQueryOptions =
+ private Map<SystemQueryOptionKind, SystemQueryOption> systemQueryOptions =
new HashMap<SystemQueryOptionKind, SystemQueryOption>();
private String fragment;
@@ -249,27 +249,27 @@ public class UriInfoImpl implements UriInfo {
*/
public UriInfoImpl setSystemQueryOption(final SystemQueryOption systemOption) {
final SystemQueryOptionKind kind = systemOption.getKind();
+ if (systemQueryOptions.containsKey(kind)) {
+ throw new ODataRuntimeException("Double System Query Option: " + systemOption.getName());
+ }
+
switch (kind) {
- case EXPAND:
- case FILTER:
- case FORMAT:
- case ID:
- case COUNT:
- case ORDERBY:
- case SEARCH:
- case SELECT:
- case SKIP:
- case SKIPTOKEN:
- case TOP:
- case LEVELS:
- if (systemQueryOptions.containsKey(kind)) {
- throw new ODataRuntimeException("Double System Query Option: " + systemOption.getName());
- } else {
+ case EXPAND:
+ case FILTER:
+ case FORMAT:
+ case ID:
+ case COUNT:
+ case ORDERBY:
+ case SEARCH:
+ case SELECT:
+ case SKIP:
+ case SKIPTOKEN:
+ case TOP:
+ case LEVELS:
systemQueryOptions.put(kind, systemOption);
- }
- break;
- default:
- throw new ODataRuntimeException("Unsupported System Query Option: " + systemOption.getName());
+ break;
+ default:
+ throw new ODataRuntimeException("Unsupported System Query Option: " + systemOption.getName());
}
return this;
}