You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/11/25 16:45:05 UTC
[3/3] olingo-odata4 git commit: [OLINGO-472] BatchDeserializer
refactoring
[OLINGO-472] BatchDeserializer refactoring
Signed-off-by: Christian Amend <ch...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/babc3a61
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/babc3a61
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/babc3a61
Branch: refs/heads/master
Commit: babc3a615461f467cfb662ca178de3b0fb20a4d1
Parents: 402e847
Author: Christian Holzer <c....@sap.com>
Authored: Thu Nov 20 17:40:54 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Tue Nov 25 16:36:59 2014 +0100
----------------------------------------------------------------------
.../fit/tecsvc/client/BatchClientITCase.java | 3 -
.../olingo/commons/api/http/HttpHeader.java | 7 +
.../olingo/server/api/batch/BatchException.java | 65 -----
.../olingo/server/api/batch/BatchFacade.java | 6 +-
.../exception/BatchDeserializerException.java | 66 +++++
.../api/batch/exception/BatchException.java | 47 ++++
.../exception/BatchSerializerExecption.java | 44 ++++
.../deserializer/FixedFormatDeserializer.java | 8 +-
.../batch/BatchDeserializerResult.java | 23 --
.../api/deserializer/batch/BatchOptions.java | 114 +++++++++
.../deserializer/batch/BatchRequestPart.java | 2 +-
.../server/api/processor/BatchProcessor.java | 2 +-
.../api/serializer/FixedFormatSerializer.java | 5 +-
.../apache/olingo/server/core/ODataHandler.java | 2 +-
.../core/batchhandler/BatchFascadeImpl.java | 48 ++++
.../server/core/batchhandler/BatchHandler.java | 17 +-
.../core/batchhandler/BatchOperationImpl.java | 47 ----
.../core/batchhandler/BatchPartHandler.java | 24 +-
.../BatchReferenceRewriter.java | 6 +-
.../FixedFormatDeserializerImpl.java | 17 +-
.../core/deserializer/batch/BatchBodyPart.java | 34 +--
.../deserializer/batch/BatchChangeSetPart.java | 7 +-
.../core/deserializer/batch/BatchParser.java | 40 ++-
.../deserializer/batch/BatchParserCommon.java | 52 ++--
.../deserializer/batch/BatchQueryOperation.java | 10 +-
.../batch/BatchRequestPartImpl.java | 2 +-
.../batch/BatchRequestTransformator.java | 65 ++---
.../deserializer/batch/BatchTransformator.java | 28 ---
.../batch/BatchTransformatorCommon.java | 33 +--
.../BufferedReaderIncludingLineEndings.java | 59 +----
.../server/core/deserializer/batch/Header.java | 8 +-
.../core/deserializer/batch/HeaderField.java | 154 ++++++------
.../batch/HttpRequestStatusLine.java | 60 +++--
.../server/core/deserializer/batch/Line.java | 72 ++++++
.../serializer/BatchResponseSerializer.java | 153 ++++--------
.../serializer/FixedFormatSerializerImpl.java | 13 +-
.../server-core-exceptions-i18n.properties | 42 ++--
.../batchhandler/MockedBatchHandlerTest.java | 73 +++---
.../deserializer/BatchParserCommonTest.java | 17 +-
.../deserializer/BatchRequestParserTest.java | 246 +++++++++----------
.../BufferedReaderIncludingLineEndingsTest.java | 77 +++---
.../server/core/deserializer/HeaderTest.java | 8 -
.../server/core/deserializer/StringUtil.java | 3 +-
.../serializer/BatchResponseSerializerTest.java | 175 +++++++++++++
.../serializer/BatchResponseWriterTest.java | 180 --------------
.../processor/TechnicalBatchProcessor.java | 86 +++++--
46 files changed, 1212 insertions(+), 1038 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
index f2e1ab6..3d6fba9 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
@@ -24,9 +24,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import java.math.BigDecimal;
import java.net.URI;
-import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
@@ -50,7 +48,6 @@ import org.apache.olingo.client.core.uri.URIUtils;
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.format.ODataFormat;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 675d108..23a396c 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
@@ -162,4 +162,11 @@ public interface HttpHeader {
*/
public static final String ODATA_MAX_VERSION = "OData-MaxVersion";
+ /**
+ * OData Prefer Header
+ * See {@link <a href="http://docs.oasis-open.org/odata/odata/v4.0/errata01/os/complete/part1-protocol/
+ * odata-v4.0-errata01-os-part1-protocol-complete.html#_Toc399426728">OData Version 4.0 Part 1:
+ * Protocol Plus Errata 01</a>}
+ */
+ public static final String PREFER = "Prefer";
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchException.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchException.java
deleted file mode 100644
index 8da47a8..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchException.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;
-
-import org.apache.olingo.server.api.ODataTranslatedException;
-
-public class BatchException extends ODataTranslatedException {
- 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_CONTENT_ID;
-
- @Override
- public String getKey() {
- return name();
- }
- }
-
- private static final long serialVersionUID = -907752788975531134L;
-
- public BatchException(final String developmentMessage, final MessageKey messageKey, final int lineNumber) {
- this(developmentMessage, messageKey, "" + lineNumber);
- }
-
- public BatchException(final String developmentMessage, final MessageKey messageKey, final String... parameters) {
- super(developmentMessage, messageKey, parameters);
- }
-
- @Override
- protected String getBundleName() {
- return DEFAULT_SERVER_BUNDLE_NAME;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchFacade.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchFacade.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchFacade.java
index 7e85136..7785dc0 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchFacade.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/BatchFacade.java
@@ -19,11 +19,13 @@
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.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
public interface BatchFacade {
- public ODataResponse handleODataRequest(ODataRequest request, BatchRequestPart requestPart) throws BatchException;
+ public ODataResponse handleODataRequest(ODataRequest request, BatchRequestPart requestPart)
+ throws BatchDeserializerException;
- public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchException;
+ public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchDeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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
new file mode 100644
index 0000000..48f3815
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchDeserializerException.java
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+public class BatchDeserializerException extends BatchException {
+ 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;
+
+ @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);
+ }
+
+ @Override
+ protected String getBundleName() {
+ return DEFAULT_SERVER_BUNDLE_NAME;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchException.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchException.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchException.java
new file mode 100644
index 0000000..61f9ff2
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchException.java
@@ -0,0 +1,47 @@
+/*
+ * 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.ODataTranslatedException;
+
+public class BatchException extends ODataTranslatedException {
+ private static final long serialVersionUID = 8747815702545202733L;
+
+ public static enum MessageKeys implements MessageKey {
+ ;
+
+ @Override
+ public String getKey() {
+ return name();
+ }
+ }
+
+ public BatchException(final String developmentMessage, final MessageKey messageKey, final int lineNumber) {
+ this(developmentMessage, messageKey, "" + lineNumber);
+ }
+
+ public BatchException(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/babc3a61/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchSerializerExecption.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchSerializerExecption.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchSerializerExecption.java
new file mode 100644
index 0000000..9af85da
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/batch/exception/BatchSerializerExecption.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+public class BatchSerializerExecption extends BatchException {
+
+ private static final long serialVersionUID = 2634433974342796905L;
+
+ public static enum MessageKeys implements MessageKey {
+ MISSING_CONTENT_ID;
+
+ @Override
+ public String getKey() {
+ return name();
+ }
+ }
+
+ public BatchSerializerExecption(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/babc3a61/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 fc8e2d9..1eba75c 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
@@ -18,12 +18,14 @@
*/
package org.apache.olingo.server.api.deserializer;
+import java.io.InputStream;
import java.util.List;
-import org.apache.olingo.server.api.ODataRequest;
-import org.apache.olingo.server.api.batch.BatchException;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
+import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
public interface FixedFormatDeserializer {
- public List<BatchRequestPart> parseBatchRequest(ODataRequest request, boolean isStrict) throws BatchException;
+ public List<BatchRequestPart> parseBatchRequest(InputStream content, String boundary, BatchOptions options)
+ throws BatchDeserializerException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchDeserializerResult.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchDeserializerResult.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchDeserializerResult.java
deleted file mode 100644
index d397e33..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchDeserializerResult.java
+++ /dev/null
@@ -1,23 +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.deserializer.batch;
-
-public interface BatchDeserializerResult {
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchOptions.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchOptions.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchOptions.java
new file mode 100644
index 0000000..e01d810
--- /dev/null
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchOptions.java
@@ -0,0 +1,114 @@
+/*
+ * 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 java.io.InputStream;
+
+import org.apache.olingo.server.api.ODataRequest;
+import org.apache.olingo.server.api.deserializer.FixedFormatDeserializer;
+
+/**
+ * Options for the batch deserializer.
+ * See {@link FixedFormatDeserializer#parseBatchRequest(InputStream, String, BatchOptions)}
+ */
+public class BatchOptions {
+ private boolean isStrict = true;
+ private String rawBaseUri = "";
+ private String rawServiceResolutionUri = "";
+
+ private BatchOptions() { }
+
+ /**
+ * Returns if the batch parsing is strict.
+ * Default is true
+ *
+ * @return true if parsing is strict
+ */
+ public boolean isStrict() {
+ return isStrict;
+ }
+
+ /**
+ * See {@link ODataRequest#getRawBaseUri()}
+ */
+ public String getRawBaseUri() {
+ return rawBaseUri;
+ }
+
+ /**
+ * See {@link ODataRequest#getRawServiceResolutionUri()}
+ */
+ public String getRawServiceResolutionUri() {
+ return rawServiceResolutionUri;
+ }
+
+ /**
+ * Creates a new BatchOptions builder
+ *
+ * @return new BatchOptions builder instance
+ */
+ public static Builder with() {
+ return new Builder();
+ }
+
+ /**
+ * BatchOptions builder
+ */
+ public static class Builder {
+ private BatchOptions options;
+
+ /** Initializes the options builder. */
+ public Builder() {
+ options = new BatchOptions();
+ }
+
+ /**
+ * See {@link BatchOptions#isStrict()}
+ */
+ public Builder isStrict(boolean isStrict) {
+ options.isStrict = isStrict;
+ return this;
+ }
+
+ /**
+ * See {@link ODataRequest#getRawBaseUri()}
+ */
+ public Builder rawBaseUri(String baseUri) {
+ options.rawBaseUri = baseUri;
+ return this;
+ }
+
+ /**
+ * See {@link ODataRequest#getRawServiceResolutionUri()}
+ */
+ public Builder rawServiceResolutionUri(String serviceResolutionUri) {
+ options.rawServiceResolutionUri = serviceResolutionUri;
+ return this;
+ }
+
+ /**
+ * Creates a new BatchOptions instance
+ *
+ * @return new BatchOptions instance
+ */
+ public BatchOptions build() {
+ return options;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchRequestPart.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchRequestPart.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchRequestPart.java
index 928b8a0..f7025a3 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchRequestPart.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/deserializer/batch/BatchRequestPart.java
@@ -26,7 +26,7 @@ import org.apache.olingo.server.api.ODataRequest;
* A BatchPart
* <p> BatchPart represents a distinct MIME part of a Batch Request body. It can be ChangeSet or Query Operation
*/
-public interface BatchRequestPart extends BatchDeserializerResult {
+public interface BatchRequestPart {
/**
* Get the info if a BatchPart is a ChangeSet
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/BatchProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/BatchProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/BatchProcessor.java
index 5faece4..99dc12b 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/BatchProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/BatchProcessor.java
@@ -22,8 +22,8 @@ import java.util.List;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.batch.BatchException;
import org.apache.olingo.server.api.batch.BatchFacade;
+import org.apache.olingo.server.api.batch.exception.BatchException;
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
import org.apache.olingo.server.api.serializer.SerializerException;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 35780ed..28ed0ef 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,8 +22,7 @@ import java.io.InputStream;
import java.util.List;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.batch.BatchException;
+import org.apache.olingo.server.api.batch.exception.BatchSerializerExecption;
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
/** OData serializer for fixed output formats. */
@@ -52,5 +51,5 @@ public interface FixedFormatSerializer {
// TODO: Document
// TODO: Return type
- void writeResponseParts(List<ODataResponsePart> batchResponses, ODataResponse response) throws BatchException;
+ InputStream batchResponse(List<ODataResponsePart> batchResponses, String boundary) throws BatchSerializerExecption;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
index 4467778..63d0dce 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
@@ -35,7 +35,7 @@ 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.BatchException;
+import org.apache.olingo.server.api.batch.exception.BatchException;
import org.apache.olingo.server.api.processor.BatchProcessor;
import org.apache.olingo.server.api.processor.ComplexCollectionProcessor;
import org.apache.olingo.server.api.processor.ComplexProcessor;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFascadeImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFascadeImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFascadeImpl.java
new file mode 100644
index 0000000..9f2a5c9
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchFascadeImpl.java
@@ -0,0 +1,48 @@
+/*
+ * 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.core.batchhandler;
+
+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.BatchRequestPart;
+import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
+import org.apache.olingo.server.api.processor.BatchProcessor;
+import org.apache.olingo.server.core.ODataHandler;
+
+public class BatchFascadeImpl implements BatchFacade {
+ private final BatchPartHandler partHandler;
+
+ public BatchFascadeImpl(ODataHandler oDataHandler, ODataRequest request, BatchProcessor batchProcessor,
+ final boolean isStrict) {
+ partHandler = new BatchPartHandler(oDataHandler, batchProcessor, this);
+ }
+
+ @Override
+ public ODataResponse handleODataRequest(ODataRequest request, BatchRequestPart requestPart)
+ throws BatchDeserializerException {
+ return partHandler.handleODataRequest(request, requestPart);
+ }
+
+ @Override
+ public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchDeserializerException {
+ return partHandler.handleBatchRequest(request);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 9b3ece1..b2d8647 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
@@ -22,9 +22,10 @@ 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.BatchException;
import org.apache.olingo.server.api.batch.BatchFacade;
-import org.apache.olingo.server.api.batch.BatchException.MessageKeys;
+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.batch.exception.BatchException;
import org.apache.olingo.server.api.processor.BatchProcessor;
import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.core.ODataHandler;
@@ -44,26 +45,26 @@ public class BatchHandler {
throws SerializerException, BatchException {
validateRequest(request);
- final BatchFacade operation = new BatchOperationImpl(oDataHandler, request, batchProcessor, isStrict);
+ final BatchFacade operation = new BatchFascadeImpl(oDataHandler, request, batchProcessor, isStrict);
batchProcessor.executeBatch(operation, request, response);
}
- private void validateRequest(final ODataRequest request) throws BatchException {
+ private void validateRequest(final ODataRequest request) throws BatchDeserializerException {
validateHttpMethod(request);
validateContentType(request);
}
- private void validateContentType(final ODataRequest request) throws BatchException {
+ 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 BatchException("Invalid content type", MessageKeys.INVALID_CONTENT_TYPE, 0);
+ throw new BatchDeserializerException("Invalid content type", MessageKeys.INVALID_CONTENT_TYPE, 0);
}
}
- private void validateHttpMethod(final ODataRequest request) throws BatchException {
+ private void validateHttpMethod(final ODataRequest request) throws BatchDeserializerException {
if (request.getMethod() != HttpMethod.POST) {
- throw new BatchException("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/babc3a61/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchOperationImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchOperationImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchOperationImpl.java
deleted file mode 100644
index 281ccba..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchOperationImpl.java
+++ /dev/null
@@ -1,47 +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.core.batchhandler;
-
-import org.apache.olingo.server.api.ODataRequest;
-import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.api.batch.BatchFacade;
-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.core.ODataHandler;
-
-public class BatchOperationImpl implements BatchFacade {
- private final BatchPartHandler partHandler;
-
- public BatchOperationImpl(ODataHandler oDataHandler, ODataRequest request, BatchProcessor batchProcessor,
- final boolean isStrict) {
- partHandler = new BatchPartHandler(oDataHandler, batchProcessor, this);
- }
-
- @Override
- public ODataResponse handleODataRequest(ODataRequest request, BatchRequestPart requestPart) throws BatchException {
- return partHandler.handleODataRequest(request, requestPart);
- }
-
- @Override
- public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchException {
- return partHandler.handleBatchRequest(request);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 734dfb4..ab12c6a 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
@@ -20,8 +20,8 @@ package org.apache.olingo.server.core.batchhandler;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.batch.BatchException;
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.BatchRequestPart;
import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
import org.apache.olingo.server.api.processor.BatchProcessor;
@@ -32,25 +32,26 @@ import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
public class BatchPartHandler {
private final ODataHandler oDataHandler;
private final BatchProcessor batchProcessor;
- private final BatchFacade batchOperation;
+ private final BatchFacade batchFascade;
private final BatchReferenceRewriter rewriter;
public BatchPartHandler(final ODataHandler oDataHandler, final BatchProcessor processor,
- final BatchFacade batchOperation) {
+ final BatchFacade batchFascade) {
this.oDataHandler = oDataHandler;
this.batchProcessor = processor;
- this.batchOperation = batchOperation;
+ this.batchFascade = batchFascade;
rewriter = new BatchReferenceRewriter();
}
- public ODataResponse handleODataRequest(ODataRequest request, BatchRequestPart requestPart) throws BatchException {
+ public ODataResponse handleODataRequest(ODataRequest request, BatchRequestPart requestPart)
+ throws BatchDeserializerException {
final ODataResponse response;
if (requestPart.isChangeSet()) {
rewriter.replaceReference(request, requestPart);
response = oDataHandler.process(request);
-
+
rewriter.addMapping(request, response, requestPart);
} else {
response = oDataHandler.process(request);
@@ -65,18 +66,17 @@ public class BatchPartHandler {
return response;
}
- public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchException {
+ public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchDeserializerException {
if (request.isChangeSet()) {
return handleChangeSet(request);
} else {
final ODataResponse response = handleODataRequest(request.getRequests().get(0), request);
-
+
return new ODataResponsePart(response, false);
}
}
-
- private ODataResponsePart handleChangeSet(BatchRequestPart request) throws BatchException {
- return batchProcessor.executeChangeSet(batchOperation, request.getRequests(), request);
+
+ private ODataResponsePart handleChangeSet(BatchRequestPart request) {
+ return batchProcessor.executeChangeSet(batchFascade, request.getRequests(), request);
}
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 2acf45c..1da892f 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,7 +28,7 @@ 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.BatchException;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
import org.apache.olingo.server.core.deserializer.batch.HttpRequestStatusLine.ODataURI;
@@ -80,7 +80,7 @@ public class BatchReferenceRewriter {
}
public void addMapping(ODataRequest request, ODataResponse response, BatchRequestPart requestPart)
- throws BatchException {
+ throws BatchDeserializerException {
final UriMapping mapping = getUriMappingOrDefault(requestPart);
final String resourceUri = getODataPath(request, response);
final String contentId = request.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
@@ -88,7 +88,7 @@ public class BatchReferenceRewriter {
mapping.addMapping(contentId, resourceUri);
}
- private String getODataPath(ODataRequest request, ODataResponse response) throws BatchException {
+ private String getODataPath(ODataRequest request, ODataResponse response) throws BatchDeserializerException {
String resourceUri = null;
if (request.getMethod() == HttpMethod.POST) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 8ab3950..65feae7 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
@@ -18,12 +18,12 @@
*/
package org.apache.olingo.server.core.deserializer;
+import java.io.InputStream;
import java.util.List;
-import org.apache.olingo.commons.api.http.HttpHeader;
-import org.apache.olingo.server.api.ODataRequest;
-import org.apache.olingo.server.api.batch.BatchException;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
import org.apache.olingo.server.api.deserializer.FixedFormatDeserializer;
+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;
@@ -31,13 +31,10 @@ public class FixedFormatDeserializerImpl implements FixedFormatDeserializer {
// TODO: Deserializer
@Override
- public List<BatchRequestPart> parseBatchRequest(ODataRequest request, boolean isStrict) throws BatchException {
- BatchParser parser = new BatchParser();
- return parser.parseBatchRequest(request.getBody(), getContentType(request), request.getRawBaseUri(),
- request.getRawServiceResolutionUri(), isStrict);
- }
+ public List<BatchRequestPart> parseBatchRequest(InputStream content, String boundary, BatchOptions options)
+ throws BatchDeserializerException {
+ final BatchParser parser = new BatchParser();
- private String getContentType(ODataRequest request) {
- return request.getHeader(HttpHeader.CONTENT_TYPE);
+ return parser.parseBatchRequest(content, boundary, options);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 ae00891..a11b886 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
@@ -6,9 +6,9 @@
* 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
@@ -22,8 +22,7 @@ import java.util.LinkedList;
import java.util.List;
import org.apache.olingo.commons.api.http.HttpHeader;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings.Line;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
public class BatchBodyPart implements BatchPart {
final private String boundary;
@@ -40,7 +39,7 @@ public class BatchBodyPart implements BatchPart {
remainingMessage.addAll(message);
}
- public BatchBodyPart parse() throws BatchException {
+ public BatchBodyPart parse() throws BatchDeserializerException {
headers = BatchParserCommon.consumeHeaders(remainingMessage);
BatchParserCommon.consumeBlankLine(remainingMessage, isStrict);
isChangeSet = isChangeSet(headers);
@@ -49,13 +48,14 @@ public class BatchBodyPart implements BatchPart {
return this;
}
- private boolean isChangeSet(final Header header) throws BatchException {
+ private boolean isChangeSet(final Header header) throws BatchDeserializerException {
final List<String> contentTypes = headers.getHeaders(HttpHeader.CONTENT_TYPE);
boolean isChangeSet = false;
if (contentTypes.size() == 0) {
- throw new BatchException("Missing content type", BatchException.MessageKeys.MISSING_CONTENT_TYPE, ""
- + headers.getLineNumber());
+ throw new BatchDeserializerException("Missing content type",
+ BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE, ""
+ + headers.getLineNumber());
}
for (String contentType : contentTypes) {
@@ -67,7 +67,8 @@ public class BatchBodyPart implements BatchPart {
return isChangeSet;
}
- private List<BatchQueryOperation> consumeRequest(final List<Line> remainingMessage) throws BatchException {
+ private List<BatchQueryOperation> consumeRequest(final List<Line> remainingMessage)
+ throws BatchDeserializerException {
if (isChangeSet) {
return consumeChangeSet(remainingMessage);
} else {
@@ -75,7 +76,8 @@ public class BatchBodyPart implements BatchPart {
}
}
- private List<BatchQueryOperation> consumeChangeSet(final List<Line> remainingMessage2) throws BatchException {
+ private List<BatchQueryOperation> consumeChangeSet(final List<Line> remainingMessage2)
+ throws BatchDeserializerException {
final List<List<Line>> changeRequests = splitChangeSet(remainingMessage);
final List<BatchQueryOperation> requestList = new LinkedList<BatchQueryOperation>();
@@ -86,7 +88,7 @@ public class BatchBodyPart implements BatchPart {
return requestList;
}
- private List<List<Line>> splitChangeSet(final List<Line> remainingMessage2) throws BatchException {
+ private List<List<Line>> splitChangeSet(final List<Line> remainingMessage2) throws BatchDeserializerException {
final HeaderField contentTypeField = headers.getHeaderField(HttpHeader.CONTENT_TYPE);
final String changeSetBoundary = BatchParserCommon.getBoundary(contentTypeField.getValueNotNull(),
@@ -96,15 +98,17 @@ public class BatchBodyPart implements BatchPart {
return BatchParserCommon.splitMessageByBoundary(remainingMessage, changeSetBoundary);
}
- private void validateChangeSetBoundary(final String changeSetBoundary, final Header header) throws BatchException {
+ private void validateChangeSetBoundary(final String changeSetBoundary, final Header header)
+ throws BatchDeserializerException {
if (changeSetBoundary.equals(boundary)) {
- throw new BatchException("Change set boundary is equals to batch request boundary",
- BatchException.MessageKeys.INVALID_BOUNDARY,
+ throw new BatchDeserializerException("Change set boundary is equals to batch request boundary",
+ BatchDeserializerException.MessageKeys.INVALID_BOUNDARY,
"" + header.getHeaderField(HttpHeader.CONTENT_TYPE).getLineNumber());
}
}
- private List<BatchQueryOperation> consumeQueryOperation(final List<Line> remainingMessage) throws BatchException {
+ private List<BatchQueryOperation> consumeQueryOperation(final List<Line> remainingMessage)
+ throws BatchDeserializerException {
final List<BatchQueryOperation> requestList = new LinkedList<BatchQueryOperation>();
requestList.add(new BatchQueryOperation(remainingMessage, isStrict).parse());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 a2f8da5..47210c3 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,18 +20,17 @@ package org.apache.olingo.server.core.deserializer.batch;
import java.util.List;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings.Line;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
public class BatchChangeSetPart extends BatchQueryOperation {
private BatchQueryOperation request;
- public BatchChangeSetPart(final List<Line> message, final boolean isStrict) throws BatchException {
+ public BatchChangeSetPart(final List<Line> message, final boolean isStrict) throws BatchDeserializerException {
super(message, isStrict);
}
@Override
- public BatchChangeSetPart parse() throws BatchException {
+ public BatchChangeSetPart parse() throws BatchDeserializerException {
headers = BatchParserCommon.consumeHeaders(message);
BatchParserCommon.consumeBlankLine(message, isStrict);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 675966a..f7a78b8 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,33 +25,28 @@ import java.util.LinkedList;
import java.util.List;
import org.apache.olingo.commons.api.ODataRuntimeException;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerResult;
+import org.apache.olingo.server.api.batch.exception.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.BufferedReaderIncludingLineEndings.Line;
public class BatchParser {
- private String contentTypeMime;
- private String rawServiceResolutionUri;
- private boolean isStrict;
+ private BatchOptions options;
- @SuppressWarnings("unchecked")
- public List<BatchRequestPart> parseBatchRequest(final InputStream in, final String contentType, final String baseUri,
- final String serviceResolutionUri, final boolean isStrict) throws BatchException {
+ public List<BatchRequestPart> parseBatchRequest(InputStream content, String boundary, BatchOptions options)
+ throws BatchDeserializerException {
+ this.options = options;
- contentTypeMime = contentType;
- this.isStrict = isStrict;
- this.rawServiceResolutionUri = serviceResolutionUri;
-
- return (List<BatchRequestPart>) parse(in, new BatchRequestTransformator(baseUri, rawServiceResolutionUri));
+ BatchRequestTransformator transformator = new BatchRequestTransformator(options.getRawBaseUri(),
+ options.getRawServiceResolutionUri());
+ return parse(content, boundary, transformator);
}
- private List<? extends BatchDeserializerResult> parse(final InputStream in,
+ private List<BatchRequestPart> parse(final InputStream in, String boundary,
final BatchRequestTransformator transformator)
- throws BatchException {
+ throws BatchDeserializerException {
try {
- return parseBatch(in, transformator);
+ return parseBatch(in, boundary, transformator);
} catch (IOException e) {
throw new ODataRuntimeException(e);
} finally {
@@ -63,14 +58,13 @@ public class BatchParser {
}
}
- private List<BatchDeserializerResult> parseBatch(final InputStream in, final BatchRequestTransformator transformator)
- throws IOException, BatchException {
- final String boundary = BatchParserCommon.getBoundary(contentTypeMime, 1);
- final List<BatchDeserializerResult> resultList = new LinkedList<BatchDeserializerResult>();
+ private List<BatchRequestPart> parseBatch(final InputStream in, final String boundary,
+ final BatchRequestTransformator transformator) throws IOException, BatchDeserializerException {
+ final List<BatchRequestPart> resultList = new LinkedList<BatchRequestPart>();
final List<List<Line>> bodyPartStrings = splitBodyParts(in, boundary);
for (List<Line> bodyPartString : bodyPartStrings) {
- BatchBodyPart bodyPart = new BatchBodyPart(bodyPartString, boundary, isStrict).parse();
+ BatchBodyPart bodyPart = new BatchBodyPart(bodyPartString, boundary, options.isStrict()).parse();
resultList.addAll(transformator.transform(bodyPart));
}
@@ -78,7 +72,7 @@ public class BatchParser {
}
private List<List<Line>> splitBodyParts(final InputStream in, final String boundary) throws IOException,
- BatchException {
+ BatchDeserializerException {
final BufferedReaderIncludingLineEndings reader = new BufferedReaderIncludingLineEndings(new InputStreamReader(in));
final List<Line> message = reader.toLineList();
reader.close();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 851a57b..b09f56b 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
@@ -6,9 +6,9 @@
* 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
@@ -29,8 +29,7 @@ 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.BatchException;
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings.Line;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
public class BatchParserCommon {
@@ -40,7 +39,7 @@ public class BatchParserCommon {
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,
@@ -48,14 +47,19 @@ public class BatchParserCommon {
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 BatchException {
+
+ 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);
+ }
+
if (contentType.toLowerCase(Locale.ENGLISH).startsWith("multipart/mixed")) {
final String[] parameter = contentType.split(";");
@@ -66,14 +70,15 @@ public class BatchParserCommon {
if (attrValue[1].matches(REG_EX_BOUNDARY)) {
return trimQuota(attrValue[1].trim());
} else {
- throw new BatchException("Invalid boundary format", BatchException.MessageKeys.INVALID_BOUNDARY, "" + line);
+ throw new BatchDeserializerException("Invalid boundary format",
+ BatchDeserializerException.MessageKeys.INVALID_BOUNDARY, "" + line);
}
}
}
}
- throw new BatchException("Content type is not multipart mixed",
- BatchException.MessageKeys.INVALID_CONTENT_TYPE, HttpContentType.MULTIPART_MIXED);
+ throw new BatchDeserializerException("Content type is not multipart mixed",
+ BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, HttpContentType.MULTIPART_MIXED);
}
public static String removeEndingSlash(String content) {
@@ -92,7 +97,7 @@ public class BatchParserCommon {
}
public static List<List<Line>> splitMessageByBoundary(final List<Line> message, final String boundary)
- throws BatchException {
+ throws BatchDeserializerException {
final List<List<Line>> messageParts = new LinkedList<List<Line>>();
List<Line> currentPart = new ArrayList<Line>();
boolean isEndReached = false;
@@ -126,7 +131,8 @@ public class BatchParserCommon {
}
if (!isEndReached) {
- throw new BatchException("Missing close boundary delimiter", BatchException.MessageKeys.MISSING_CLOSE_DELIMITER,
+ throw new BatchDeserializerException("Missing close boundary delimiter",
+ BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER,
"" + lineNumer);
}
@@ -177,26 +183,28 @@ public class BatchParserCommon {
return headers;
}
- public static void consumeBlankLine(final List<Line> remainingMessage, final boolean isStrict) throws BatchException {
- //TODO is \r\n to strict?
+ public static void consumeBlankLine(final List<Line> remainingMessage, final boolean isStrict)
+ throws BatchDeserializerException {
+ // TODO is \r\n to strict?
if (remainingMessage.size() > 0 && remainingMessage.get(0).toString().matches("\\s*(\r\n|\n)\\s*")) {
remainingMessage.remove(0);
} else {
if (isStrict) {
final int lineNumber = (remainingMessage.size() > 0) ? remainingMessage.get(0).getLineNumber() : 0;
- throw new BatchException("Missing blank line", BatchException.MessageKeys.MISSING_BLANK_LINE, "[None]", ""
- + lineNumber);
+ throw new BatchDeserializerException("Missing blank line",
+ BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE, "[None]", ""
+ + lineNumber);
}
}
}
- public static InputStream convertLineListToInputStream(List<Line> messageList) {
+ public static InputStream convertLineListToInputStream(final List<Line> messageList) {
final String message = lineListToString(messageList);
return new ByteArrayInputStream(message.getBytes());
}
- private static String lineListToString(List<Line> messageList) {
+ private static String lineListToString(final List<Line> messageList) {
final StringBuilder builder = new StringBuilder();
for (Line currentLine : messageList) {
@@ -205,15 +213,15 @@ public class BatchParserCommon {
return builder.toString();
}
-
+
public static String trimLineListToLength(final List<Line> list, final int length) {
final String message = lineListToString(list);
final int lastIndex = Math.min(length, message.length());
return (lastIndex > 0) ? message.substring(0, lastIndex) : "";
}
-
- public static InputStream convertLineListToInputStream(List<Line> list, int length) {
+
+ public static InputStream convertLineListToInputStream(final List<Line> list, final int length) {
final String message = trimLineListToLength(list, length);
return new ByteArrayInputStream(message.getBytes());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 faffd0f..efc9f32 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,8 +20,7 @@ package org.apache.olingo.server.core.deserializer.batch;
import java.util.List;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings.Line;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
public class BatchQueryOperation implements BatchPart {
@@ -37,7 +36,7 @@ public class BatchQueryOperation implements BatchPart {
this.message = message;
}
- public BatchQueryOperation parse() throws BatchException {
+ public BatchQueryOperation parse() throws BatchDeserializerException {
httpStatusLine = consumeHttpStatusLine(message);
headers = BatchParserCommon.consumeHeaders(message);
BatchParserCommon.consumeBlankLine(message, isStrict);
@@ -46,7 +45,7 @@ public class BatchQueryOperation implements BatchPart {
return this;
}
- protected Line consumeHttpStatusLine(final List<Line> message) throws BatchException {
+ protected Line consumeHttpStatusLine(final List<Line> message) throws BatchDeserializerException {
if (message.size() > 0 && !message.get(0).toString().trim().equals("")) {
final Line method = message.get(0);
message.remove(0);
@@ -54,7 +53,8 @@ public class BatchQueryOperation implements BatchPart {
return method;
} else {
final int line = (message.size() > 0) ? message.get(0).getLineNumber() : 0;
- throw new BatchException("Missing http request line", BatchException.MessageKeys.INVALID_STATUS_LINE, "" + line);
+ throw new BatchDeserializerException("Missing http request line",
+ BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE, "" + line);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestPartImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestPartImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestPartImpl.java
index c68e130..4054a0d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestPartImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestPartImpl.java
@@ -33,7 +33,7 @@ public class BatchRequestPartImpl implements BatchRequestPart {
private List<ODataRequest> requests = new ArrayList<ODataRequest>();
private boolean isChangeSet;
-
+
public BatchRequestPartImpl(final boolean isChangeSet, final List<ODataRequest> requests) {
this.isChangeSet = isChangeSet;
this.requests = requests;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 b169b9b..d0f3dd5 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
@@ -6,9 +6,9 @@
* 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
@@ -27,24 +27,23 @@ import java.util.List;
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.BatchException;
-import org.apache.olingo.server.api.batch.BatchException.MessageKeys;
-import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerResult;
+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.BatchRequestPart;
import org.apache.olingo.server.core.deserializer.batch.HttpRequestStatusLine.ODataURI;
-public class BatchRequestTransformator implements BatchTransformator {
+public class BatchRequestTransformator {
private final String baseUri;
private final String rawServiceResolutionUri;
public BatchRequestTransformator(final String baseUri, final String serviceResolutionUri) {
this.baseUri = baseUri;
- this.rawServiceResolutionUri = serviceResolutionUri;
+ rawServiceResolutionUri = serviceResolutionUri;
}
- @Override
- public List<BatchDeserializerResult> transform(final BatchBodyPart bodyPart) throws BatchException {
+ public List<BatchRequestPart> transform(final BatchBodyPart bodyPart) throws BatchDeserializerException {
final List<ODataRequest> requests = new LinkedList<ODataRequest>();
- final List<BatchDeserializerResult> resultList = new ArrayList<BatchDeserializerResult>();
+ final List<BatchRequestPart> resultList = new ArrayList<BatchRequestPart>();
validateBodyPartHeader(bodyPart);
@@ -56,9 +55,8 @@ public class BatchRequestTransformator implements BatchTransformator {
return resultList;
}
- private ODataRequest
- processQueryOperation(BatchBodyPart bodyPart, String baseUri, BatchQueryOperation queryOperation)
- throws BatchException {
+ private ODataRequest processQueryOperation(final BatchBodyPart bodyPart, final String baseUri,
+ final BatchQueryOperation queryOperation) throws BatchDeserializerException {
if (bodyPart.isChangeSet()) {
BatchQueryOperation encapsulatedQueryOperation = ((BatchChangeSetPart) queryOperation).getRequest();
handleContentId(queryOperation, encapsulatedQueryOperation);
@@ -70,46 +68,49 @@ public class BatchRequestTransformator implements BatchTransformator {
}
}
- private void handleContentId(BatchQueryOperation changeRequestPart, BatchQueryOperation request)
- throws BatchException {
+ private void handleContentId(final BatchQueryOperation changeRequestPart, final BatchQueryOperation request)
+ throws BatchDeserializerException {
final HeaderField contentIdChangeRequestPart = getContentId(changeRequestPart);
final HeaderField contentIdRequest = getContentId(request);
if (contentIdChangeRequestPart == null && contentIdRequest == null) {
- throw new BatchException("Missing content id", MessageKeys.MISSING_CONTENT_ID, changeRequestPart.getHeaders()
+ throw new BatchDeserializerException("Missing content id", MessageKeys.MISSING_CONTENT_ID, changeRequestPart
+ .getHeaders()
.getLineNumber());
} else if (contentIdChangeRequestPart != null) {
- request.getHeaders().replaceHeaderField(contentIdChangeRequestPart);
+ request.getHeaders().replaceHeaderField(contentIdChangeRequestPart);
}
}
- private HeaderField getContentId(final BatchQueryOperation queryOperation) throws BatchException {
+ private HeaderField getContentId(final BatchQueryOperation queryOperation) throws BatchDeserializerException {
final HeaderField contentTypeHeader = queryOperation.getHeaders().getHeaderField(BatchParserCommon.HTTP_CONTENT_ID);
if (contentTypeHeader != null) {
if (contentTypeHeader.getValues().size() == 1) {
return contentTypeHeader;
} else {
- throw new BatchException("Invalid header", MessageKeys.INVALID_HEADER, contentTypeHeader.getLineNumber());
+ throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, contentTypeHeader
+ .getLineNumber());
}
}
return null;
}
- private ODataRequest createRequest(BatchQueryOperation operation, String baseUri, boolean isChangeSet)
- throws BatchException {
+ private ODataRequest createRequest(final BatchQueryOperation operation, final String baseUri,
+ final boolean isChangeSet)
+ throws BatchDeserializerException {
final HttpRequestStatusLine statusLine =
new HttpRequestStatusLine(operation.getHttpStatusLine(), baseUri, rawServiceResolutionUri, operation
.getHeaders());
statusLine.validateHttpMethod(isChangeSet);
final ODataURI uri = statusLine.getUri();
-
+
validateBody(statusLine, operation);
InputStream bodyStrean = getBodyStream(operation, statusLine);
validateForbiddenHeader(operation);
-
+
final ODataRequest request = new ODataRequest();
request.setBody(bodyStrean);
request.setMethod(statusLine.getMethod());
@@ -126,18 +127,18 @@ public class BatchRequestTransformator implements BatchTransformator {
return request;
}
- private void validateForbiddenHeader(BatchQueryOperation operation) throws BatchException {
+ 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)
|| header.exists(BatchParserCommon.HTTP_RANGE) || header.exists(BatchParserCommon.HTTP_TE)) {
- throw new BatchException("Forbidden header", MessageKeys.FORBIDDEN_HEADER, header.getLineNumber());
+ throw new BatchDeserializerException("Forbidden header", MessageKeys.FORBIDDEN_HEADER, header.getLineNumber());
}
}
- private InputStream getBodyStream(BatchQueryOperation operation, HttpRequestStatusLine statusLine)
- throws BatchException {
+ private InputStream getBodyStream(final BatchQueryOperation operation, final HttpRequestStatusLine statusLine)
+ throws BatchDeserializerException {
if (statusLine.getMethod().equals(HttpMethod.GET)) {
return new ByteArrayInputStream(new byte[0]);
} else {
@@ -151,9 +152,11 @@ public class BatchRequestTransformator implements BatchTransformator {
}
}
- private void validateBody(HttpRequestStatusLine statusLine, BatchQueryOperation operation) throws BatchException {
+ private void validateBody(final HttpRequestStatusLine statusLine, final BatchQueryOperation operation)
+ throws BatchDeserializerException {
if (statusLine.getMethod().equals(HttpMethod.GET) && isUnvalidGetRequestBody(operation)) {
- throw new BatchException("Invalid request line", MessageKeys.INVALID_CONTENT, statusLine.getLineNumber());
+ throw new BatchDeserializerException("Invalid request line", MessageKeys.INVALID_CONTENT, statusLine
+ .getLineNumber());
}
}
@@ -162,7 +165,7 @@ public class BatchRequestTransformator implements BatchTransformator {
|| (operation.getBody().size() == 1 && !"".equals(operation.getBody().get(0).toString().trim()));
}
- private void validateHeader(BatchPart bodyPart, boolean isChangeSet) throws BatchException {
+ 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);
@@ -171,7 +174,7 @@ public class BatchRequestTransformator implements BatchTransformator {
}
}
- private void validateBodyPartHeader(BatchBodyPart bodyPart) throws BatchException {
+ private void validateBodyPartHeader(final BatchBodyPart bodyPart) throws BatchDeserializerException {
final Header header = bodyPart.getHeaders();
if (bodyPart.isChangeSet()) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformator.java
deleted file mode 100644
index 462a2e2..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformator.java
+++ /dev/null
@@ -1,28 +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.core.deserializer.batch;
-
-import java.util.List;
-
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.api.deserializer.batch.BatchDeserializerResult;
-
-public interface BatchTransformator {
- public List<BatchDeserializerResult> transform(BatchBodyPart bodyPart) throws BatchException;
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 4738641..2a55bed 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
@@ -6,9 +6,9 @@
* 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
@@ -23,25 +23,27 @@ import java.util.regex.Pattern;
import org.apache.olingo.commons.api.http.HttpContentType;
import org.apache.olingo.commons.api.http.HttpHeader;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.api.batch.BatchException.MessageKeys;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
public class BatchTransformatorCommon {
- public static void validateContentType(final Header headers, final Pattern pattern) throws BatchException {
+ public static void validateContentType(final Header headers, final Pattern pattern)
+ throws BatchDeserializerException {
List<String> contentTypes = headers.getHeaders(HttpHeader.CONTENT_TYPE);
if (contentTypes.size() == 0) {
- throw new BatchException("Missing content type", MessageKeys.MISSING_CONTENT_TYPE, headers.getLineNumber());
+ throw new BatchDeserializerException("Missing content type", MessageKeys.MISSING_CONTENT_TYPE, headers
+ .getLineNumber());
}
if (!headers.isHeaderMatching(HttpHeader.CONTENT_TYPE, pattern)) {
- throw new BatchException("Invalid content type", MessageKeys.INVALID_CONTENT_TYPE,
+ throw new BatchDeserializerException("Invalid content type", MessageKeys.INVALID_CONTENT_TYPE,
HttpContentType.MULTIPART_MIXED + " or " + HttpContentType.APPLICATION_HTTP);
}
}
- public static void validateContentTransferEncoding(Header headers) throws BatchException {
+ public static void validateContentTransferEncoding(final Header headers) throws BatchDeserializerException {
final HeaderField contentTransferField = headers.getHeaderField(BatchParserCommon.HTTP_CONTENT_TRANSFER_ENCODING);
if (contentTransferField != null) {
@@ -50,20 +52,21 @@ public class BatchTransformatorCommon {
String encoding = contentTransferValues.get(0);
if (!BatchParserCommon.BINARY_ENCODING.equalsIgnoreCase(encoding)) {
- throw new BatchException("Invalid content transfer encoding", MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING,
+ throw new BatchDeserializerException("Invalid content transfer encoding",
+ MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING,
headers.getLineNumber());
}
} else {
- throw new BatchException("Invalid header", MessageKeys.INVALID_HEADER, headers.getLineNumber());
+ throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, headers.getLineNumber());
}
} else {
- throw new BatchException("Missing mandatory content transfer encoding",
+ throw new BatchDeserializerException("Missing mandatory content transfer encoding",
MessageKeys.MISSING_CONTENT_TRANSFER_ENCODING,
headers.getLineNumber());
}
}
- public static int getContentLength(Header headers) throws BatchException {
+ public static int getContentLength(final Header headers) throws BatchDeserializerException {
final HeaderField contentLengthField = headers.getHeaderField(HttpHeader.CONTENT_LENGTH);
if (contentLengthField != null && contentLengthField.getValues().size() == 1) {
@@ -73,13 +76,15 @@ public class BatchTransformatorCommon {
int contentLength = Integer.parseInt(contentLengthValues.get(0));
if (contentLength < 0) {
- throw new BatchException("Invalid content length", MessageKeys.INVALID_CONTENT_LENGTH, contentLengthField
+ throw new BatchDeserializerException("Invalid content length", MessageKeys.INVALID_CONTENT_LENGTH,
+ contentLengthField
.getLineNumber());
}
return contentLength;
} catch (NumberFormatException e) {
- throw new BatchException("Invalid header", MessageKeys.INVALID_HEADER, contentLengthField.getLineNumber());
+ throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, contentLengthField
+ .getLineNumber());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndings.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndings.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndings.java
index 64b4bcb..2268a1d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndings.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndings.java
@@ -93,18 +93,18 @@ public class BufferedReaderIncludingLineEndings extends Reader {
return bytesRead;
}
-
+
public List<String> toList() throws IOException {
final List<String> result = new ArrayList<String>();
String currentLine;
-
+
while ((currentLine = readLine()) != null) {
result.add(currentLine);
}
return result;
}
-
+
public List<Line> toLineList() throws IOException {
final List<Line> result = new ArrayList<Line>();
String currentLine;
@@ -230,57 +230,4 @@ public class BufferedReaderIncludingLineEndings extends Reader {
return limit;
}
-
- public static class Line {
- private final int lineNumber;
- private final String content;
-
- public Line(final String content, final int lineNumber) {
- this.content = content;
- this.lineNumber = lineNumber;
- }
-
- public int getLineNumber() {
- return lineNumber;
- }
-
- @Override
- public String toString() {
- return content;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((content == null) ? 0 : content.hashCode());
- result = prime * result + lineNumber;
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- Line other = (Line) obj;
- if (content == null) {
- if (other.content != null) {
- return false;
- }
- } else if (!content.equals(other.content)) {
- return false;
- }
- if (lineNumber != other.lineNumber) {
- return false;
- }
- return true;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/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 a318201..a9b05b1 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
@@ -6,9 +6,9 @@
* 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
@@ -60,7 +60,7 @@ public class Header implements Iterable<HeaderField> {
public boolean exists(final String name) {
final HeaderField field = headers.get(name.toLowerCase(Locale.ENGLISH));
-
+
return field != null && field.getValues().size() != 0;
}
@@ -160,7 +160,7 @@ public class Header implements Iterable<HeaderField> {
public HeaderField next() {
return headers.get(keyIterator.next());
}
-
+
@Override
public void remove() {
throw new UnsupportedOperationException();