mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-06 00:29:05 +00:00
[OLINGO-659] clean-up in batch handling
Change-Id: I016ada42ce0e9fb8e0cc021422f7f03fd5b06a9d Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
parent
4070e15531
commit
21b36a898a
@ -70,8 +70,9 @@ public final class ContentType {
|
||||
public static final ContentType APPLICATION_FORM_URLENCODED =
|
||||
new ContentType(APPLICATION, "x-www-form-urlencoded", null);
|
||||
|
||||
public static final ContentType MULTIPART_MIXED = new ContentType(MULTIPART, "mixed", null);
|
||||
public static final ContentType APPLICATION_HTTP = new ContentType(APPLICATION, "http", null);
|
||||
|
||||
public static final ContentType MULTIPART_MIXED = new ContentType(MULTIPART, "mixed", null);
|
||||
public static final ContentType MULTIPART_FORM_DATA = new ContentType(MULTIPART, "form-data", null);
|
||||
|
||||
public static final String PARAMETER_CHARSET_UTF8 = "charset=utf-8";
|
||||
|
@ -19,9 +19,7 @@
|
||||
package org.apache.olingo.commons.api.http;
|
||||
|
||||
/**
|
||||
* HTTP header constants
|
||||
*
|
||||
*
|
||||
* HTTP header constants.
|
||||
*/
|
||||
public interface HttpHeader {
|
||||
|
||||
@ -61,6 +59,8 @@ public interface HttpHeader {
|
||||
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.12">HTTP/1.1 documentation</a>}.
|
||||
*/
|
||||
public static final String CONTENT_LANGUAGE = "Content-Language";
|
||||
/** See <a href="http://www.rfc-editor.org/rfc/rfc2392.txt">RFC 2392</a>. */
|
||||
public static final String CONTENT_ID = "Content-ID";
|
||||
/**
|
||||
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13">HTTP/1.1 documentation</a>}.
|
||||
*/
|
||||
@ -81,10 +81,14 @@ public interface HttpHeader {
|
||||
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19">HTTP/1.1 documentation</a>}.
|
||||
*/
|
||||
public static final String ETAG = "ETag";
|
||||
/** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */
|
||||
public static final String EXPECT = "Expect";
|
||||
/**
|
||||
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21">HTTP/1.1 documentation</a>}.
|
||||
*/
|
||||
public static final String EXPIRES = "Expires";
|
||||
/** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */
|
||||
public static final String FROM = "From";
|
||||
/**
|
||||
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23">HTTP/1.1 documentation</a>}.
|
||||
*/
|
||||
@ -117,6 +121,20 @@ public interface HttpHeader {
|
||||
* See {@link <a href="http://tools.ietf.org/html/rfc5988#page-6">Web Linking (IETF RFC-5988) documentation</a>}.
|
||||
*/
|
||||
public static final String LINK = "Link";
|
||||
/** See <a href="http://www.rfc-editor.org/rfc/rfc7231.txt">RFC 7231</a>. */
|
||||
public static final String MAX_FORWARDS = "Max-Forwards";
|
||||
/**
|
||||
* OData Prefer Header.
|
||||
* See <a href="http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html#_Toc406398233">
|
||||
* OData Version 4.0 Part 1: Protocol</a> and <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>.
|
||||
*/
|
||||
public static final String PREFER = "Prefer";
|
||||
/**
|
||||
* OData Preference-Applied Header.
|
||||
* See <a href="http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html#_Toc406398247">
|
||||
* OData Version 4.0 Part 1: Protocol</a> and <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>.
|
||||
*/
|
||||
public static final String PREFERENCE_APPLIED = "Preference-Applied";
|
||||
/**
|
||||
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37">HTTP/1.1 documentation</a>}.
|
||||
*/
|
||||
@ -133,6 +151,7 @@ public interface HttpHeader {
|
||||
* See {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.47">HTTP/1.1 documentation</a>}.
|
||||
*/
|
||||
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
|
||||
|
||||
/**
|
||||
* See {@link <a href="http://www.ietf.org/rfc/rfc2109.txt">IETF RFC 2109</a>}.
|
||||
*/
|
||||
@ -161,18 +180,4 @@ public interface HttpHeader {
|
||||
* OData Custom Header
|
||||
*/
|
||||
public static final String ODATA_MAX_VERSION = "OData-MaxVersion";
|
||||
|
||||
/**
|
||||
* OData Prefer Header.
|
||||
* See <a href="http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html#_Toc406398233">
|
||||
* OData Version 4.0 Part 1: Protocol</a> and <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>.
|
||||
*/
|
||||
public static final String PREFER = "Prefer";
|
||||
|
||||
/**
|
||||
* OData Preference-Applied Header.
|
||||
* See <a href="http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html#_Toc406398247">
|
||||
* OData Version 4.0 Part 1: Protocol</a> and <a href="https://www.ietf.org/rfc/rfc7240.txt">RFC 7240</a>.
|
||||
*/
|
||||
public static final String PREFERENCE_APPLIED = "Preference-Applied";
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
|
||||
@ -42,6 +42,13 @@ public interface FixedFormatDeserializer {
|
||||
*/
|
||||
public Object primitiveValue(InputStream content, EdmProperty property) throws DeserializerException;
|
||||
|
||||
/**
|
||||
* Reads batch data from an InputStream.
|
||||
* @param content the data as multipart input stream
|
||||
* @param boundary the boundary between the parts
|
||||
* @param options options for the deserializer
|
||||
* @return a list of batch-request parts
|
||||
*/
|
||||
public List<BatchRequestPart> parseBatchRequest(InputStream content, String boundary, BatchOptions options)
|
||||
throws BatchDeserializerException;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.api.batch.exception;
|
||||
package org.apache.olingo.server.api.deserializer.batch;
|
||||
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
|
||||
@ -52,14 +52,26 @@ public class BatchDeserializerException extends DeserializerException {
|
||||
|
||||
private static final long serialVersionUID = -907752788975531134L;
|
||||
|
||||
public BatchDeserializerException(final String developmentMessage, final MessageKey messageKey,
|
||||
final int lineNumber) {
|
||||
this(developmentMessage, messageKey, "" + lineNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates batch deserializer exception.
|
||||
* @param developmentMessage message text as fallback and for debugging purposes
|
||||
* @param messageKey one of the {@link MessageKeys} for the exception text in the resource bundle
|
||||
* @param parameters parameters for the exception text
|
||||
*/
|
||||
public BatchDeserializerException(final String developmentMessage, final MessageKey messageKey,
|
||||
final String... parameters) {
|
||||
super(developmentMessage, messageKey, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates batch deserializer exception.
|
||||
* @param developmentMessage message text as fallback and for debugging purposes
|
||||
* @param cause the cause of this exception
|
||||
* @param messageKey one of the {@link MessageKeys} for the exception text in the resource bundle
|
||||
* @param parameters parameters for the exception text
|
||||
*/
|
||||
public BatchDeserializerException(final String developmentMessage, final Throwable cause,
|
||||
final MessageKey messageKey, final String... parameters) {
|
||||
super(developmentMessage, cause, messageKey, parameters);
|
||||
}
|
||||
}
|
@ -16,9 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.olingo.server.api.batch.exception;
|
||||
package org.apache.olingo.server.api.serializer;
|
||||
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
|
||||
public class BatchSerializerException extends SerializerException {
|
||||
|
@ -22,7 +22,6 @@ import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchSerializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
|
||||
|
||||
/** OData serializer for fixed output formats. */
|
||||
@ -50,11 +49,10 @@ public interface FixedFormatSerializer {
|
||||
throws SerializerException;
|
||||
|
||||
/**
|
||||
* Serializes a batch response
|
||||
* @param batchResponses
|
||||
* @param boundary
|
||||
* Serializes a batch response.
|
||||
* @param batchResponses the response parts
|
||||
* @param boundary the boundary between the parts
|
||||
* @return response as an input stream
|
||||
* @throws BatchSerializerException
|
||||
*/
|
||||
InputStream batchResponse(List<ODataResponsePart> batchResponses, String boundary) throws BatchSerializerException;
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.ODataServerError;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.serializer.CustomContentTypeSupport;
|
||||
import org.apache.olingo.server.api.serializer.ODataSerializer;
|
||||
import org.apache.olingo.server.api.serializer.RepresentationType;
|
||||
|
@ -33,7 +33,7 @@ import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.ODataLibraryException;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
|
||||
@ -165,9 +165,9 @@ public class BatchRequest extends ServiceRequest {
|
||||
}
|
||||
|
||||
private void addContentID(ODataRequest batchPartRequest, ODataResponse batchPartResponse) {
|
||||
final String contentId = batchPartRequest.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
|
||||
final String contentId = batchPartRequest.getHeader(HttpHeader.CONTENT_ID);
|
||||
if (contentId != null) {
|
||||
batchPartResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, contentId);
|
||||
batchPartResponse.setHeader(HttpHeader.CONTENT_ID, contentId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,12 +177,10 @@ public class BatchRequest extends ServiceRequest {
|
||||
}
|
||||
|
||||
private void validateContentType() throws ODataApplicationException {
|
||||
final String contentType = getRequestContentType().toContentTypeString();
|
||||
|
||||
if (contentType == null
|
||||
|| !BatchParserCommon.PATTERN_MULTIPART_BOUNDARY.matcher(contentType).matches()) {
|
||||
final ContentType contentType = getRequestContentType();
|
||||
if (contentType == null || !contentType.isCompatible(ContentType.MULTIPART_MIXED)) {
|
||||
throw new ODataApplicationException("Invalid content type",
|
||||
HttpStatusCode.PRECONDITION_FAILED.getStatusCode(), Locale.getDefault());
|
||||
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import org.apache.olingo.server.api.ODataLibraryException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.batch.BatchFacade;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
|
||||
import org.apache.olingo.server.api.processor.BatchProcessor;
|
||||
@ -34,8 +34,7 @@ public class BatchFacadeImpl implements BatchFacade {
|
||||
private final BatchPartHandler partHandler;
|
||||
|
||||
public BatchFacadeImpl(final ODataHandler oDataHandler, final ODataRequest request,
|
||||
final BatchProcessor batchProcessor,
|
||||
final boolean isStrict) {
|
||||
final BatchProcessor batchProcessor, final boolean isStrict) {
|
||||
partHandler = new BatchPartHandler(oDataHandler, batchProcessor, this);
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.olingo.server.core.batchhandler;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
@ -25,8 +26,8 @@ import org.apache.olingo.server.api.ODataLibraryException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.batch.BatchFacade;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.processor.BatchProcessor;
|
||||
import org.apache.olingo.server.core.ODataHandler;
|
||||
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
|
||||
@ -55,16 +56,13 @@ public class BatchHandler {
|
||||
}
|
||||
|
||||
private void validateContentType(final ODataRequest request) throws BatchDeserializerException {
|
||||
final String contentType = request.getHeader(HttpHeader.CONTENT_TYPE);
|
||||
|
||||
if (contentType == null || !BatchParserCommon.PATTERN_MULTIPART_BOUNDARY.matcher(contentType).matches()) {
|
||||
throw new BatchDeserializerException("Invalid content type", MessageKeys.INVALID_CONTENT_TYPE, 0);
|
||||
}
|
||||
// This method does validation.
|
||||
BatchParserCommon.getContentType(request.getHeader(HttpHeader.CONTENT_TYPE), ContentType.MULTIPART_MIXED, 0);
|
||||
}
|
||||
|
||||
private void validateHttpMethod(final ODataRequest request) throws BatchDeserializerException {
|
||||
if (request.getMethod() != HttpMethod.POST) {
|
||||
throw new BatchDeserializerException("Invalid HTTP method", MessageKeys.INVALID_METHOD, 0);
|
||||
throw new BatchDeserializerException("Invalid HTTP method", MessageKeys.INVALID_METHOD, "0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,13 @@
|
||||
*/
|
||||
package org.apache.olingo.server.core.batchhandler;
|
||||
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataLibraryException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.batch.BatchFacade;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
|
||||
import org.apache.olingo.server.api.processor.BatchProcessor;
|
||||
@ -75,9 +76,9 @@ public class BatchPartHandler {
|
||||
}
|
||||
|
||||
// Add content id to response
|
||||
final String contentId = request.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
|
||||
final String contentId = request.getHeader(HttpHeader.CONTENT_ID);
|
||||
if (contentId != null) {
|
||||
response.setHeader(BatchParserCommon.HTTP_CONTENT_ID, contentId);
|
||||
response.setHeader(HttpHeader.CONTENT_ID, contentId);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
@ -28,9 +28,8 @@ import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
|
||||
|
||||
public class BatchReferenceRewriter {
|
||||
private static final String REG_EX_REFERENCE = "\\$(.*)(/.*)?";
|
||||
@ -67,7 +66,7 @@ public class BatchReferenceRewriter {
|
||||
public void addMapping(final ODataRequest request, final ODataResponse response)
|
||||
throws BatchDeserializerException {
|
||||
final String resourceUri = getODataPath(request, response);
|
||||
final String contentId = request.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
|
||||
final String contentId = request.getHeader(HttpHeader.CONTENT_ID);
|
||||
|
||||
contentIdMapping.put(contentId, resourceUri);
|
||||
}
|
||||
@ -91,12 +90,10 @@ public class BatchReferenceRewriter {
|
||||
}
|
||||
|
||||
private String parseODataPath(final String uri, final String rawBaseUri) throws BatchDeserializerException {
|
||||
int index = uri.indexOf(rawBaseUri);
|
||||
|
||||
if (index == 0) {
|
||||
if (uri.indexOf(rawBaseUri) == 0) {
|
||||
return uri.substring(rawBaseUri.length());
|
||||
} else {
|
||||
throw new BatchDeserializerException("Invalid base uri or uri", MessageKeys.INVALID_URI, 0);
|
||||
throw new BatchDeserializerException("Invalid base uri or uri", MessageKeys.INVALID_URI, "0");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,9 +28,9 @@ import java.util.List;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.FixedFormatDeserializer;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
import org.apache.olingo.server.core.deserializer.batch.BatchParser;
|
||||
|
@ -21,8 +21,9 @@ package org.apache.olingo.server.core.deserializer.batch;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
|
||||
public class BatchBodyPart implements BatchPart {
|
||||
final private String boundary;
|
||||
@ -52,10 +53,10 @@ public class BatchBodyPart implements BatchPart {
|
||||
final List<String> contentTypes = headers.getHeaders(HttpHeader.CONTENT_TYPE);
|
||||
boolean isChangeSet = false;
|
||||
|
||||
if (contentTypes.size() == 0) {
|
||||
if (contentTypes.isEmpty()) {
|
||||
throw new BatchDeserializerException("Missing content type",
|
||||
BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE, ""
|
||||
+ headers.getLineNumber());
|
||||
BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE,
|
||||
Integer.toString(headers.getLineNumber()));
|
||||
}
|
||||
|
||||
for (String contentType : contentTypes) {
|
||||
@ -69,14 +70,10 @@ public class BatchBodyPart implements BatchPart {
|
||||
|
||||
private List<BatchQueryOperation> consumeRequest(final List<Line> remainingMessage)
|
||||
throws BatchDeserializerException {
|
||||
if (isChangeSet) {
|
||||
return consumeChangeSet(remainingMessage);
|
||||
} else {
|
||||
return consumeQueryOperation(remainingMessage);
|
||||
}
|
||||
return isChangeSet ? consumeChangeSet(remainingMessage) : consumeQueryOperation(remainingMessage);
|
||||
}
|
||||
|
||||
private List<BatchQueryOperation> consumeChangeSet(final List<Line> remainingMessage2)
|
||||
private List<BatchQueryOperation> consumeChangeSet(List<Line> remainingMessage)
|
||||
throws BatchDeserializerException {
|
||||
final List<List<Line>> changeRequests = splitChangeSet(remainingMessage);
|
||||
final List<BatchQueryOperation> requestList = new LinkedList<BatchQueryOperation>();
|
||||
@ -103,7 +100,7 @@ public class BatchBodyPart implements BatchPart {
|
||||
if (changeSetBoundary.equals(boundary)) {
|
||||
throw new BatchDeserializerException("Change set boundary is equals to batch request boundary",
|
||||
BatchDeserializerException.MessageKeys.INVALID_BOUNDARY,
|
||||
"" + header.getHeaderField(HttpHeader.CONTENT_TYPE).getLineNumber());
|
||||
Integer.toString(header.getHeaderField(HttpHeader.CONTENT_TYPE).getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +113,12 @@ public class BatchBodyPart implements BatchPart {
|
||||
}
|
||||
|
||||
private boolean isContentTypeMultiPartMixed(final String contentType) {
|
||||
return BatchParserCommon.PATTERN_MULTIPART_BOUNDARY.matcher(contentType).matches();
|
||||
try {
|
||||
BatchParserCommon.getContentType(contentType, ContentType.MULTIPART_MIXED, 0);
|
||||
return true;
|
||||
} catch (final BatchDeserializerException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,7 +20,7 @@ package org.apache.olingo.server.core.deserializer.batch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
|
||||
public class BatchChangeSetPart extends BatchQueryOperation {
|
||||
private BatchQueryOperation request;
|
||||
|
@ -25,7 +25,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.ODataRuntimeException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
|
||||
|
@ -24,12 +24,12 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.olingo.commons.api.http.HttpContentType;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
|
||||
public class BatchParserCommon {
|
||||
|
||||
@ -38,47 +38,55 @@ public class BatchParserCommon {
|
||||
"(\\),/:=\\?]{1,69}[a-zA-Z0-9_\\-\\.'\\+\\(\\),/:=\\?])\"";
|
||||
private static final Pattern PATTERN_LAST_CRLF = Pattern.compile("(.*)(\r\n){1}( *)", Pattern.DOTALL);
|
||||
private static final Pattern PATTERN_HEADER_LINE = Pattern.compile("([a-zA-Z\\-]+):\\s?(.*)\\s*");
|
||||
private static final String REG_EX_APPLICATION_HTTP = "application/http";
|
||||
|
||||
public static final Pattern PATTERN_MULTIPART_BOUNDARY = Pattern.compile("multipart/mixed(.*)",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
public static final Pattern PATTERN_CONTENT_TYPE_APPLICATION_HTTP = Pattern.compile(REG_EX_APPLICATION_HTTP,
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
protected static final String HTTP_RANGE = "Range";
|
||||
protected static final String HTTP_TE = "TE";
|
||||
|
||||
public static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding";
|
||||
|
||||
protected static final String BOUNDARY = "boundary";
|
||||
public static final String BINARY_ENCODING = "binary";
|
||||
public static final String HTTP_CONTENT_ID = "Content-Id";
|
||||
public static final String HTTP_CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding";
|
||||
|
||||
public static final String HTTP_EXPECT = "Expect";
|
||||
public static final String HTTP_FROM = "From";
|
||||
public static final String HTTP_MAX_FORWARDS = "Max-Forwards";
|
||||
public static final String HTTP_RANGE = "Range";
|
||||
public static final String HTTP_TE = "TE";
|
||||
|
||||
public static String getBoundary(final String contentType, final int line) throws BatchDeserializerException {
|
||||
if (contentType == null) {
|
||||
throw new BatchDeserializerException("Missing content type",
|
||||
BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE, line);
|
||||
}
|
||||
final ContentType type = getContentType(contentType, ContentType.MULTIPART_MIXED, line);
|
||||
|
||||
if (contentType.toLowerCase(Locale.ENGLISH).startsWith("multipart/mixed")) {
|
||||
final String[] parameter = contentType.split(";");
|
||||
|
||||
for (final String pair : parameter) {
|
||||
|
||||
final String[] attrValue = pair.split("=");
|
||||
if (attrValue.length == 2 && "boundary".equals(attrValue[0].trim().toLowerCase(Locale.ENGLISH))) {
|
||||
if (attrValue[1].matches(REG_EX_BOUNDARY)) {
|
||||
return trimQuota(attrValue[1].trim());
|
||||
} else {
|
||||
throw new BatchDeserializerException("Invalid boundary format",
|
||||
BatchDeserializerException.MessageKeys.INVALID_BOUNDARY, "" + line);
|
||||
}
|
||||
String boundary;
|
||||
final Map<String, String> parameters = type.getParameters();
|
||||
for (final String parameterName : parameters.keySet()) {
|
||||
if (BOUNDARY.equalsIgnoreCase(parameterName)) {
|
||||
boundary = parameters.get(parameterName).trim();
|
||||
if (boundary.matches(REG_EX_BOUNDARY)) {
|
||||
return trimQuotes(boundary);
|
||||
} else {
|
||||
throw new BatchDeserializerException("Invalid boundary format",
|
||||
BatchDeserializerException.MessageKeys.INVALID_BOUNDARY, Integer.toString(line));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
throw new BatchDeserializerException("Content type is not multipart mixed",
|
||||
BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, HttpContentType.MULTIPART_MIXED);
|
||||
throw new BatchDeserializerException("Missing boundary.",
|
||||
BatchDeserializerException.MessageKeys.MISSING_BOUNDARY_DELIMITER, Integer.toString(line));
|
||||
}
|
||||
|
||||
public static ContentType getContentType(final String contentType, final ContentType expected, final int line)
|
||||
throws BatchDeserializerException {
|
||||
ContentType type = null;
|
||||
try {
|
||||
type = ContentType.create(contentType);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
if (contentType == null) {
|
||||
throw new BatchDeserializerException("Missing content type", e,
|
||||
BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE, Integer.toString(line));
|
||||
} else {
|
||||
throw new BatchDeserializerException("Invalid content type.", e,
|
||||
BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, Integer.toString(line));
|
||||
}
|
||||
}
|
||||
if (type.isCompatible(expected)) {
|
||||
return type;
|
||||
} else {
|
||||
throw new BatchDeserializerException("Content type is not the expected content type",
|
||||
BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, expected.toContentTypeString());
|
||||
}
|
||||
}
|
||||
|
||||
public static String removeEndingSlash(final String content) {
|
||||
@ -88,11 +96,10 @@ public class BatchParserCommon {
|
||||
return (lastSlashIndex == newContent.length() - 1) ? newContent.substring(0, newContent.length() - 1) : newContent;
|
||||
}
|
||||
|
||||
private static String trimQuota(final String boundary) {
|
||||
if (boundary.matches("\".*\"")) {
|
||||
return boundary.replace("\"", "");
|
||||
private static String trimQuotes(final String boundary) {
|
||||
if (boundary != null && boundary.length() >= 2 && boundary.startsWith("\"") && boundary.endsWith("\"")) {
|
||||
return boundary.substring(1, boundary.length() - 1);
|
||||
}
|
||||
|
||||
return boundary;
|
||||
}
|
||||
|
||||
@ -124,22 +131,21 @@ public class BatchParserCommon {
|
||||
}
|
||||
}
|
||||
|
||||
final int lineNumer = (message.size() > 0) ? message.get(0).getLineNumber() : 0;
|
||||
// Remove preamble
|
||||
if (messageParts.size() > 0) {
|
||||
messageParts.remove(0);
|
||||
}
|
||||
|
||||
if (!isEndReached) {
|
||||
final int lineNumber = (message.size() > 0) ? message.get(0).getLineNumber() : 0;
|
||||
throw new BatchDeserializerException("Missing close boundary delimiter",
|
||||
BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER,
|
||||
"" + lineNumer);
|
||||
BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER, Integer.toString(lineNumber));
|
||||
}
|
||||
|
||||
return messageParts;
|
||||
}
|
||||
|
||||
private static void removeEndingCRLFFromList(final List<Line> list) {
|
||||
private static void removeEndingCRLFFromList(List<Line> list) {
|
||||
if (list.size() > 0) {
|
||||
Line lastLine = list.remove(list.size() - 1);
|
||||
list.add(removeEndingCRLF(lastLine));
|
||||
@ -157,7 +163,7 @@ public class BatchParserCommon {
|
||||
}
|
||||
}
|
||||
|
||||
public static Header consumeHeaders(final List<Line> remainingMessage) {
|
||||
public static Header consumeHeaders(List<Line> remainingMessage) {
|
||||
final int headerLineNumber = remainingMessage.size() != 0 ? remainingMessage.get(0).getLineNumber() : 0;
|
||||
final Header headers = new Header(headerLineNumber);
|
||||
final Iterator<Line> iter = remainingMessage.iterator();
|
||||
@ -183,7 +189,7 @@ public class BatchParserCommon {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public static void consumeBlankLine(final List<Line> remainingMessage, final boolean isStrict)
|
||||
public static void consumeBlankLine(List<Line> remainingMessage, final boolean isStrict)
|
||||
throws BatchDeserializerException {
|
||||
if (remainingMessage.size() > 0 && remainingMessage.get(0).toString().matches("\\s*(\r\n|\n)\\s*")) {
|
||||
remainingMessage.remove(0);
|
||||
@ -191,8 +197,7 @@ public class BatchParserCommon {
|
||||
if (isStrict) {
|
||||
final int lineNumber = (remainingMessage.size() > 0) ? remainingMessage.get(0).getLineNumber() : 0;
|
||||
throw new BatchDeserializerException("Missing blank line",
|
||||
BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE, "[None]", ""
|
||||
+ lineNumber);
|
||||
BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE, "[None]", Integer.toString(lineNumber));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ package org.apache.olingo.server.core.deserializer.batch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
|
||||
public class BatchQueryOperation implements BatchPart {
|
||||
|
||||
|
@ -24,12 +24,13 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
|
||||
|
||||
public class BatchRequestTransformator {
|
||||
private final String baseUri;
|
||||
@ -73,23 +74,22 @@ public class BatchRequestTransformator {
|
||||
final HeaderField contentIdRequest = getContentId(request);
|
||||
|
||||
if (contentIdChangeRequestPart == null && contentIdRequest == null) {
|
||||
throw new BatchDeserializerException("Missing content id", MessageKeys.MISSING_CONTENT_ID, changeRequestPart
|
||||
.getHeaders()
|
||||
.getLineNumber());
|
||||
throw new BatchDeserializerException("Missing content id", MessageKeys.MISSING_CONTENT_ID,
|
||||
Integer.toString(changeRequestPart.getHeaders().getLineNumber()));
|
||||
} else if (contentIdChangeRequestPart != null) {
|
||||
request.getHeaders().replaceHeaderField(contentIdChangeRequestPart);
|
||||
}
|
||||
}
|
||||
|
||||
private HeaderField getContentId(final BatchQueryOperation queryOperation) throws BatchDeserializerException {
|
||||
final HeaderField contentTypeHeader = queryOperation.getHeaders().getHeaderField(BatchParserCommon.HTTP_CONTENT_ID);
|
||||
final HeaderField contentTypeHeader = queryOperation.getHeaders().getHeaderField(HttpHeader.CONTENT_ID);
|
||||
|
||||
if (contentTypeHeader != null) {
|
||||
if (contentTypeHeader.getValues().size() == 1) {
|
||||
return contentTypeHeader;
|
||||
} else {
|
||||
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, contentTypeHeader
|
||||
.getLineNumber());
|
||||
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER,
|
||||
Integer.toString(contentTypeHeader.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,10 +127,11 @@ public class BatchRequestTransformator {
|
||||
private void validateForbiddenHeader(final BatchQueryOperation operation) throws BatchDeserializerException {
|
||||
final Header header = operation.getHeaders();
|
||||
|
||||
if (header.exists(HttpHeader.AUTHORIZATION) || header.exists(BatchParserCommon.HTTP_EXPECT)
|
||||
|| header.exists(BatchParserCommon.HTTP_FROM) || header.exists(BatchParserCommon.HTTP_MAX_FORWARDS)
|
||||
if (header.exists(HttpHeader.AUTHORIZATION) || header.exists(HttpHeader.EXPECT)
|
||||
|| header.exists(HttpHeader.FROM) || header.exists(HttpHeader.MAX_FORWARDS)
|
||||
|| header.exists(BatchParserCommon.HTTP_RANGE) || header.exists(BatchParserCommon.HTTP_TE)) {
|
||||
throw new BatchDeserializerException("Forbidden header", MessageKeys.FORBIDDEN_HEADER, header.getLineNumber());
|
||||
throw new BatchDeserializerException("Forbidden header", MessageKeys.FORBIDDEN_HEADER,
|
||||
Integer.toString(header.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,8 +153,8 @@ public class BatchRequestTransformator {
|
||||
private void validateBody(final HttpRequestStatusLine statusLine, final BatchQueryOperation operation)
|
||||
throws BatchDeserializerException {
|
||||
if (statusLine.getMethod().equals(HttpMethod.GET) && isUnvalidGetRequestBody(operation)) {
|
||||
throw new BatchDeserializerException("Invalid request line", MessageKeys.INVALID_CONTENT, statusLine
|
||||
.getLineNumber());
|
||||
throw new BatchDeserializerException("Invalid request line", MessageKeys.INVALID_CONTENT,
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,7 +166,7 @@ public class BatchRequestTransformator {
|
||||
private void validateHeader(final BatchPart bodyPart, final boolean isChangeSet) throws BatchDeserializerException {
|
||||
final Header headers = bodyPart.getHeaders();
|
||||
|
||||
BatchTransformatorCommon.validateContentType(headers, BatchParserCommon.PATTERN_CONTENT_TYPE_APPLICATION_HTTP);
|
||||
BatchTransformatorCommon.validateContentType(headers, ContentType.APPLICATION_HTTP);
|
||||
if (isChangeSet) {
|
||||
BatchTransformatorCommon.validateContentTransferEncoding(headers);
|
||||
}
|
||||
@ -175,10 +176,10 @@ public class BatchRequestTransformator {
|
||||
final Header header = bodyPart.getHeaders();
|
||||
|
||||
if (bodyPart.isChangeSet()) {
|
||||
BatchTransformatorCommon.validateContentType(header, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY);
|
||||
BatchTransformatorCommon.validateContentType(header, ContentType.MULTIPART_MIXED);
|
||||
} else {
|
||||
BatchTransformatorCommon.validateContentTransferEncoding(header);
|
||||
BatchTransformatorCommon.validateContentType(header, BatchParserCommon.PATTERN_CONTENT_TYPE_APPLICATION_HTTP);
|
||||
BatchTransformatorCommon.validateContentType(header, ContentType.APPLICATION_HTTP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,32 +19,30 @@
|
||||
package org.apache.olingo.server.core.deserializer.batch;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.olingo.commons.api.http.HttpContentType;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
|
||||
|
||||
public class BatchTransformatorCommon {
|
||||
|
||||
public static void validateContentType(final Header headers, final Pattern pattern)
|
||||
public static void validateContentType(final Header headers, final ContentType expected)
|
||||
throws BatchDeserializerException {
|
||||
List<String> contentTypes = headers.getHeaders(HttpHeader.CONTENT_TYPE);
|
||||
final List<String> contentTypes = headers.getHeaders(HttpHeader.CONTENT_TYPE);
|
||||
|
||||
if (contentTypes.size() == 0) {
|
||||
throw new BatchDeserializerException("Missing content type", MessageKeys.MISSING_CONTENT_TYPE, headers
|
||||
.getLineNumber());
|
||||
if (contentTypes.isEmpty()) {
|
||||
throw new BatchDeserializerException("Missing content type", MessageKeys.MISSING_CONTENT_TYPE,
|
||||
Integer.toString(headers.getLineNumber()));
|
||||
}
|
||||
if (!headers.isHeaderMatching(HttpHeader.CONTENT_TYPE, pattern)) {
|
||||
|
||||
if (BatchParserCommon.getContentType(contentTypes.get(0), expected, headers.getLineNumber()) == null) {
|
||||
throw new BatchDeserializerException("Invalid content type", MessageKeys.INVALID_CONTENT_TYPE,
|
||||
HttpContentType.MULTIPART_MIXED + " or " + HttpContentType.APPLICATION_HTTP);
|
||||
expected.toContentTypeString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void validateContentTransferEncoding(final Header headers) throws BatchDeserializerException {
|
||||
final HeaderField contentTransferField = headers.getHeaderField(BatchParserCommon.HTTP_CONTENT_TRANSFER_ENCODING);
|
||||
final HeaderField contentTransferField = headers.getHeaderField(BatchParserCommon.CONTENT_TRANSFER_ENCODING);
|
||||
|
||||
if (contentTransferField != null) {
|
||||
final List<String> contentTransferValues = contentTransferField.getValues();
|
||||
@ -54,15 +52,16 @@ public class BatchTransformatorCommon {
|
||||
if (!BatchParserCommon.BINARY_ENCODING.equalsIgnoreCase(encoding)) {
|
||||
throw new BatchDeserializerException("Invalid content transfer encoding",
|
||||
MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING,
|
||||
headers.getLineNumber());
|
||||
Integer.toString(headers.getLineNumber()));
|
||||
}
|
||||
} else {
|
||||
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, headers.getLineNumber());
|
||||
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER,
|
||||
Integer.toString(headers.getLineNumber()));
|
||||
}
|
||||
} else {
|
||||
throw new BatchDeserializerException("Missing mandatory content transfer encoding",
|
||||
MessageKeys.MISSING_CONTENT_TRANSFER_ENCODING,
|
||||
headers.getLineNumber());
|
||||
Integer.toString(headers.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,14 +76,13 @@ public class BatchTransformatorCommon {
|
||||
|
||||
if (contentLength < 0) {
|
||||
throw new BatchDeserializerException("Invalid content length", MessageKeys.INVALID_CONTENT_LENGTH,
|
||||
contentLengthField
|
||||
.getLineNumber());
|
||||
Integer.toString(contentLengthField.getLineNumber()));
|
||||
}
|
||||
|
||||
return contentLength;
|
||||
} catch (NumberFormatException e) {
|
||||
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, contentLengthField
|
||||
.getLineNumber());
|
||||
throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER,
|
||||
Integer.toString(contentLengthField.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Header implements Iterable<HeaderField> {
|
||||
private final Map<String, HeaderField> headers = new HashMap<String, HeaderField>();
|
||||
@ -64,14 +63,6 @@ public class Header implements Iterable<HeaderField> {
|
||||
return field != null && field.getValues().size() != 0;
|
||||
}
|
||||
|
||||
public boolean isHeaderMatching(final String name, final Pattern pattern) {
|
||||
if (getHeaders(name).size() != 1) {
|
||||
return false;
|
||||
} else {
|
||||
return pattern.matcher(getHeaders(name).get(0)).matches();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeHeader(final String name) {
|
||||
headers.remove(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
|
||||
|
||||
public class HttpRequestStatusLine {
|
||||
private static final Pattern PATTERN_RELATIVE_URI = Pattern.compile("([^/][^?]*)(?:\\?(.*))?");
|
||||
@ -67,8 +67,8 @@ public class HttpRequestStatusLine {
|
||||
parseUri(parts[1], requestBaseUri);
|
||||
httpVersion = parseHttpVersion(parts[2]);
|
||||
} else {
|
||||
throw new BatchDeserializerException("Invalid status line", MessageKeys.INVALID_STATUS_LINE, statusLine
|
||||
.getLineNumber());
|
||||
throw new BatchDeserializerException("Invalid status line", MessageKeys.INVALID_STATUS_LINE,
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,8 +81,9 @@ public class HttpRequestStatusLine {
|
||||
} else {
|
||||
parseRelativeUri(rawUri);
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
throw new BatchDeserializerException("Malformed uri", MessageKeys.INVALID_URI, statusLine.getLineNumber());
|
||||
} catch (final URISyntaxException e) {
|
||||
throw new BatchDeserializerException("Malformed uri", e, MessageKeys.INVALID_URI,
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,8 +92,8 @@ public class HttpRequestStatusLine {
|
||||
final String relativeUri = removeLeadingSlash(rawUri.substring(baseUri.length()));
|
||||
parseRelativeUri(relativeUri);
|
||||
} else {
|
||||
throw new BatchDeserializerException("Base uri do not match", MessageKeys.INVALID_BASE_URI, statusLine
|
||||
.getLineNumber());
|
||||
throw new BatchDeserializerException("Base uri does not match", MessageKeys.INVALID_BASE_URI,
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,7 +107,8 @@ public class HttpRequestStatusLine {
|
||||
if (relativeUriMatcher.matches()) {
|
||||
buildUri(relativeUriMatcher.group(1), relativeUriMatcher.group(2));
|
||||
} else {
|
||||
throw new BatchDeserializerException("Malformed uri", MessageKeys.INVALID_URI, statusLine.getLineNumber());
|
||||
throw new BatchDeserializerException("Malformed uri", MessageKeys.INVALID_URI,
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,15 +129,15 @@ public class HttpRequestStatusLine {
|
||||
try {
|
||||
return HttpMethod.valueOf(method.trim());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new BatchDeserializerException("Illegal http method", MessageKeys.INVALID_METHOD, statusLine
|
||||
.getLineNumber());
|
||||
throw new BatchDeserializerException("Illegal http method", e, MessageKeys.INVALID_METHOD,
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
}
|
||||
}
|
||||
|
||||
private String parseHttpVersion(final String httpVersion) throws BatchDeserializerException {
|
||||
if (!HTTP_VERSION.equals(httpVersion.trim())) {
|
||||
throw new BatchDeserializerException("Invalid http version", MessageKeys.INVALID_HTTP_VERSION, statusLine
|
||||
.getLineNumber());
|
||||
throw new BatchDeserializerException("Invalid http version", MessageKeys.INVALID_HTTP_VERSION,
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
} else {
|
||||
return HTTP_VERSION;
|
||||
}
|
||||
@ -147,11 +149,11 @@ public class HttpRequestStatusLine {
|
||||
if (!validMethods.contains(getMethod().toString())) {
|
||||
if (isChangeSet) {
|
||||
throw new BatchDeserializerException("Invalid change set method", MessageKeys.INVALID_CHANGESET_METHOD,
|
||||
statusLine.getLineNumber());
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
} else {
|
||||
throw new BatchDeserializerException("Invalid query operation method",
|
||||
MessageKeys.INVALID_QUERY_OPERATION_METHOD,
|
||||
statusLine.getLineNumber());
|
||||
Integer.toString(statusLine.getLineNumber()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ import org.apache.olingo.commons.api.http.HttpContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchSerializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchSerializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
|
||||
import org.apache.olingo.server.api.serializer.BatchSerializerException;
|
||||
import org.apache.olingo.server.api.serializer.BatchSerializerException.MessageKeys;
|
||||
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
|
||||
|
||||
public class BatchResponseSerializer {
|
||||
@ -149,7 +149,7 @@ public class BatchResponseSerializer {
|
||||
|
||||
for (final String key : header.keySet()) {
|
||||
// Requests do never has a content id header
|
||||
if (!key.equalsIgnoreCase(BatchParserCommon.HTTP_CONTENT_ID)) {
|
||||
if (!key.equalsIgnoreCase(HttpHeader.CONTENT_ID)) {
|
||||
appendHeader(key, header.get(key), builder);
|
||||
}
|
||||
}
|
||||
@ -157,16 +157,14 @@ public class BatchResponseSerializer {
|
||||
appendHeader(HttpHeader.CONTENT_LENGTH, "" + contentLength, builder);
|
||||
}
|
||||
|
||||
private void
|
||||
appendBodyPartHeader(final ODataResponse response, final StringBuilder builder, final boolean isChangeSet)
|
||||
throws BatchSerializerException {
|
||||
private void appendBodyPartHeader(final ODataResponse response, final StringBuilder builder,
|
||||
final boolean isChangeSet) throws BatchSerializerException {
|
||||
appendHeader(HttpHeader.CONTENT_TYPE, HttpContentType.APPLICATION_HTTP, builder);
|
||||
appendHeader(BatchParserCommon.HTTP_CONTENT_TRANSFER_ENCODING, BatchParserCommon.BINARY_ENCODING, builder);
|
||||
appendHeader(BatchParserCommon.CONTENT_TRANSFER_ENCODING, BatchParserCommon.BINARY_ENCODING, builder);
|
||||
|
||||
if (isChangeSet) {
|
||||
if (response.getHeaders().get(BatchParserCommon.HTTP_CONTENT_ID) != null) {
|
||||
appendHeader(BatchParserCommon.HTTP_CONTENT_ID, response.getHeaders().get(BatchParserCommon.HTTP_CONTENT_ID),
|
||||
builder);
|
||||
if (response.getHeaders().get(HttpHeader.CONTENT_ID) != null) {
|
||||
appendHeader(HttpHeader.CONTENT_ID, response.getHeaders().get(HttpHeader.CONTENT_ID), builder);
|
||||
} else {
|
||||
throw new BatchSerializerException("Missing content id", MessageKeys.MISSING_CONTENT_ID);
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ import java.util.List;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchSerializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
|
||||
import org.apache.olingo.server.api.serializer.BatchSerializerException;
|
||||
import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
|
||||
import org.apache.olingo.server.api.serializer.PrimitiveValueSerializerOptions;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
|
@ -29,6 +29,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -45,12 +46,12 @@ import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.batch.BatchFacade;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchSerializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
|
||||
import org.apache.olingo.server.api.processor.BatchProcessor;
|
||||
import org.apache.olingo.server.api.serializer.BatchSerializerException;
|
||||
import org.apache.olingo.server.core.ODataHandler;
|
||||
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
|
||||
import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings;
|
||||
@ -364,7 +365,7 @@ public class MockedBatchHandlerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMineBodyPartTransitiv() throws Exception {
|
||||
public void mimeBodyPartTransitive() throws Exception {
|
||||
final String content = ""
|
||||
+ "--batch_12345" + CRLF
|
||||
+ "Content-Type: multipart/mixed; boundary=changeset_12345" + CRLF
|
||||
@ -528,7 +529,7 @@ public class MockedBatchHandlerTest {
|
||||
assertEquals("Content-Type: application/http" + CRLF, response.get(lineNumber++));
|
||||
assertEquals("Content-Transfer-Encoding: binary" + CRLF, response.get(lineNumber++));
|
||||
|
||||
assertTrue(response.get(lineNumber).contains("Content-Id:"));
|
||||
assertTrue(response.get(lineNumber).contains("Content-ID:"));
|
||||
String contentId = response.get(lineNumber).split(":")[1].trim();
|
||||
lineNumber++;
|
||||
|
||||
@ -538,10 +539,7 @@ public class MockedBatchHandlerTest {
|
||||
}
|
||||
|
||||
private Map<String, List<String>> getMimeHeader() {
|
||||
final Map<String, List<String>> header = new HashMap<String, List<String>>();
|
||||
header.put(HttpHeader.CONTENT_TYPE, Arrays.asList(new String[] { BATCH_CONTENT_TYPE }));
|
||||
|
||||
return header;
|
||||
return Collections.singletonMap(HttpHeader.CONTENT_TYPE, Collections.singletonList(BATCH_CONTENT_TYPE));
|
||||
}
|
||||
|
||||
private ODataRequest buildODataRequest(final String content, final Map<String, List<String>> header)
|
||||
@ -640,9 +638,9 @@ public class MockedBatchHandlerTest {
|
||||
oDataResponse.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||
}
|
||||
|
||||
final String contentId = request.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
|
||||
final String contentId = request.getHeader(HttpHeader.CONTENT_ID);
|
||||
if (contentId != null) {
|
||||
oDataResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, contentId);
|
||||
oDataResponse.setHeader(HttpHeader.CONTENT_ID, contentId);
|
||||
}
|
||||
|
||||
return oDataResponse;
|
||||
|
@ -44,7 +44,7 @@ public class BatchParserCommonTest {
|
||||
final Header header = BatchParserCommon.consumeHeaders(message);
|
||||
assertNotNull(header);
|
||||
|
||||
final List<String> contentIdHeaders = header.getHeaders(BatchParserCommon.HTTP_CONTENT_ID);
|
||||
final List<String> contentIdHeaders = header.getHeaders(HttpHeader.CONTENT_ID);
|
||||
assertNotNull(contentIdHeaders);
|
||||
assertEquals(2, contentIdHeaders.size());
|
||||
assertEquals("1", contentIdHeaders.get(0));
|
||||
@ -64,7 +64,7 @@ public class BatchParserCommonTest {
|
||||
final Header header = BatchParserCommon.consumeHeaders(message);
|
||||
assertNotNull(header);
|
||||
|
||||
final List<String> contentIdHeaders = header.getHeaders(BatchParserCommon.HTTP_CONTENT_ID);
|
||||
final List<String> contentIdHeaders = header.getHeaders(HttpHeader.CONTENT_ID);
|
||||
assertNotNull(contentIdHeaders);
|
||||
assertEquals(1, contentIdHeaders.size());
|
||||
assertEquals("1", contentIdHeaders.get(0));
|
||||
|
@ -32,10 +32,10 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BatchRequestParserTest {
|
||||
@ -143,7 +143,7 @@ public class BatchRequestParserTest {
|
||||
for (ODataRequest request : requests) {
|
||||
assertEquals(HttpMethod.POST, request.getMethod());
|
||||
assertEquals("100000", request.getHeader(HttpHeader.CONTENT_LENGTH));
|
||||
assertEquals("1", request.getHeader(BatchParserCommon.HTTP_CONTENT_ID));
|
||||
assertEquals("1", request.getHeader(HttpHeader.CONTENT_ID));
|
||||
assertEquals("application/octet-stream", request.getHeader(HttpHeader.CONTENT_TYPE));
|
||||
|
||||
final InputStream body = request.getBody();
|
||||
@ -213,7 +213,7 @@ public class BatchRequestParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundaryParameterWithQuotas() throws Exception {
|
||||
public void boundaryParameterWithQuotes() throws Exception {
|
||||
final String contentType = "multipart/mixed; boundary=\"batch_1.2+34:2j)0?\"";
|
||||
final String boundary = BatchParserCommon.getBoundary(contentType, 0);
|
||||
final String batch = ""
|
||||
@ -250,19 +250,19 @@ public class BatchRequestParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchWithoutBoundaryParameter() throws Exception {
|
||||
public void batchWithoutBoundaryParameter() throws Exception {
|
||||
final String invalidContentType = "multipart/mixed";
|
||||
|
||||
try {
|
||||
BatchParserCommon.getBoundary(invalidContentType, 0);
|
||||
fail();
|
||||
} catch (BatchDeserializerException e) {
|
||||
assertMessageKey(e, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE);
|
||||
assertMessageKey(e, BatchDeserializerException.MessageKeys.MISSING_BOUNDARY_DELIMITER);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoundaryParameterWithoutQuota() throws Exception {
|
||||
public void boundaryParameterWithoutQuote() throws Exception {
|
||||
final String invalidContentType = "multipart/mixed;boundary=batch_1740-bb:84-2f7f";
|
||||
|
||||
try {
|
||||
@ -917,13 +917,13 @@ public class BatchRequestParserTest {
|
||||
assertEquals(1, multipart.getRequests().size());
|
||||
final ODataRequest retrieveRequest = multipart.getRequests().get(0);
|
||||
|
||||
assertEquals("BBB", retrieveRequest.getHeader(BatchParserCommon.HTTP_CONTENT_ID));
|
||||
assertEquals("BBB", retrieveRequest.getHeader(HttpHeader.CONTENT_ID));
|
||||
} else {
|
||||
for (ODataRequest request : multipart.getRequests()) {
|
||||
if (HttpMethod.POST.equals(request.getMethod())) {
|
||||
assertEquals("1", request.getHeader(BatchParserCommon.HTTP_CONTENT_ID));
|
||||
assertEquals("1", request.getHeader(HttpHeader.CONTENT_ID));
|
||||
} else if (HttpMethod.PUT.equals(request.getMethod())) {
|
||||
assertEquals("2", request.getHeader(BatchParserCommon.HTTP_CONTENT_ID));
|
||||
assertEquals("2", request.getHeader(HttpHeader.CONTENT_ID));
|
||||
assertEquals("/$1/EmployeeName", request.getRawODataPath());
|
||||
assertEquals("http://localhost/odata/$1/EmployeeName", request.getRawRequestUri());
|
||||
}
|
||||
@ -1147,7 +1147,7 @@ public class BatchRequestParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForddenHeaderAuthorisation() throws Exception {
|
||||
public void forbiddenHeaderAuthorization() throws Exception {
|
||||
final String batch = ""
|
||||
+ "--batch_8194-cf13-1f56" + CRLF
|
||||
+ MIME_HEADERS
|
||||
@ -1162,7 +1162,7 @@ public class BatchRequestParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForddenHeaderExpect() throws Exception {
|
||||
public void forbiddenHeaderExpect() throws Exception {
|
||||
final String batch = ""
|
||||
+ "--batch_8194-cf13-1f56" + CRLF
|
||||
+ MIME_HEADERS
|
||||
@ -1177,7 +1177,7 @@ public class BatchRequestParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForddenHeaderFrom() throws Exception {
|
||||
public void forbiddenHeaderFrom() throws Exception {
|
||||
final String batch = ""
|
||||
+ "--batch_8194-cf13-1f56" + CRLF
|
||||
+ MIME_HEADERS
|
||||
@ -1192,7 +1192,7 @@ public class BatchRequestParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForddenHeaderRange() throws Exception {
|
||||
public void forbiddenHeaderRange() throws Exception {
|
||||
final String batch = ""
|
||||
+ "--batch_8194-cf13-1f56" + CRLF
|
||||
+ MIME_HEADERS
|
||||
@ -1207,7 +1207,7 @@ public class BatchRequestParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForddenHeaderMaxForwards() throws Exception {
|
||||
public void forbiddenHeaderMaxForwards() throws Exception {
|
||||
final String batch = ""
|
||||
+ "--batch_8194-cf13-1f56" + CRLF
|
||||
+ MIME_HEADERS
|
||||
@ -1222,7 +1222,7 @@ public class BatchRequestParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForddenHeaderTE() throws Exception {
|
||||
public void forbiddenHeaderTE() throws Exception {
|
||||
final String batch = ""
|
||||
+ "--batch_8194-cf13-1f56" + CRLF
|
||||
+ MIME_HEADERS
|
||||
|
@ -19,7 +19,6 @@
|
||||
package org.apache.olingo.server.core.deserializer.batch;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@ -72,14 +71,6 @@ public class HeaderTest {
|
||||
assertEquals(HttpContentType.MULTIPART_MIXED, header.getHeaders(HttpHeader.CONTENT_TYPE).get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatcher() {
|
||||
Header header = new Header(1);
|
||||
header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + ";boundary=123", 1);
|
||||
|
||||
assertTrue(header.isHeaderMatching(HttpHeader.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldName() {
|
||||
Header header = new Header(0);
|
||||
@ -107,13 +98,6 @@ public class HeaderTest {
|
||||
assertTrue(header.getHeaderField(HttpHeader.CONTENT_TYPE) != copy.getHeaderField(HttpHeader.CONTENT_TYPE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatcherNoHeader() {
|
||||
Header header = new Header(1);
|
||||
|
||||
assertFalse(header.isHeaderMatching(HttpHeader.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicatedAddList() {
|
||||
Header header = new Header(1);
|
||||
|
@ -22,8 +22,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerException.MessageKeys;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpRequestStatusLineTest {
|
||||
|
@ -29,11 +29,11 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
|
||||
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
|
||||
import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -46,7 +46,7 @@ public class BatchResponseSerializerTest {
|
||||
final List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
|
||||
ODataResponse response = new ODataResponse();
|
||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||
response.setHeader(HttpHeader.CONTENT_TYPE, "application/json");
|
||||
response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
|
||||
response.setContent(IOUtils.toInputStream("Walter Winter" + CRLF));
|
||||
|
||||
List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
|
||||
@ -55,7 +55,7 @@ public class BatchResponseSerializerTest {
|
||||
|
||||
ODataResponse changeSetResponse = new ODataResponse();
|
||||
changeSetResponse.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
|
||||
changeSetResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1");
|
||||
changeSetResponse.setHeader(HttpHeader.CONTENT_ID, "1");
|
||||
responses = new ArrayList<ODataResponse>(1);
|
||||
responses.add(changeSetResponse);
|
||||
parts.add(new ODataResponsePart(responses, true));
|
||||
@ -86,7 +86,7 @@ public class BatchResponseSerializerTest {
|
||||
assertTrue(body.get(line++).contains("--changeset_"));
|
||||
assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Id: 1" + CRLF, body.get(line++));
|
||||
assertEquals("Content-ID: 1" + CRLF, body.get(line++));
|
||||
assertEquals(CRLF, body.get(line++));
|
||||
assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Length: 0" + CRLF, body.get(line++));
|
||||
@ -110,7 +110,7 @@ public class BatchResponseSerializerTest {
|
||||
|
||||
ODataResponse changeSetResponse = new ODataResponse();
|
||||
changeSetResponse.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
|
||||
changeSetResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1");
|
||||
changeSetResponse.setHeader(HttpHeader.CONTENT_ID, "1");
|
||||
responses = new ArrayList<ODataResponse>(1);
|
||||
responses.add(changeSetResponse);
|
||||
parts.add(new ODataResponsePart(responses, true));
|
||||
@ -140,7 +140,7 @@ public class BatchResponseSerializerTest {
|
||||
assertTrue(body.get(line++).contains("--changeset_"));
|
||||
assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Id: 1" + CRLF, body.get(line++));
|
||||
assertEquals("Content-ID: 1" + CRLF, body.get(line++));
|
||||
assertEquals(CRLF, body.get(line++));
|
||||
assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Length: 0" + CRLF, body.get(line++));
|
||||
@ -189,7 +189,7 @@ public class BatchResponseSerializerTest {
|
||||
public void testChangeSetResponse() throws Exception {
|
||||
List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
|
||||
ODataResponse response = new ODataResponse();
|
||||
response.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1");
|
||||
response.setHeader(HttpHeader.CONTENT_ID, "1");
|
||||
response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
|
||||
|
||||
List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
|
||||
@ -214,7 +214,7 @@ public class BatchResponseSerializerTest {
|
||||
assertTrue(body.get(line++).contains("--changeset_"));
|
||||
assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Id: 1" + CRLF, body.get(line++));
|
||||
assertEquals("Content-ID: 1" + CRLF, body.get(line++));
|
||||
assertEquals(CRLF, body.get(line++));
|
||||
assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++));
|
||||
assertEquals("Content-Length: 0" + CRLF, body.get(line++));
|
||||
|
Loading…
x
Reference in New Issue
Block a user