[OLINGO-659] clean-up in batch handling Change-Id: I016ada42ce0e9fb8e0cc021422f7f03fd5b06a9d
Signed-off-by: Christian Amend <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/21b36a89 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/21b36a89 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/21b36a89 Branch: refs/heads/olingo712 Commit: 21b36a898a0a2940c25dcf86d1efe93c12eb20c6 Parents: 4070e15 Author: Klaus Straubinger <[email protected]> Authored: Wed Jun 24 16:31:02 2015 +0200 Committer: Christian Amend <[email protected]> Committed: Wed Jun 24 16:33:42 2015 +0200 ---------------------------------------------------------------------- .../olingo/commons/api/format/ContentType.java | 3 +- .../olingo/commons/api/http/HttpHeader.java | 39 +++---- .../exception/BatchDeserializerException.java | 65 ------------ .../exception/BatchSerializerException.java | 46 --------- .../deserializer/FixedFormatDeserializer.java | 9 +- .../batch/BatchDeserializerException.java | 77 ++++++++++++++ .../serializer/BatchSerializerException.java | 45 +++++++++ .../api/serializer/FixedFormatSerializer.java | 8 +- .../apache/olingo/server/core/ErrorHandler.java | 2 +- .../server/core/requests/BatchRequest.java | 14 ++- .../core/batchhandler/BatchFacadeImpl.java | 5 +- .../server/core/batchhandler/BatchHandler.java | 14 ++- .../core/batchhandler/BatchPartHandler.java | 7 +- .../BatchReferenceRewriter.java | 13 +-- .../FixedFormatDeserializerImpl.java | 2 +- .../core/deserializer/batch/BatchBodyPart.java | 26 ++--- .../deserializer/batch/BatchChangeSetPart.java | 2 +- .../core/deserializer/batch/BatchParser.java | 2 +- .../deserializer/batch/BatchParserCommon.java | 101 ++++++++++--------- .../deserializer/batch/BatchQueryOperation.java | 2 +- .../batch/BatchRequestTransformator.java | 33 +++--- .../batch/BatchTransformatorCommon.java | 38 ++++--- .../server/core/deserializer/batch/Header.java | 9 -- .../batch/HttpRequestStatusLine.java | 32 +++--- .../serializer/BatchResponseSerializer.java | 18 ++-- .../serializer/FixedFormatSerializerImpl.java | 2 +- .../batchhandler/MockedBatchHandlerTest.java | 18 ++-- .../batch/BatchParserCommonTest.java | 4 +- .../batch/BatchRequestParserTest.java | 32 +++--- .../core/deserializer/batch/HeaderTest.java | 16 --- .../batch/HttpRequestStatusLineTest.java | 4 +- .../serializer/BatchResponseSerializerTest.java | 16 +-- 32 files changed, 349 insertions(+), 355 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java index 4e2eb04..aa30323 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java @@ -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"; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java index de804fc..f7b9364 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/http/HttpHeader.java @@ -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"; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchDeserializerException.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchDeserializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchDeserializerException.java deleted file mode 100644 index b00ae53..0000000 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchDeserializerException.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.server.api.batch.exception; - -import org.apache.olingo.server.api.deserializer.DeserializerException; - -public class BatchDeserializerException extends DeserializerException { - public static enum MessageKeys implements MessageKey { - INVALID_BOUNDARY, - INVALID_CHANGESET_METHOD, - INVALID_CONTENT, - INVALID_CONTENT_LENGTH, - INVALID_CONTENT_TRANSFER_ENCODING, - INVALID_CONTENT_TYPE, - INVALID_HEADER, - INVALID_HTTP_VERSION, - INVALID_METHOD, - INVALID_QUERY_OPERATION_METHOD, - INVALID_STATUS_LINE, - INVALID_URI, - MISSING_BLANK_LINE, - MISSING_BOUNDARY_DELIMITER, - MISSING_CLOSE_DELIMITER, - MISSING_CONTENT_ID, - MISSING_CONTENT_TRANSFER_ENCODING, - MISSING_CONTENT_TYPE, - MISSING_MANDATORY_HEADER, - FORBIDDEN_HEADER, - INVALID_BASE_URI; - - @Override - public String getKey() { - return name(); - } - } - - private static final long serialVersionUID = -907752788975531134L; - - public BatchDeserializerException(final String developmentMessage, final MessageKey messageKey, - final int lineNumber) { - this(developmentMessage, messageKey, "" + lineNumber); - } - - public BatchDeserializerException(final String developmentMessage, final MessageKey messageKey, - final String... parameters) { - super(developmentMessage, messageKey, parameters); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchSerializerException.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchSerializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchSerializerException.java deleted file mode 100644 index 9a645a1..0000000 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchSerializerException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.server.api.batch.exception; - -import org.apache.olingo.server.api.serializer.SerializerException; - -public class BatchSerializerException extends SerializerException { - - private static final long serialVersionUID = 2634433974342796905L; - - public static enum MessageKeys implements MessageKey { - MISSING_CONTENT_ID; - - @Override - public String getKey() { - return name(); - } - } - - public BatchSerializerException(final String developmentMessage, final MessageKey messageKey, - final String... parameters) { - super(developmentMessage, messageKey, parameters); - } - - @Override - protected String getBundleName() { - return DEFAULT_SERVER_BUNDLE_NAME; - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/FixedFormatDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/FixedFormatDeserializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/FixedFormatDeserializer.java index bded690..22dd711 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/FixedFormatDeserializer.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/FixedFormatDeserializer.java @@ -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; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchDeserializerException.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchDeserializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchDeserializerException.java new file mode 100644 index 0000000..fbc958b --- /dev/null +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchDeserializerException.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.server.api.deserializer.batch; + +import org.apache.olingo.server.api.deserializer.DeserializerException; + +public class BatchDeserializerException extends DeserializerException { + public static enum MessageKeys implements MessageKey { + INVALID_BOUNDARY, + INVALID_CHANGESET_METHOD, + INVALID_CONTENT, + INVALID_CONTENT_LENGTH, + INVALID_CONTENT_TRANSFER_ENCODING, + INVALID_CONTENT_TYPE, + INVALID_HEADER, + INVALID_HTTP_VERSION, + INVALID_METHOD, + INVALID_QUERY_OPERATION_METHOD, + INVALID_STATUS_LINE, + INVALID_URI, + MISSING_BLANK_LINE, + MISSING_BOUNDARY_DELIMITER, + MISSING_CLOSE_DELIMITER, + MISSING_CONTENT_ID, + MISSING_CONTENT_TRANSFER_ENCODING, + MISSING_CONTENT_TYPE, + MISSING_MANDATORY_HEADER, + FORBIDDEN_HEADER, + INVALID_BASE_URI; + + @Override + public String getKey() { + return name(); + } + } + + private static final long serialVersionUID = -907752788975531134L; + + /** + * 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); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/BatchSerializerException.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/BatchSerializerException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/BatchSerializerException.java new file mode 100644 index 0000000..fa193e9 --- /dev/null +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/BatchSerializerException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.server.api.serializer; + + +public class BatchSerializerException extends SerializerException { + + private static final long serialVersionUID = 2634433974342796905L; + + public static enum MessageKeys implements MessageKey { + MISSING_CONTENT_ID; + + @Override + public String getKey() { + return name(); + } + } + + public BatchSerializerException(final String developmentMessage, final MessageKey messageKey, + final String... parameters) { + super(developmentMessage, messageKey, parameters); + } + + @Override + protected String getBundleName() { + return DEFAULT_SERVER_BUNDLE_NAME; + } + +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java ---------------------------------------------------------------------- diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java index fc41c73..d15d5ce 100644 --- a/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java +++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/serializer/FixedFormatSerializer.java @@ -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; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java index b83d383..83b1f52 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ErrorHandler.java @@ -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; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java index a38f9d8..d14b5ad 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java @@ -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()); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFacadeImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFacadeImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFacadeImpl.java index 856897c..9bb042d 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFacadeImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFacadeImpl.java @@ -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); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java index 7568f67..d842c51 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java @@ -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"); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchPartHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchPartHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchPartHandler.java index de1dcb1..e115dcb 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchPartHandler.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchPartHandler.java @@ -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; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java index a39f8c5..b3ba074 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java @@ -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"); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java index 46910f1..7c54f1d 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java @@ -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; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java index cfb531f..f5d68e4 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java @@ -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 http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchChangeSetPart.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchChangeSetPart.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchChangeSetPart.java index 47210c3..3c596fd 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchChangeSetPart.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchChangeSetPart.java @@ -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; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParser.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParser.java index 17b10bc..5d251ec 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParser.java @@ -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; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/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 ed75acf..7fd17e5 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 @@ -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); - 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); - } + protected static final String HTTP_RANGE = "Range"; + protected static final String HTTP_TE = "TE"; - if (contentType.toLowerCase(Locale.ENGLISH).startsWith("multipart/mixed")) { - final String[] parameter = contentType.split(";"); + public static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; - for (final String pair : parameter) { + protected static final String BOUNDARY = "boundary"; + public static final String BINARY_ENCODING = "binary"; - 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); - } + public static String getBoundary(final String contentType, final int line) throws BatchDeserializerException { + final ContentType type = getContentType(contentType, ContentType.MULTIPART_MIXED, 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("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)); } } - throw new BatchDeserializerException("Content type is not multipart mixed", - BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, HttpContentType.MULTIPART_MIXED); + 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)); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java index efc9f32..8bbcb81 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java @@ -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 { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/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 16e8af3..57ecfbe 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 @@ -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); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java index e445e10..5c379e0 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java @@ -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())); } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java index a9b05b1..67a9757 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java @@ -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)); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java index c4fb8f7..efe1ce1 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java @@ -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())); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/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 3661907..577f083 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 @@ -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); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java index 6fd911b..dd15973 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java @@ -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; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java index 75496e3..47f7b86 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java @@ -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; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommonTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommonTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommonTest.java index 89656ab..137c89a 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommonTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommonTest.java @@ -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)); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestParserTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestParserTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestParserTest.java index a194cc9..e43840d 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestParserTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestParserTest.java @@ -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 http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java index 6ab6491..c18d227 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HeaderTest.java @@ -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; @@ -73,14 +72,6 @@ public class HeaderTest { } @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); header.addHeader("MyFieldNamE", "myValue", 1); @@ -108,13 +99,6 @@ public class HeaderTest { } @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); header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED, 1); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/21b36a89/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java index f859481..1d3bb1f 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLineTest.java @@ -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 {
