[OLINGO-750] Fixed (some) major issues
This commit is contained in:
parent
cd11add7c1
commit
e6d1b964f9
|
@ -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";
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue