You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2015/02/17 10:53:41 UTC
[27/35] olingo-odata4 git commit: [OLINGO-575] Removed V4 server code
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index a34aa95..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/FixedFormatDeserializerImpl.java
+++ /dev/null
@@ -1,60 +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;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-
-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.BatchOptions;
-import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
-import org.apache.olingo.server.core.deserializer.batch.BatchParser;
-
-public class FixedFormatDeserializerImpl implements FixedFormatDeserializer {
-
- @Override
- public byte[] binary(InputStream content) throws DeserializerException {
- ByteArrayOutputStream result = new ByteArrayOutputStream();
- byte[] buffer = new byte[128];
- int count = -1;
- try {
- while ((count = content.read(buffer)) > -1) {
- result.write(buffer, 0, count);
- }
- result.flush();
- } catch (final IOException e) {
- throw new DeserializerException("An I/O exception occurred.", e,
- DeserializerException.MessageKeys.IO_EXCEPTION);
- }
- return result.toByteArray();
- }
-
- // TODO: Deserializer
- @Override
- public List<BatchRequestPart> parseBatchRequest(InputStream content, String boundary, BatchOptions options)
- throws BatchDeserializerException {
- final BatchParser parser = new BatchParser();
-
- return parser.parseBatchRequest(content, boundary, options);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index a11b886..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java
+++ /dev/null
@@ -1,139 +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.LinkedList;
-import java.util.List;
-
-import org.apache.olingo.commons.api.http.HttpHeader;
-import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
-
-public class BatchBodyPart implements BatchPart {
- final private String boundary;
- final private boolean isStrict;
- final List<Line> remainingMessage = new LinkedList<Line>();
-
- private Header headers;
- private boolean isChangeSet;
- private List<BatchQueryOperation> requests;
-
- public BatchBodyPart(final List<Line> message, final String boundary, final boolean isStrict) {
- this.boundary = boundary;
- this.isStrict = isStrict;
- remainingMessage.addAll(message);
- }
-
- public BatchBodyPart parse() throws BatchDeserializerException {
- headers = BatchParserCommon.consumeHeaders(remainingMessage);
- BatchParserCommon.consumeBlankLine(remainingMessage, isStrict);
- isChangeSet = isChangeSet(headers);
- requests = consumeRequest(remainingMessage);
-
- return this;
- }
-
- 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 BatchDeserializerException("Missing content type",
- BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE, ""
- + headers.getLineNumber());
- }
-
- for (String contentType : contentTypes) {
- if (isContentTypeMultiPartMixed(contentType)) {
- isChangeSet = true;
- }
- }
-
- return isChangeSet;
- }
-
- private List<BatchQueryOperation> consumeRequest(final List<Line> remainingMessage)
- throws BatchDeserializerException {
- if (isChangeSet) {
- return consumeChangeSet(remainingMessage);
- } else {
- return consumeQueryOperation(remainingMessage);
- }
- }
-
- private List<BatchQueryOperation> consumeChangeSet(final List<Line> remainingMessage2)
- throws BatchDeserializerException {
- final List<List<Line>> changeRequests = splitChangeSet(remainingMessage);
- final List<BatchQueryOperation> requestList = new LinkedList<BatchQueryOperation>();
-
- for (List<Line> changeRequest : changeRequests) {
- requestList.add(new BatchChangeSetPart(changeRequest, isStrict).parse());
- }
-
- return requestList;
- }
-
- 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(),
- contentTypeField.getLineNumber());
- validateChangeSetBoundary(changeSetBoundary, headers);
-
- return BatchParserCommon.splitMessageByBoundary(remainingMessage, changeSetBoundary);
- }
-
- private void validateChangeSetBoundary(final String changeSetBoundary, final Header header)
- throws BatchDeserializerException {
- 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());
- }
- }
-
- private List<BatchQueryOperation> consumeQueryOperation(final List<Line> remainingMessage)
- throws BatchDeserializerException {
- final List<BatchQueryOperation> requestList = new LinkedList<BatchQueryOperation>();
- requestList.add(new BatchQueryOperation(remainingMessage, isStrict).parse());
-
- return requestList;
- }
-
- private boolean isContentTypeMultiPartMixed(final String contentType) {
- return BatchParserCommon.PATTERN_MULTIPART_BOUNDARY.matcher(contentType).matches();
- }
-
- @Override
- public Header getHeaders() {
- return headers;
- }
-
- @Override
- public boolean isStrict() {
- return isStrict;
- }
-
- public boolean isChangeSet() {
- return isChangeSet;
- }
-
- public List<BatchQueryOperation> getRequests() {
- return requests;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index 47210c3..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchChangeSetPart.java
+++ /dev/null
@@ -1,55 +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.exception.BatchDeserializerException;
-
-public class BatchChangeSetPart extends BatchQueryOperation {
- private BatchQueryOperation request;
-
- public BatchChangeSetPart(final List<Line> message, final boolean isStrict) throws BatchDeserializerException {
- super(message, isStrict);
- }
-
- @Override
- public BatchChangeSetPart parse() throws BatchDeserializerException {
- headers = BatchParserCommon.consumeHeaders(message);
- BatchParserCommon.consumeBlankLine(message, isStrict);
-
- request = new BatchQueryOperation(message, isStrict).parse();
-
- return this;
- }
-
- public BatchQueryOperation getRequest() {
- return request;
- }
-
- @Override
- public List<Line> getBody() {
- return request.getBody();
- }
-
- @Override
- public Line getHttpStatusLine() {
- return request.getHttpStatusLine();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index f7a78b8..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParser.java
+++ /dev/null
@@ -1,82 +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.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-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.BatchOptions;
-import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
-
-public class BatchParser {
-
- private BatchOptions options;
-
- public List<BatchRequestPart> parseBatchRequest(InputStream content, String boundary, BatchOptions options)
- throws BatchDeserializerException {
- this.options = options;
-
- BatchRequestTransformator transformator = new BatchRequestTransformator(options.getRawBaseUri(),
- options.getRawServiceResolutionUri());
- return parse(content, boundary, transformator);
- }
-
- private List<BatchRequestPart> parse(final InputStream in, String boundary,
- final BatchRequestTransformator transformator)
- throws BatchDeserializerException {
- try {
- return parseBatch(in, boundary, transformator);
- } catch (IOException e) {
- throw new ODataRuntimeException(e);
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- throw new ODataRuntimeException(e);
- }
- }
- }
-
- 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, options.isStrict()).parse();
- resultList.addAll(transformator.transform(bodyPart));
- }
-
- return resultList;
- }
-
- private List<List<Line>> splitBodyParts(final InputStream in, final String boundary) throws IOException,
- BatchDeserializerException {
- final BufferedReaderIncludingLineEndings reader = new BufferedReaderIncludingLineEndings(new InputStreamReader(in));
- final List<Line> message = reader.toLineList();
- reader.close();
-
- return BatchParserCommon.splitMessageByBoundary(message, boundary);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index b09f56b..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
+++ /dev/null
@@ -1,229 +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.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-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;
-
-public class BatchParserCommon {
-
- private static final String REG_EX_BOUNDARY =
- "([a-zA-Z0-9_\\-\\.'\\+]{1,70})|\"([a-zA-Z0-9_\\-\\.'\\+\\s\\" +
- "(\\),/:=\\?]{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);
- }
-
- if (contentType.toLowerCase(Locale.ENGLISH).startsWith("multipart/mixed")) {
- final String[] parameter = contentType.split(";");
-
- for (final String pair : parameter) {
-
- final String[] attrValue = pair.split("=");
- if (attrValue.length == 2 && "boundary".equals(attrValue[0].trim().toLowerCase(Locale.ENGLISH))) {
- if (attrValue[1].matches(REG_EX_BOUNDARY)) {
- return trimQuota(attrValue[1].trim());
- } else {
- throw new BatchDeserializerException("Invalid boundary format",
- BatchDeserializerException.MessageKeys.INVALID_BOUNDARY, "" + line);
- }
- }
-
- }
- }
- throw new BatchDeserializerException("Content type is not multipart mixed",
- BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE, HttpContentType.MULTIPART_MIXED);
- }
-
- public static String removeEndingSlash(String content) {
- content = content.trim();
- int lastSlashIndex = content.lastIndexOf('/');
-
- return (lastSlashIndex == content.length() - 1) ? content.substring(0, content.length() - 1) : content;
- }
-
- private static String trimQuota(String boundary) {
- if (boundary.matches("\".*\"")) {
- boundary = boundary.replace("\"", "");
- }
-
- return boundary;
- }
-
- public static List<List<Line>> splitMessageByBoundary(final List<Line> message, final String boundary)
- throws BatchDeserializerException {
- final List<List<Line>> messageParts = new LinkedList<List<Line>>();
- List<Line> currentPart = new ArrayList<Line>();
- boolean isEndReached = false;
-
- final String quotedBoundary = Pattern.quote(boundary);
- final Pattern boundaryDelimiterPattern = Pattern.compile("--" + quotedBoundary + "--[\\s ]*");
- final Pattern boundaryPattern = Pattern.compile("--" + quotedBoundary + "[\\s ]*");
-
- for (Line currentLine : message) {
- if (boundaryDelimiterPattern.matcher(currentLine.toString()).matches()) {
- removeEndingCRLFFromList(currentPart);
- messageParts.add(currentPart);
- isEndReached = true;
- } else if (boundaryPattern.matcher(currentLine.toString()).matches()) {
- removeEndingCRLFFromList(currentPart);
- messageParts.add(currentPart);
- currentPart = new LinkedList<Line>();
- } else {
- currentPart.add(currentLine);
- }
-
- if (isEndReached) {
- break;
- }
- }
-
- final int lineNumer = (message.size() > 0) ? message.get(0).getLineNumber() : 0;
- // Remove preamble
- if (messageParts.size() > 0) {
- messageParts.remove(0);
- }
-
- if (!isEndReached) {
- throw new BatchDeserializerException("Missing close boundary delimiter",
- BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER,
- "" + lineNumer);
- }
-
- return messageParts;
- }
-
- private static void removeEndingCRLFFromList(final List<Line> list) {
- if (list.size() > 0) {
- Line lastLine = list.remove(list.size() - 1);
- list.add(removeEndingCRLF(lastLine));
- }
- }
-
- public static Line removeEndingCRLF(final Line line) {
- Pattern pattern = PATTERN_LAST_CRLF;
- Matcher matcher = pattern.matcher(line.toString());
-
- if (matcher.matches()) {
- return new Line(matcher.group(1), line.getLineNumber());
- } else {
- return line;
- }
- }
-
- public static Header consumeHeaders(final 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();
- Line currentLine;
- boolean isHeader = true;
-
- while (iter.hasNext() && isHeader) {
- currentLine = iter.next();
- final Matcher headerMatcher = PATTERN_HEADER_LINE.matcher(currentLine.toString());
-
- if (headerMatcher.matches() && headerMatcher.groupCount() == 2) {
- iter.remove();
-
- String headerName = headerMatcher.group(1).trim();
- String headerValue = headerMatcher.group(2).trim();
-
- headers.addHeader(headerName, Header.splitValuesByComma(headerValue), currentLine.getLineNumber());
- } else {
- isHeader = false;
- }
- }
-
- return headers;
- }
-
- 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 BatchDeserializerException("Missing blank line",
- BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE, "[None]", ""
- + lineNumber);
- }
- }
- }
-
- public static InputStream convertLineListToInputStream(final List<Line> messageList) {
- final String message = lineListToString(messageList);
-
- return new ByteArrayInputStream(message.getBytes());
- }
-
- private static String lineListToString(final List<Line> messageList) {
- final StringBuilder builder = new StringBuilder();
-
- for (Line currentLine : messageList) {
- builder.append(currentLine.toString());
- }
-
- 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(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/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchPart.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchPart.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchPart.java
deleted file mode 100644
index 9ee642d..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchPart.java
+++ /dev/null
@@ -1,25 +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;
-
-public interface BatchPart {
- public Header getHeaders();
-
- public boolean isStrict();
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index efc9f32..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchQueryOperation.java
+++ /dev/null
@@ -1,82 +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.exception.BatchDeserializerException;
-
-public class BatchQueryOperation implements BatchPart {
-
- protected final boolean isStrict;
- protected Line httpStatusLine;
- protected Header headers;
- protected List<Line> body;
- protected int bodySize;
- protected List<Line> message;
-
- public BatchQueryOperation(final List<Line> message, final boolean isStrict) {
- this.isStrict = isStrict;
- this.message = message;
- }
-
- public BatchQueryOperation parse() throws BatchDeserializerException {
- httpStatusLine = consumeHttpStatusLine(message);
- headers = BatchParserCommon.consumeHeaders(message);
- BatchParserCommon.consumeBlankLine(message, isStrict);
- body = message;
-
- return this;
- }
-
- 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);
-
- return method;
- } else {
- final int line = (message.size() > 0) ? message.get(0).getLineNumber() : 0;
- throw new BatchDeserializerException("Missing http request line",
- BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE, "" + line);
- }
- }
-
- public Line getHttpStatusLine() {
- return httpStatusLine;
- }
-
- public List<Line> getBody() {
- return body;
- }
-
- public int getBodySize() {
- return bodySize;
- }
-
- @Override
- public Header getHeaders() {
- return headers;
- }
-
- @Override
- public boolean isStrict() {
- return isStrict;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index 6da8de8..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchRequestTransformator.java
+++ /dev/null
@@ -1,184 +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.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.LinkedList;
-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.exception.BatchDeserializerException;
-import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
-import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
-
-public class BatchRequestTransformator {
- private final String baseUri;
- private final String rawServiceResolutionUri;
-
- public BatchRequestTransformator(final String baseUri, final String serviceResolutionUri) {
- this.baseUri = baseUri;
- rawServiceResolutionUri = serviceResolutionUri;
- }
-
- public List<BatchRequestPart> transform(final BatchBodyPart bodyPart) throws BatchDeserializerException {
- final List<ODataRequest> requests = new LinkedList<ODataRequest>();
- final List<BatchRequestPart> resultList = new ArrayList<BatchRequestPart>();
-
- validateBodyPartHeader(bodyPart);
-
- for (BatchQueryOperation queryOperation : bodyPart.getRequests()) {
- requests.add(processQueryOperation(bodyPart, baseUri, queryOperation));
- }
-
- resultList.add(new BatchRequestPart(bodyPart.isChangeSet(), requests));
- return resultList;
- }
-
- 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);
- validateHeader(queryOperation, true);
-
- return createRequest(encapsulatedQueryOperation, baseUri, bodyPart.isChangeSet());
- } else {
- return createRequest(queryOperation, baseUri, bodyPart.isChangeSet());
- }
- }
-
- 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 BatchDeserializerException("Missing content id", MessageKeys.MISSING_CONTENT_ID, 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);
-
- if (contentTypeHeader != null) {
- if (contentTypeHeader.getValues().size() == 1) {
- return contentTypeHeader;
- } else {
- throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, contentTypeHeader
- .getLineNumber());
- }
- }
-
- return null;
- }
-
- private ODataRequest createRequest(final BatchQueryOperation operation, final String baseUri,
- final boolean isChangeSet)
- throws BatchDeserializerException {
- final HttpRequestStatusLine statusLine =
- new HttpRequestStatusLine(operation.getHttpStatusLine(), baseUri, rawServiceResolutionUri);
- statusLine.validateHttpMethod(isChangeSet);
-
- validateBody(statusLine, operation);
- InputStream bodyStrean = getBodyStream(operation, statusLine);
-
- validateForbiddenHeader(operation);
-
- final ODataRequest request = new ODataRequest();
- request.setBody(bodyStrean);
- request.setMethod(statusLine.getMethod());
- request.setRawBaseUri(statusLine.getRawBaseUri());
- request.setRawODataPath(statusLine.getRawODataPath());
- request.setRawQueryPath(statusLine.getRawQueryPath());
- request.setRawRequestUri(statusLine.getRawRequestUri());
- request.setRawServiceResolutionUri(statusLine.getRawServiceResolutionUri());
-
- for (final HeaderField field : operation.getHeaders()) {
- request.addHeader(field.getFieldName(), field.getValues());
- }
-
- return request;
- }
-
- 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 BatchDeserializerException("Forbidden header", MessageKeys.FORBIDDEN_HEADER, header.getLineNumber());
- }
- }
-
- private InputStream getBodyStream(final BatchQueryOperation operation, final HttpRequestStatusLine statusLine)
- throws BatchDeserializerException {
- if (statusLine.getMethod().equals(HttpMethod.GET)) {
- return new ByteArrayInputStream(new byte[0]);
- } else {
- int contentLength = BatchTransformatorCommon.getContentLength(operation.getHeaders());
-
- if (contentLength == -1) {
- return BatchParserCommon.convertLineListToInputStream(operation.getBody());
- } else {
- return BatchParserCommon.convertLineListToInputStream(operation.getBody(), contentLength);
- }
- }
- }
-
- 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());
- }
- }
-
- private boolean isUnvalidGetRequestBody(final BatchQueryOperation operation) {
- return (operation.getBody().size() > 1)
- || (operation.getBody().size() == 1 && !"".equals(operation.getBody().get(0).toString().trim()));
- }
-
- 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);
- if (isChangeSet) {
- BatchTransformatorCommon.validateContentTransferEncoding(headers);
- }
- }
-
- private void validateBodyPartHeader(final BatchBodyPart bodyPart) throws BatchDeserializerException {
- final Header header = bodyPart.getHeaders();
-
- if (bodyPart.isChangeSet()) {
- BatchTransformatorCommon.validateContentType(header, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY);
- } else {
- BatchTransformatorCommon.validateContentTransferEncoding(header);
- BatchTransformatorCommon.validateContentType(header, BatchParserCommon.PATTERN_CONTENT_TYPE_APPLICATION_HTTP);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index 2a55bed..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java
+++ /dev/null
@@ -1,93 +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 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.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 BatchDeserializerException {
- 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 (!headers.isHeaderMatching(HttpHeader.CONTENT_TYPE, pattern)) {
-
- throw new BatchDeserializerException("Invalid content type", MessageKeys.INVALID_CONTENT_TYPE,
- HttpContentType.MULTIPART_MIXED + " or " + HttpContentType.APPLICATION_HTTP);
- }
- }
-
- public static void validateContentTransferEncoding(final Header headers) throws BatchDeserializerException {
- final HeaderField contentTransferField = headers.getHeaderField(BatchParserCommon.HTTP_CONTENT_TRANSFER_ENCODING);
-
- if (contentTransferField != null) {
- final List<String> contentTransferValues = contentTransferField.getValues();
- if (contentTransferValues.size() == 1) {
- String encoding = contentTransferValues.get(0);
-
- if (!BatchParserCommon.BINARY_ENCODING.equalsIgnoreCase(encoding)) {
- throw new BatchDeserializerException("Invalid content transfer encoding",
- MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING,
- headers.getLineNumber());
- }
- } else {
- throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, headers.getLineNumber());
- }
- } else {
- throw new BatchDeserializerException("Missing mandatory content transfer encoding",
- MessageKeys.MISSING_CONTENT_TRANSFER_ENCODING,
- headers.getLineNumber());
- }
- }
-
- public static int getContentLength(final Header headers) throws BatchDeserializerException {
- final HeaderField contentLengthField = headers.getHeaderField(HttpHeader.CONTENT_LENGTH);
-
- if (contentLengthField != null && contentLengthField.getValues().size() == 1) {
- final List<String> contentLengthValues = contentLengthField.getValues();
-
- try {
- int contentLength = Integer.parseInt(contentLengthValues.get(0));
-
- if (contentLength < 0) {
- throw new BatchDeserializerException("Invalid content length", MessageKeys.INVALID_CONTENT_LENGTH,
- contentLengthField
- .getLineNumber());
- }
-
- return contentLength;
- } catch (NumberFormatException e) {
- throw new BatchDeserializerException("Invalid header", MessageKeys.INVALID_HEADER, contentLengthField
- .getLineNumber());
- }
- }
-
- return -1;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index 2268a1d..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BufferedReaderIncludingLineEndings.java
+++ /dev/null
@@ -1,233 +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.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
-
-public class BufferedReaderIncludingLineEndings extends Reader {
- private static final char CR = '\r';
- private static final char LF = '\n';
- private static final int EOF = -1;
- private static final int BUFFER_SIZE = 8192;
- private Reader reader;
- private char[] buffer;
- private int offset = 0;
- private int limit = 0;
-
- public BufferedReaderIncludingLineEndings(final Reader reader) {
- this(reader, BUFFER_SIZE);
- }
-
- public BufferedReaderIncludingLineEndings(final Reader reader, final int bufferSize) {
- if (bufferSize <= 0) {
- throw new IllegalArgumentException("Buffer size must be greater than zero.");
- }
-
- this.reader = reader;
- buffer = new char[bufferSize];
- }
-
- @Override
- public int read(final char[] charBuffer, final int bufferOffset, final int length) throws IOException {
- if ((bufferOffset + length) > charBuffer.length) {
- throw new IndexOutOfBoundsException("Buffer is too small");
- }
-
- if (length < 0 || bufferOffset < 0) {
- throw new IndexOutOfBoundsException("Offset and length must be grater than zero");
- }
-
- // Check if buffer is filled. Return if EOF is reached
- // Is buffer refill required
- if (limit == offset || isEOF()) {
- fillBuffer();
-
- if (isEOF()) {
- return EOF;
- }
- }
-
- int bytesRead = 0;
- int bytesToRead = length;
- int currentOutputOffset = bufferOffset;
-
- while (bytesToRead != 0) {
- // Is buffer refill required?
- if (limit == offset) {
- fillBuffer();
-
- if (isEOF()) {
- bytesToRead = 0;
- }
- }
-
- if (bytesToRead > 0) {
- int readByte = Math.min(limit - offset, bytesToRead);
- bytesRead += readByte;
- bytesToRead -= readByte;
-
- for (int i = 0; i < readByte; i++) {
- charBuffer[currentOutputOffset++] = buffer[offset++];
- }
- }
- }
-
- 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;
- int counter = 1;
-
- while ((currentLine = readLine()) != null) {
- result.add(new Line(currentLine, counter++));
- }
-
- return result;
- }
-
- public String readLine() throws IOException {
- if (limit == EOF) {
- return null;
- }
-
- final StringBuilder stringBuffer = new StringBuilder();
- boolean foundLineEnd = false; // EOF will be considered as line ending
-
- while (!foundLineEnd) {
- // Is buffer refill required?
- if (limit == offset) {
- if (fillBuffer() == EOF) {
- foundLineEnd = true;
- }
- }
-
- if (!foundLineEnd) {
- char currentChar = buffer[offset++];
- stringBuffer.append(currentChar);
-
- if (currentChar == LF) {
- foundLineEnd = true;
- } else if (currentChar == CR) {
- foundLineEnd = true;
-
- // Check next char. Consume \n if available
- // Is buffer refill required?
- if (limit == offset) {
- fillBuffer();
- }
-
- // Check if there is at least one character
- if (limit != EOF && buffer[offset] == LF) {
- stringBuffer.append(LF);
- offset++;
- }
- }
- }
- }
-
- return (stringBuffer.length() == 0) ? null : stringBuffer.toString();
- }
-
- @Override
- public void close() throws IOException {
- reader.close();
- }
-
- @Override
- public boolean ready() throws IOException {
- // Not EOF and buffer refill is not required
- return !isEOF() && !(limit == offset);
- }
-
- @Override
- public void reset() throws IOException {
- throw new IOException("Reset is not supported");
- }
-
- @Override
- public void mark(final int readAheadLimit) throws IOException {
- throw new IOException("Mark is not supported");
- }
-
- @Override
- public boolean markSupported() {
- return false;
- }
-
- @Override
- public long skip(final long n) throws IOException {
- if (n == 0) {
- return 0;
- } else if (n < 0) {
- throw new IllegalArgumentException("skip value is negative");
- } else {
- long charactersToSkip = n;
- long charactersSkiped = 0;
-
- while (charactersToSkip != 0) {
- // Is buffer refill required?
- if (limit == offset) {
- fillBuffer();
-
- if (isEOF()) {
- charactersToSkip = 0;
- }
- }
-
- // Check if more characters are available
- if (!isEOF()) {
- int skipChars = (int) Math.min(limit - offset, charactersToSkip);
-
- charactersSkiped += skipChars;
- charactersToSkip -= skipChars;
- offset += skipChars;
- }
- }
-
- return charactersSkiped;
- }
- }
-
- private boolean isEOF() {
- return limit == EOF;
- }
-
- private int fillBuffer() throws IOException {
- limit = reader.read(buffer, 0, buffer.length);
- offset = 0;
-
- return limit;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index a9b05b1..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Header.java
+++ /dev/null
@@ -1,181 +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.ArrayList;
-import java.util.HashMap;
-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>();
- private int lineNumber;
-
- public Header(final int lineNumer) {
- lineNumber = lineNumer;
- }
-
- public void addHeader(final String name, final String value, final int lineNumber) {
- final HeaderField headerField = getHeaderFieldOrDefault(name, lineNumber);
- final List<String> headerValues = headerField.getValues();
-
- if (!headerValues.contains(value)) {
- headerValues.add(value);
- }
- }
-
- public void addHeader(final String name, final List<String> values, final int lineNumber) {
- final HeaderField headerField = getHeaderFieldOrDefault(name, lineNumber);
- final List<String> headerValues = headerField.getValues();
-
- for (final String value : values) {
- if (!headerValues.contains(value)) {
- headerValues.add(value);
- }
- }
- }
-
- public void replaceHeaderField(final HeaderField headerField) {
- headers.put(headerField.getFieldName().toLowerCase(Locale.ENGLISH), headerField);
- }
-
- public boolean exists(final String name) {
- final HeaderField field = headers.get(name.toLowerCase(Locale.ENGLISH));
-
- 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));
- }
-
- public String getHeader(final String name) {
- final HeaderField headerField = getHeaderField(name);
-
- return (headerField == null) ? null : headerField.getValue();
- }
-
- public String getHeaderNotNull(final String name) {
- final HeaderField headerField = getHeaderField(name);
-
- return (headerField == null) ? "" : headerField.getValueNotNull();
- }
-
- public List<String> getHeaders(final String name) {
- final HeaderField headerField = getHeaderField(name);
-
- return (headerField == null) ? new ArrayList<String>() : headerField.getValues();
- }
-
- public HeaderField getHeaderField(final String name) {
- return headers.get(name.toLowerCase(Locale.ENGLISH));
- }
-
- public int getLineNumber() {
- return lineNumber;
- }
-
- public Map<String, String> toSingleMap() {
- final Map<String, String> singleMap = new HashMap<String, String>();
-
- for (final String key : headers.keySet()) {
- HeaderField field = headers.get(key);
- singleMap.put(field.getFieldName(), getHeader(key));
- }
-
- return singleMap;
- }
-
- public Map<String, List<String>> toMultiMap() {
- final Map<String, List<String>> singleMap = new HashMap<String, List<String>>();
-
- for (final String key : headers.keySet()) {
- HeaderField field = headers.get(key);
- singleMap.put(field.getFieldName(), field.getValues());
- }
-
- return singleMap;
- }
-
- private HeaderField getHeaderFieldOrDefault(final String name, final int lineNumber) {
- HeaderField headerField = headers.get(name.toLowerCase(Locale.ENGLISH));
-
- if (headerField == null) {
- headerField = new HeaderField(name, lineNumber);
- headers.put(name.toLowerCase(Locale.ENGLISH), headerField);
- }
-
- return headerField;
- }
-
- @Override
- public Header clone() {
- final Header newInstance = new Header(lineNumber);
-
- for (final String key : headers.keySet()) {
- newInstance.headers.put(key, headers.get(key).clone());
- }
-
- return newInstance;
- }
-
- @Override
- public Iterator<HeaderField> iterator() {
- return new Iterator<HeaderField>() {
- Iterator<String> keyIterator = headers.keySet().iterator();
-
- @Override
- public boolean hasNext() {
- return keyIterator.hasNext();
- }
-
- @Override
- public HeaderField next() {
- return headers.get(keyIterator.next());
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
- }
-
- public static List<String> splitValuesByComma(final String headerValue) {
- final List<String> singleValues = new ArrayList<String>();
-
- String[] parts = headerValue.split(",");
- for (final String value : parts) {
- singleValues.add(value.trim());
- }
-
- return singleValues;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HeaderField.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HeaderField.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HeaderField.java
deleted file mode 100644
index 870f276..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HeaderField.java
+++ /dev/null
@@ -1,121 +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.ArrayList;
-import java.util.List;
-
-public class HeaderField implements Cloneable {
- private final String fieldName;
- private final List<String> values;
- private final int lineNumber;
-
- public HeaderField(final String fieldName, final int lineNumber) {
- this(fieldName, new ArrayList<String>(), lineNumber);
- }
-
- public HeaderField(final String fieldName, final List<String> values, final int lineNumber) {
- this.fieldName = fieldName;
- this.values = values;
- this.lineNumber = lineNumber;
- }
-
- public String getFieldName() {
- return fieldName;
- }
-
- public List<String> getValues() {
- return values;
- }
-
- public String getValue() {
- final StringBuilder result = new StringBuilder();
-
- for (final String value : values) {
- result.append(value);
- result.append(", ");
- }
-
- if (result.length() > 0) {
- result.delete(result.length() - 2, result.length());
- }
-
- return result.toString();
- }
-
- public String getValueNotNull() {
- final String value = getValue();
-
- return (value == null) ? "" : value;
- }
-
- @Override
- public HeaderField clone() {
- List<String> newValues = new ArrayList<String>();
- newValues.addAll(values);
-
- return new HeaderField(fieldName, newValues, lineNumber);
- }
-
- public int getLineNumber() {
- return lineNumber;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((fieldName == null) ? 0 : fieldName.hashCode());
- result = prime * result + lineNumber;
- result = prime * result + ((values == null) ? 0 : values.hashCode());
- 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;
- }
- HeaderField other = (HeaderField) obj;
- if (fieldName == null) {
- if (other.fieldName != null) {
- return false;
- }
- } else if (!fieldName.equals(other.fieldName)) {
- return false;
- }
- if (lineNumber != other.lineNumber) {
- return false;
- }
- if (values == null) {
- if (other.values != null) {
- return false;
- }
- } else if (!values.equals(other.values)) {
- return false;
- }
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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
deleted file mode 100644
index 74b67cb..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java
+++ /dev/null
@@ -1,194 +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.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-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;
-
-public class HttpRequestStatusLine {
- private static final Pattern PATTERN_RELATIVE_URI = Pattern.compile("([^/][^?]*)(?:\\?(.*))?");
-
- private static final Set<String> HTTP_BATCH_METHODS = new HashSet<String>(Arrays.asList(new String[] { "GET" }));
- private static final Set<String> HTTP_CHANGE_SET_METHODS = new HashSet<String>(Arrays.asList(new String[] { "POST",
- "PUT", "DELETE", "PATCH" }));
- private static final String HTTP_VERSION = "HTTP/1.1";
-
- final private Line statusLine;
- final String requestBaseUri;
-
- private HttpMethod method;
- private String httpVersion;
- private String rawServiceResolutionUri;
- private String rawQueryPath;
- private String rawODataPath;
- private String rawBaseUri;
- private String rawRequestUri;
-
- public HttpRequestStatusLine(final Line httpStatusLine, final String baseUri, final String serviceResolutionUri)
- throws BatchDeserializerException {
- statusLine = httpStatusLine;
- requestBaseUri = baseUri;
- rawServiceResolutionUri = serviceResolutionUri;
-
- parse();
- }
-
- private void parse() throws BatchDeserializerException {
- final String[] parts = statusLine.toString().split(" ");
-
- if (parts.length == 3) {
- method = parseMethod(parts[0]);
- // uri = new ODataURI(parts[1], requestBaseUri, statusLine.getLineNumber(), header.getHeaders(HttpHeader.HOST));
- parseUri(parts[1], requestBaseUri);
- httpVersion = parseHttpVersion(parts[2]);
- } else {
- throw new BatchDeserializerException("Invalid status line", MessageKeys.INVALID_STATUS_LINE, statusLine
- .getLineNumber());
- }
- }
-
- private void parseUri(String rawUri, String baseUri) throws BatchDeserializerException {
- try {
- final URI uri = new URI(rawUri);
-
- if (uri.isAbsolute()) {
- parseAbsoluteUri(rawUri, baseUri);
- } else {
- parseRelativeUri(rawUri);
- }
- } catch (URISyntaxException e) {
- throw new BatchDeserializerException("Malformed uri", MessageKeys.INVALID_URI, statusLine.getLineNumber());
- }
- }
-
- private void parseAbsoluteUri(String rawUri, String baseUri) throws BatchDeserializerException {
- if (rawUri.startsWith(baseUri)) {
- 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());
- }
- }
-
- private String removeLeadingSlash(String value) {
- return (value.length() > 0 && value.charAt(0) == '/') ? value.substring(1) : value;
- }
-
- private void parseRelativeUri(String rawUri) throws BatchDeserializerException {
- final Matcher relativeUriMatcher = PATTERN_RELATIVE_URI.matcher(rawUri);
-
- if (relativeUriMatcher.matches()) {
- buildUri(relativeUriMatcher.group(1), relativeUriMatcher.group(2));
- } else {
- throw new BatchDeserializerException("Malformed uri", MessageKeys.INVALID_URI, statusLine.getLineNumber());
- }
- }
-
- private void buildUri(final String oDataPath, final String queryOptions) throws BatchDeserializerException {
- rawBaseUri = requestBaseUri;
- rawODataPath = "/" + oDataPath;
- rawRequestUri = requestBaseUri + rawODataPath;
-
- if (queryOptions != null) {
- rawRequestUri += "?" + queryOptions;
- rawQueryPath = queryOptions;
- } else {
- rawQueryPath = "";
- }
- }
-
- private HttpMethod parseMethod(final String method) throws BatchDeserializerException {
- try {
- return HttpMethod.valueOf(method.trim());
- } catch (IllegalArgumentException e) {
- throw new BatchDeserializerException("Illegal http method", MessageKeys.INVALID_METHOD, 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());
- } else {
- return HTTP_VERSION;
- }
- }
-
- public void validateHttpMethod(final boolean isChangeSet) throws BatchDeserializerException {
- Set<String> validMethods = (isChangeSet) ? HTTP_CHANGE_SET_METHODS : HTTP_BATCH_METHODS;
-
- if (!validMethods.contains(getMethod().toString())) {
- if (isChangeSet) {
- throw new BatchDeserializerException("Invalid change set method", MessageKeys.INVALID_CHANGESET_METHOD,
- statusLine.getLineNumber());
- } else {
- throw new BatchDeserializerException("Invalid query operation method",
- MessageKeys.INVALID_QUERY_OPERATION_METHOD,
- statusLine.getLineNumber());
- }
- }
- }
-
- public HttpMethod getMethod() {
- return method;
- }
-
- public String getHttpVersion() {
- return httpVersion;
- }
-
- public int getLineNumber() {
- return statusLine.getLineNumber();
- }
-
- public String getRequestBaseUri() {
- return requestBaseUri;
- }
-
- public String getRawServiceResolutionUri() {
- return rawServiceResolutionUri;
- }
-
- public String getRawQueryPath() {
- return rawQueryPath;
- }
-
- public String getRawODataPath() {
- return rawODataPath;
- }
-
- public String getRawBaseUri() {
- return rawBaseUri;
- }
-
- public String getRawRequestUri() {
- return rawRequestUri;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Line.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Line.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Line.java
deleted file mode 100644
index 6485a49..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Line.java
+++ /dev/null
@@ -1,72 +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;
-
-public 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;
- }
-}
\ No newline at end of file