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:03 UTC

[1/3] olingo-odata4 git commit: [OLINGO-472] BatchDeserializer refactoring

Repository: olingo-odata4
Updated Branches:
  refs/heads/master 402e847a8 -> babc3a615


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BufferedReaderIncludingLineEndingsTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BufferedReaderIncludingLineEndingsTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BufferedReaderIncludingLineEndingsTest.java
index d622600..83b76ef 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BufferedReaderIncludingLineEndingsTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BufferedReaderIncludingLineEndingsTest.java
@@ -21,13 +21,11 @@ package org.apache.olingo.server.core.deserializer;
 import static org.junit.Assert.*;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.util.List;
 
 import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings;
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings.Line;
+import org.apache.olingo.server.core.deserializer.batch.Line;
 import org.junit.Test;
 
 public class BufferedReaderIncludingLineEndingsTest {
@@ -50,7 +48,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   private static final String TEXT_EMPTY = "";
 
   @Test
-  public void testSimpleText() throws IOException {
+  public void testSimpleText() throws Exception {
     final String TEXT = "Test";
     BufferedReaderIncludingLineEndings reader = create(TEXT);
 
@@ -61,7 +59,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testNoText() throws IOException {
+  public void testNoText() throws Exception {
     final String TEXT = "";
     BufferedReaderIncludingLineEndings reader = create(TEXT);
 
@@ -71,7 +69,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testNoBytes() throws IOException {
+  public void testNoBytes() throws Exception {
     BufferedReaderIncludingLineEndings reader =
         new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(new byte[0])));
 
@@ -81,7 +79,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testCRLF() throws IOException {
+  public void testCRLF() throws Exception {
     final String TEXT = "Test\r\n" +
         "Test2";
 
@@ -95,7 +93,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testLF() throws IOException {
+  public void testLF() throws Exception {
     final String TEXT = "Test\n" +
         "Test2";
 
@@ -109,7 +107,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testCR() throws IOException {
+  public void testCR() throws Exception {
     final String TEXT = "Test\r" +
         "Test2";
 
@@ -123,7 +121,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testCombined() throws IOException {
+  public void testCombined() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_COMBINED);
 
     assertEquals("Test\r", reader.readLine());
@@ -143,7 +141,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testCombinedBufferSizeTwo() throws IOException {
+  public void testCombinedBufferSizeTwo() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_COMBINED, 2);
 
     assertEquals("Test\r", reader.readLine());
@@ -163,7 +161,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testCombinedBufferSizeOne() throws IOException {
+  public void testCombinedBufferSizeOne() throws Exception {
     final String TEXT = "Test\r" +
         "Test2\r\n" +
         "Test3\n" +
@@ -196,7 +194,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testDoubleLF() throws IOException {
+  public void testDoubleLF() throws Exception {
     final String TEXT = "Test\r" +
         "\r";
 
@@ -208,7 +206,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testSkipSimple() throws IOException {
+  public void testSkipSimple() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL);
 
     assertEquals(5, reader.skip(5)); // Test\r
@@ -219,7 +217,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testSkipBufferOne() throws IOException {
+  public void testSkipBufferOne() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL, 1);
 
     assertEquals(5, reader.skip(5)); // Test\r
@@ -230,7 +228,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testReadThanSkip() throws IOException {
+  public void testReadThanSkip() throws Exception {
     final String TEXT = "Test\r" +
         "\r" +
         "123";
@@ -246,7 +244,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testReadMoreBufferCapacityThanCharacterAvailable() throws IOException {
+  public void testReadMoreBufferCapacityThanCharacterAvailable() throws Exception {
     final String TEXT = "Foo";
     char[] buffer = new char[20];
 
@@ -262,7 +260,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testSkipZero() throws IOException {
+  public void testSkipZero() throws Exception {
     final String TEXT = "Test\r" +
         "123\r\n";
 
@@ -277,7 +275,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testSkipToMuch() throws IOException {
+  public void testSkipToMuch() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL);
 
     assertEquals(8, reader.skip(10)); // Test\r
@@ -286,7 +284,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testReadBufferOne() throws IOException {
+  public void testReadBufferOne() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL, 1);
 
     assertEquals('T', reader.read());
@@ -302,7 +300,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testReadZeroBytes() throws IOException {
+  public void testReadZeroBytes() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL, 1);
 
     char[] buffer = new char[3];
@@ -316,7 +314,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testRead() throws IOException {
+  public void testRead() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_SMALL);
 
     assertEquals('T', reader.read());
@@ -332,7 +330,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test(expected = IndexOutOfBoundsException.class)
-  public void testFailReadBufferAndOffsetBiggerThanBuffer() throws IOException {
+  public void testFailReadBufferAndOffsetBiggerThanBuffer() throws Exception {
     BufferedReaderIncludingLineEndings reader = create("");
 
     final char[] buffer = new char[3];
@@ -340,7 +338,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test(expected = IndexOutOfBoundsException.class)
-  public void testFailLengthNegative() throws IOException {
+  public void testFailLengthNegative() throws Exception {
     final char[] buffer = new char[3];
     BufferedReaderIncludingLineEndings reader = create("123");
 
@@ -349,7 +347,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test(expected = IndexOutOfBoundsException.class)
-  public void testFailOffsetNegative() throws IOException {
+  public void testFailOffsetNegative() throws Exception {
     final char[] buffer = new char[3];
     BufferedReaderIncludingLineEndings reader = create("123");
 
@@ -358,7 +356,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testReadAndReadLine() throws IOException {
+  public void testReadAndReadLine() throws Exception {
     final String TEXT = "Test\r" +
         "bar\n" +
         "123\r\n" +
@@ -392,54 +390,54 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
   
   @Test(expected = IllegalArgumentException.class)
-  public void testSkipNegative() throws IOException {
+  public void testSkipNegative() throws Exception {
     BufferedReaderIncludingLineEndings reader = create("123");
     reader.skip(-1);
   }
 
   @Test(expected = IllegalArgumentException.class)
-  public void testFailBufferSizeZero() throws IOException {
+  public void testFailBufferSizeZero() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_EMPTY, 0);
     reader.close();
   }
 
   @Test(expected = NullPointerException.class)
-  public void testInputStreamIsNull() throws IOException {
+  public void testInputStreamIsNull() throws Exception {
     // Same behaviour like BufferedReader
     BufferedReaderIncludingLineEndings reader = new BufferedReaderIncludingLineEndings(null);
     reader.close();
   }
 
   @Test(expected = IllegalArgumentException.class)
-  public void testFailBufferSizeNegative() throws IOException {
+  public void testFailBufferSizeNegative() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_EMPTY, -1);
     reader.close();
   }
 
   @Test
-  public void testMarkSupoorted() throws IOException {
+  public void testMarkSupoorted() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_EMPTY);
 
     assertEquals(false, reader.markSupported());
     reader.close();
   }
 
-  @Test(expected = IOException.class)
-  public void testFailMark() throws IOException {
+  @Test(expected = Exception.class)
+  public void testFailMark() throws Exception {
     BufferedReaderIncludingLineEndings reader = create("123");
 
     reader.mark(1);
   }
 
-  @Test(expected = IOException.class)
-  public void testFailReset() throws IOException {
+  @Test(expected = Exception.class)
+  public void testFailReset() throws Exception {
     BufferedReaderIncludingLineEndings reader = create("123");
 
     reader.reset();
   }
 
   @Test
-  public void testReady() throws IOException {
+  public void testReady() throws Exception {
     BufferedReaderIncludingLineEndings reader = create("123\r123");
     assertEquals(false, reader.ready());
     assertEquals("123\r", reader.readLine());
@@ -451,7 +449,7 @@ public class BufferedReaderIncludingLineEndingsTest {
   }
 
   @Test
-  public void testToList() throws IOException {
+  public void testToList() throws Exception {
     BufferedReaderIncludingLineEndings reader = create(TEXT_COMBINED);
     List<Line> stringList = reader.toLineList();
 
@@ -470,13 +468,12 @@ public class BufferedReaderIncludingLineEndingsTest {
     reader.close();
   }
 
-  private BufferedReaderIncludingLineEndings create(final String inputString) throws UnsupportedEncodingException {
+  private BufferedReaderIncludingLineEndings create(final String inputString) throws Exception {
     return new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(inputString
         .getBytes("UTF-8"))));
   }
 
-  private BufferedReaderIncludingLineEndings create(final String inputString, int bufferSize)
-      throws UnsupportedEncodingException {
+  private BufferedReaderIncludingLineEndings create(final String inputString, int bufferSize) throws Exception {
     return new BufferedReaderIncludingLineEndings(new InputStreamReader(new ByteArrayInputStream(inputString
         .getBytes("UTF-8"))), bufferSize);
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/HeaderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/HeaderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/HeaderTest.java
index 369e21e..7947f55 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/HeaderTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/HeaderTest.java
@@ -113,14 +113,6 @@ public class HeaderTest {
     assertFalse(header.isHeaderMatching(HttpHeader.CONTENT_TYPE, BatchParserCommon.PATTERN_MULTIPART_BOUNDARY));
   }
 
-//  @Test
-//  public void testMatcherFail() {
-//    Header header = new Header(1);
-//    header.addHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + ";boundary=123", 1);
-//
-//    assertFalse(header.isHeaderMatching(HttpHeader.CONTENT_TYPE, BatchParserCommon.PATTERN_HEADER_LINE));
-//  }
-
   @Test
   public void testDuplicatedAddList() {
     Header header = new Header(1);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/StringUtil.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/StringUtil.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/StringUtil.java
index 8fcebd0..f9ec664 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/StringUtil.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/StringUtil.java
@@ -19,7 +19,6 @@
 package org.apache.olingo.server.core.deserializer;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
@@ -30,7 +29,7 @@ import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingL
 public class StringUtil {
   
   
-  public static String toString(final InputStream in) throws IOException {
+  public static String toString(final InputStream in) throws Exception {
     final StringBuilder builder = new StringBuilder();
     final BufferedReaderIncludingLineEndings reader = new BufferedReaderIncludingLineEndings(new InputStreamReader(in));
     String currentLine;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseSerializerTest.java
new file mode 100644
index 0000000..d889cac
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseSerializerTest.java
@@ -0,0 +1,175 @@
+/*
+ * 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.serializer;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
+import org.apache.olingo.server.core.deserializer.StringUtil;
+import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
+import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings;
+import org.apache.olingo.server.core.serializer.BatchResponseSerializer;
+import org.junit.Test;
+
+public class BatchResponseSerializerTest {
+  private static final String CRLF = "\r\n";
+  private static final String BOUNDARY = "batch_" + UUID.randomUUID().toString();
+
+  @Test
+  public void testBatchResponse() throws Exception {
+    final List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
+    ODataResponse response = new ODataResponse();
+    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+    response.setHeader(HttpHeader.CONTENT_TYPE, "application/json");
+    response.setContent(StringUtil.toInputStream("Walter Winter" + CRLF));
+
+    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
+    responses.add(response);
+    parts.add(new ODataResponsePart(responses, false));
+
+    ODataResponse changeSetResponse = new ODataResponse();
+    changeSetResponse.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
+    changeSetResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1");
+    responses = new ArrayList<ODataResponse>(1);
+    responses.add(changeSetResponse);
+    parts.add(new ODataResponsePart(responses, true));
+
+    BatchResponseSerializer serializer = new BatchResponseSerializer();
+    final InputStream content = serializer.serialize(parts, BOUNDARY);
+    assertNotNull(content);
+    final BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(content));
+    final List<String> body = reader.toList();
+    reader.close();
+    
+    int line = 0;
+    assertEquals(25, body.size());
+    assertTrue(body.get(line++).contains("--batch_"));
+    assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertEquals("HTTP/1.1 200 OK" + CRLF, body.get(line++));
+    assertEquals("Content-Type: application/json" + CRLF, body.get(line++));
+    assertEquals("Content-Length: 15" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertEquals("Walter Winter" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertTrue(body.get(line++).contains("--batch_"));
+    assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, body.get(line++));
+    assertTrue(body.get(line++).contains("--changeset_"));
+    assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
+    assertEquals("Content-Id: 1" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++));
+    assertEquals("Content-Length: 0" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertTrue(body.get(line++).contains("--changeset_"));
+    assertEquals(CRLF, body.get(line++));
+    assertTrue(body.get(line++).contains("--batch_"));
+  }
+
+  @Test
+  public void testResponse() throws Exception {
+    List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
+    ODataResponse response = new ODataResponse();
+    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
+    response.setHeader(HttpHeader.CONTENT_TYPE, "application/json");
+    response.setContent(StringUtil.toInputStream("Walter Winter"));
+
+    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
+    responses.add(response);
+    parts.add(new ODataResponsePart(responses, false));
+
+    final BatchResponseSerializer serializer = new BatchResponseSerializer();
+    final InputStream content = serializer.serialize(parts, BOUNDARY);
+    
+    assertNotNull(content);
+    final BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(content));
+    final List<String> body = reader.toList();
+    reader.close();
+    
+    int line = 0;
+    assertEquals(10, body.size());
+    assertTrue(body.get(line++).contains("--batch_"));
+    assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertEquals("HTTP/1.1 200 OK" + CRLF, body.get(line++));
+    assertEquals("Content-Type: application/json" + CRLF, body.get(line++));
+    assertEquals("Content-Length: 13" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertEquals("Walter Winter" + CRLF, body.get(line++));
+    assertTrue(body.get(line++).contains("--batch_"));
+  }
+
+  @Test
+  public void testChangeSetResponse() throws Exception {
+    List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
+    ODataResponse response = new ODataResponse();
+    response.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1");
+    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
+
+    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
+    responses.add(response);
+    parts.add(new ODataResponsePart(responses, true));
+
+    BatchResponseSerializer serializer = new BatchResponseSerializer();
+    final InputStream content = serializer.serialize(parts, BOUNDARY);
+    
+    assertNotNull(content);
+
+    final BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(content));
+    final List<String> body = reader.toList();
+    reader.close();
+    
+    int line = 0;
+    assertEquals(15, body.size());
+    assertTrue(body.get(line++).contains("--batch_"));
+    assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_"));
+    assertEquals(CRLF, body.get(line++));
+    assertTrue(body.get(line++).contains("--changeset_"));
+    assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
+    assertEquals("Content-Id: 1" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++));
+    assertEquals("Content-Length: 0" + CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertEquals(CRLF, body.get(line++));
+    assertTrue(body.get(line++).contains("--changeset_"));
+    assertEquals(CRLF, body.get(line++));
+    assertTrue(body.get(line++).contains("--batch_"));
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseWriterTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseWriterTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseWriterTest.java
deleted file mode 100644
index d44f3c3..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseWriterTest.java
+++ /dev/null
@@ -1,180 +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.serializer;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.commons.api.http.HttpHeader;
-import org.apache.olingo.commons.api.http.HttpStatusCode;
-import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
-import org.apache.olingo.server.core.deserializer.StringUtil;
-import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings;
-import org.apache.olingo.server.core.serializer.BatchResponseSerializer;
-import org.junit.Test;
-
-public class BatchResponseWriterTest {
-  private static final String CRLF = "\r\n";
-
-  @Test
-  public void testBatchResponse() throws IOException, BatchException {
-    final List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
-    ODataResponse response = new ODataResponse();
-    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
-    response.setHeader(HttpHeader.CONTENT_TYPE, "application/json");
-    response.setContent(StringUtil.toInputStream("Walter Winter" + CRLF));
-
-    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
-    responses.add(response);
-    parts.add(new ODataResponsePart(responses, false));
-
-    ODataResponse changeSetResponse = new ODataResponse();
-    changeSetResponse.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
-    changeSetResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1");
-    responses = new ArrayList<ODataResponse>(1);
-    responses.add(changeSetResponse);
-    parts.add(new ODataResponsePart(responses, true));
-
-    BatchResponseSerializer writer = new BatchResponseSerializer();
-    ODataResponse batchResponse = new ODataResponse();
-    writer.toODataResponse(parts, batchResponse);
-
-    assertEquals(202, batchResponse.getStatusCode());
-    assertNotNull(batchResponse.getContent());
-    final BufferedReaderIncludingLineEndings reader =
-        new BufferedReaderIncludingLineEndings(new InputStreamReader(batchResponse.getContent()));
-    final List<String> body = reader.toList();
-    reader.close();
-    
-    int line = 0;
-    assertEquals(25, body.size());
-    assertTrue(body.get(line++).contains("--batch_"));
-    assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
-    assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertEquals("HTTP/1.1 200 OK" + CRLF, body.get(line++));
-    assertEquals("Content-Type: application/json" + CRLF, body.get(line++));
-    assertEquals("Content-Length: 15" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertEquals("Walter Winter" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertTrue(body.get(line++).contains("--batch_"));
-    assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_"));
-    assertEquals(CRLF, body.get(line++));
-    assertTrue(body.get(line++).contains("--changeset_"));
-    assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
-    assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
-    assertEquals("Content-Id: 1" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++));
-    assertEquals("Content-Length: 0" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertTrue(body.get(line++).contains("--changeset_"));
-    assertEquals(CRLF, body.get(line++));
-    assertTrue(body.get(line++).contains("--batch_"));
-  }
-
-  @Test
-  public void testResponse() throws IOException, BatchException {
-    List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
-    ODataResponse response = new ODataResponse();
-    response.setStatusCode(HttpStatusCode.OK.getStatusCode());
-    response.setHeader(HttpHeader.CONTENT_TYPE, "application/json");
-    response.setContent(StringUtil.toInputStream("Walter Winter"));
-
-    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
-    responses.add(response);
-    parts.add(new ODataResponsePart(responses, false));
-
-    ODataResponse batchResponse = new ODataResponse();
-    new BatchResponseSerializer().toODataResponse(parts, batchResponse);
-
-    assertEquals(202, batchResponse.getStatusCode());
-    assertNotNull(batchResponse.getContent());
-    final BufferedReaderIncludingLineEndings reader =
-        new BufferedReaderIncludingLineEndings(new InputStreamReader(batchResponse.getContent()));
-    final List<String> body = reader.toList();
-    reader.close();
-    
-    int line = 0;
-    assertEquals(10, body.size());
-    assertTrue(body.get(line++).contains("--batch_"));
-    assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
-    assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertEquals("HTTP/1.1 200 OK" + CRLF, body.get(line++));
-    assertEquals("Content-Type: application/json" + CRLF, body.get(line++));
-    assertEquals("Content-Length: 13" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertEquals("Walter Winter" + CRLF, body.get(line++));
-    assertTrue(body.get(line++).contains("--batch_"));
-  }
-
-  @Test
-  public void testChangeSetResponse() throws IOException, BatchException {
-    List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
-    ODataResponse response = new ODataResponse();
-    response.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1");
-    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
-
-    List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
-    responses.add(response);
-    parts.add(new ODataResponsePart(responses, true));
-
-    BatchResponseSerializer writer = new BatchResponseSerializer();
-    ODataResponse batchResponse = new ODataResponse();
-    writer.toODataResponse(parts, batchResponse);
-
-    assertEquals(202, batchResponse.getStatusCode());
-    assertNotNull(batchResponse.getContent());
-
-    final BufferedReaderIncludingLineEndings reader =
-        new BufferedReaderIncludingLineEndings(new InputStreamReader(batchResponse.getContent()));
-    final List<String> body = reader.toList();
-    reader.close();
-    
-    int line = 0;
-    assertEquals(15, body.size());
-    assertTrue(body.get(line++).contains("--batch_"));
-    assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_"));
-    assertEquals(CRLF, body.get(line++));
-    assertTrue(body.get(line++).contains("--changeset_"));
-    assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
-    assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
-    assertEquals("Content-Id: 1" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++));
-    assertEquals("Content-Length: 0" + CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertEquals(CRLF, body.get(line++));
-    assertTrue(body.get(line++).contains("--changeset_"));
-    assertEquals(CRLF, body.get(line++));
-    assertTrue(body.get(line++).contains("--batch_"));
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalBatchProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalBatchProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalBatchProcessor.java
index d4c9873..04d13ff 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalBatchProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalBatchProcessor.java
@@ -18,14 +18,22 @@
  */
 package org.apache.olingo.server.tecsvc.processor;
 
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
+import java.util.UUID;
 
 import org.apache.olingo.commons.api.ODataRuntimeException;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.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.batch.exception.BatchException;
+import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
 import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
 import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
 import org.apache.olingo.server.api.processor.BatchProcessor;
@@ -33,29 +41,34 @@ import org.apache.olingo.server.api.serializer.SerializerException;
 import org.apache.olingo.server.tecsvc.data.DataProvider;
 
 public class TechnicalBatchProcessor extends TechnicalProcessor implements BatchProcessor {
-
-  // TODO: Move to different location
+  // TODO remove
   private static final String PREFERENCE_CONTINUE_ON_ERROR = "odata.continue-on-error";
-  private static final String PREFER_HEADER = "Prefer";
 
   public TechnicalBatchProcessor(DataProvider dataProvider) {
     super(dataProvider);
   }
 
   @Override
-  public void executeBatch(BatchFacade operation, ODataRequest request, ODataResponse response)
+  public void executeBatch(BatchFacade fascade, ODataRequest request, ODataResponse response)
       throws SerializerException, BatchException {
-    boolean continueOnError = shouldContinueOnError(request);
 
-    final List<BatchRequestPart> parts = odata.createFixedFormatDeserializer().parseBatchRequest(request, true);
+    // TODO refactor isContinueOnError
+    boolean continueOnError = isContinueOnError(request);
+
+    final String boundary = getBoundary(request.getHeader(HttpHeader.CONTENT_TYPE));
+    final BatchOptions options =
+        BatchOptions.with().rawBaseUri(request.getRawBaseUri()).rawServiceResolutionUri(
+            request.getRawServiceResolutionUri()).build();
+    final List<BatchRequestPart> parts = odata.createFixedFormatDeserializer().parseBatchRequest(request.getBody(),
+        boundary, options);
     final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
 
     for (BatchRequestPart part : parts) {
-      final ODataResponsePart responsePart = operation.handleBatchRequest(part);
+      final ODataResponsePart responsePart = fascade.handleBatchRequest(part);
       responseParts.add(responsePart); // Also add failed responses
+      final int statusCode = responsePart.getResponses().get(0).getStatusCode();
 
-      if (responsePart.getResponses().get(0).getStatusCode() >= 400
-          && !continueOnError) {
+      if ((statusCode >= 400 && statusCode <= 600) && !continueOnError) {
 
         // Perform some additions actions
         // ...
@@ -64,11 +77,17 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
       }
     }
 
-    odata.createFixedFormatSerializer().writeResponseParts(responseParts, response); // Serialize responses
+    final String responseBoundary = "batch_" + UUID.randomUUID().toString();;
+    final InputStream responseContent =
+        odata.createFixedFormatSerializer().batchResponse(responseParts, responseBoundary);
+    response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.MULTIPART_MIXED + ";boundary=" + responseBoundary);
+    response.setContent(responseContent);
+    response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
   }
 
-  private boolean shouldContinueOnError(ODataRequest request) {
-    final List<String> preferValues = request.getHeaders(PREFER_HEADER);
+  // TODO refactor isContinueOnError
+  private boolean isContinueOnError(ODataRequest request) {
+    final List<String> preferValues = request.getHeaders(HttpHeader.PREFER);
 
     if (preferValues != null) {
       for (final String preference : preferValues) {
@@ -78,18 +97,51 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
       }
     }
     return false;
+
+  }
+
+  // TODO refactor getBoundary
+  private String getBoundary(String contentType) {
+    if (contentType == null) {
+      throw new IllegalArgumentException("Content mustn`t be null.");
+    }
+
+    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("([a-zA-Z0-9_\\-\\.'\\+]{1,70})|\"([a-zA-Z0-9_\\-\\.'\\+\\s\\" +
+              "(\\),/:=\\?]{1,69}[a-zA-Z0-9_\\-\\.'\\+\\(\\),/:=\\?])\"")) {
+
+            String boundary = attrValue[1].trim();
+            if (boundary.matches("\".*\"")) {
+              boundary = boundary.replace("\"", "");
+            }
+
+            return boundary;
+          } else {
+            throw new IllegalArgumentException("Invalid boundary");
+          }
+        }
+
+      }
+    }
+    throw new IllegalArgumentException("Content type is not multipart mixed.");
   }
 
   @Override
-  public ODataResponsePart executeChangeSet(BatchFacade operation, List<ODataRequest> requests,
+  public ODataResponsePart executeChangeSet(BatchFacade fascade, List<ODataRequest> requests,
       BatchRequestPart requestPart) {
     List<ODataResponse> responses = new ArrayList<ODataResponse>();
 
     for (ODataRequest request : requests) {
       try {
-        final ODataResponse oDataResponse = operation.handleODataRequest(request, requestPart);
+        final ODataResponse oDataResponse = fascade.handleODataRequest(request, requestPart);
+        final int statusCode = oDataResponse.getStatusCode();
 
-        if (oDataResponse.getStatusCode() < 400) {
+        if (statusCode < 400) {
           responses.add(oDataResponse);
         } else {
           // Rollback
@@ -106,7 +158,7 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
 
           return new ODataResponsePart(oDataResponse, false);
         }
-      } catch (BatchException e) {
+      } catch (BatchDeserializerException e) {
         throw new ODataRuntimeException(e);
       }
     }


[3/3] olingo-odata4 git commit: [OLINGO-472] BatchDeserializer refactoring

Posted by ch...@apache.org.
[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();


[2/3] olingo-odata4 git commit: [OLINGO-472] BatchDeserializer refactoring

Posted by ch...@apache.org.
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/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
index acd3231..870f276 100644
--- 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
@@ -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
@@ -21,101 +21,101 @@ 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 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 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 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 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(", ");
     }
 
-    public List<String> getValues() {
-      return values;
+    if (result.length() > 0) {
+      result.delete(result.length() - 2, result.length());
     }
 
-    public String getValue() {
-      final StringBuilder result = new StringBuilder();
+    return result.toString();
+  }
 
-      for (final String value : values) {
-        result.append(value);
-        result.append(", ");
-      }
+  public String getValueNotNull() {
+    final String value = getValue();
 
-      if (result.length() > 0) {
-        result.delete(result.length() - 2, result.length());
-      }
+    return (value == null) ? "" : value;
+  }
 
-      return result.toString();
-    }
+  @Override
+  public HeaderField clone() {
+    List<String> newValues = new ArrayList<String>();
+    newValues.addAll(values);
 
-    public String getValueNotNull() {
-      final String value = getValue();
+    return new HeaderField(fieldName, newValues, lineNumber);
+  }
 
-      return (value == null) ? "" : value;
-    }
+  public int getLineNumber() {
+    return lineNumber;
+  }
 
-    @Override
-    public HeaderField clone() {
-      List<String> newValues = new ArrayList<String>();
-      newValues.addAll(values);
+  @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;
+  }
 
-      return new HeaderField(fieldName, newValues, lineNumber);
+  @Override
+  public boolean equals(final Object obj) {
+    if (this == obj) {
+      return true;
     }
-
-    public int getLineNumber() {
-      return lineNumber;
+    if (obj == null) {
+      return false;
     }
-
-    @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;
+    if (getClass() != obj.getClass()) {
+      return false;
     }
-
-    @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)) {
+    HeaderField other = (HeaderField) obj;
+    if (fieldName == null) {
+      if (other.fieldName != null) {
         return false;
       }
-      if (lineNumber != other.lineNumber) {
-        return false;
-      }
-      if (values == null) {
-        if (other.values != null) {
-          return false;
-        }
-      } else if (!values.equals(other.values)) {
+    } else if (!fieldName.equals(other.fieldName)) {
+      return false;
+    }
+    if (lineNumber != other.lineNumber) {
+      return false;
+    }
+    if (values == null) {
+      if (other.values != null) {
         return false;
       }
-      return true;
+    } else if (!values.equals(other.values)) {
+      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/HttpRequestStatusLine.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java
index 1384770..1e52ebc 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/HttpRequestStatusLine.java
@@ -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
@@ -28,9 +28,8 @@ import java.util.regex.Pattern;
 
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpMethod;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.api.batch.BatchException.MessageKeys;
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings.Line;
+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("([^/][^?]*)(?:\\?(.*))?");
@@ -52,7 +51,7 @@ public class HttpRequestStatusLine {
 
   public HttpRequestStatusLine(final Line httpStatusLine, final String baseUri, final String serviceResolutionUri,
       final Header requestHeader)
-      throws BatchException {
+          throws BatchDeserializerException {
     statusLine = httpStatusLine;
     requestBaseUri = baseUri;
     header = requestHeader;
@@ -60,7 +59,7 @@ public class HttpRequestStatusLine {
     parse();
   }
 
-  private void parse() throws BatchException {
+  private void parse() throws BatchDeserializerException {
     final String[] parts = statusLine.toString().split(" ");
 
     if (parts.length == 3) {
@@ -68,35 +67,40 @@ public class HttpRequestStatusLine {
       uri = new ODataURI(parts[1], requestBaseUri, statusLine.getLineNumber(), header.getHeaders(HttpHeader.HOST));
       httpVersion = parseHttpVersion(parts[2]);
     } else {
-      throw new BatchException("Invalid status line", MessageKeys.INVALID_STATUS_LINE, statusLine.getLineNumber());
+      throw new BatchDeserializerException("Invalid status line", MessageKeys.INVALID_STATUS_LINE, statusLine
+          .getLineNumber());
     }
   }
 
-  private HttpMethod parseMethod(final String method) throws BatchException {
+  private HttpMethod parseMethod(final String method) throws BatchDeserializerException {
     try {
       return HttpMethod.valueOf(method.trim());
     } catch (IllegalArgumentException e) {
-      throw new BatchException("Illegal http method", MessageKeys.INVALID_METHOD, statusLine.getLineNumber());
+      throw new BatchDeserializerException("Illegal http method", MessageKeys.INVALID_METHOD, statusLine
+          .getLineNumber());
     }
   }
 
-  private String parseHttpVersion(final String httpVersion) throws BatchException {
+  private String parseHttpVersion(final String httpVersion) throws BatchDeserializerException {
     if (!HTTP_VERSION.equals(httpVersion.trim())) {
-      throw new BatchException("Invalid http version", MessageKeys.INVALID_HTTP_VERSION, statusLine.getLineNumber());
+      throw new BatchDeserializerException("Invalid http version", MessageKeys.INVALID_HTTP_VERSION, statusLine
+          .getLineNumber());
     } else {
       return HTTP_VERSION;
     }
   }
 
-  public void validateHttpMethod(boolean isChangeSet) throws BatchException {
+  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 BatchException("Invalid change set method", MessageKeys.INVALID_CHANGESET_METHOD, statusLine
+        throw new BatchDeserializerException("Invalid change set method", MessageKeys.INVALID_CHANGESET_METHOD,
+            statusLine
             .getLineNumber());
       } else {
-        throw new BatchException("Invalid query operation method", MessageKeys.INVALID_QUERY_OPERATION_METHOD,
+        throw new BatchDeserializerException("Invalid query operation method",
+            MessageKeys.INVALID_QUERY_OPERATION_METHOD,
             statusLine.getLineNumber());
       }
     }
@@ -127,12 +131,13 @@ public class HttpRequestStatusLine {
     private final String requestBaseUri;
     private final int lineNumber;
 
-    public ODataURI(final String rawUri, String requestBaseUri) throws BatchException {
+    public ODataURI(final String rawUri, final String requestBaseUri) throws BatchDeserializerException {
       this(rawUri, requestBaseUri, 0, new ArrayList<String>());
     }
 
-    public ODataURI(final String rawUri, String requestBaseUri, int lineNumber, List<String> hostHeader)
-        throws BatchException {
+    public ODataURI(final String rawUri, final String requestBaseUri, final int lineNumber,
+        final List<String> hostHeader)
+        throws BatchDeserializerException {
       this.lineNumber = lineNumber;
       this.requestBaseUri = requestBaseUri;
 
@@ -147,7 +152,8 @@ public class HttpRequestStatusLine {
         if (hostHeader != null && hostHeader.size() == 1) {
           buildUri(hostHeader.get(0) + absoluteUriWtithHostMatcher.group(1), absoluteUriWtithHostMatcher.group(2));
         } else {
-          throw new BatchException("Exactly one host header is required", MessageKeys.MISSING_MANDATORY_HEADER,
+          throw new BatchDeserializerException("Exactly one host header is required",
+              MessageKeys.MISSING_MANDATORY_HEADER,
               lineNumber);
         }
 
@@ -155,13 +161,13 @@ public class HttpRequestStatusLine {
         buildUri(requestBaseUri + "/" + relativeUriMatcher.group(1), relativeUriMatcher.group(2));
 
       } else {
-        throw new BatchException("Invalid uri", MessageKeys.INVALID_URI, lineNumber);
+        throw new BatchDeserializerException("Invalid uri", MessageKeys.INVALID_URI, lineNumber);
       }
     }
 
-    private void buildUri(final String resourceUri, final String queryOptions) throws BatchException {
+    private void buildUri(final String resourceUri, final String queryOptions) throws BatchDeserializerException {
       if (!resourceUri.startsWith(requestBaseUri)) {
-        throw new BatchException("Host do not match", MessageKeys.INVALID_URI, lineNumber);
+        throw new BatchDeserializerException("Host do not match", MessageKeys.INVALID_URI, lineNumber);
       }
 
       final int oDataPathIndex = resourceUri.indexOf(requestBaseUri);
@@ -182,7 +188,7 @@ public class HttpRequestStatusLine {
       return rawServiceResolutionUri;
     }
 
-    public void setRawServiceResolutionUri(String rawServiceResolutionUri) {
+    public void setRawServiceResolutionUri(final String rawServiceResolutionUri) {
       this.rawServiceResolutionUri = rawServiceResolutionUri;
     }
 
@@ -190,7 +196,7 @@ public class HttpRequestStatusLine {
       return rawQueryPath;
     }
 
-    public void setRawQueryPath(String rawQueryPath) {
+    public void setRawQueryPath(final String rawQueryPath) {
       this.rawQueryPath = rawQueryPath;
     }
 
@@ -198,7 +204,7 @@ public class HttpRequestStatusLine {
       return rawODataPath;
     }
 
-    public void setRawODataPath(String rawODataPath) {
+    public void setRawODataPath(final String rawODataPath) {
       this.rawODataPath = rawODataPath;
     }
 
@@ -206,7 +212,7 @@ public class HttpRequestStatusLine {
       return rawBaseUri;
     }
 
-    public void setRawBaseUri(String rawBaseUri) {
+    public void setRawBaseUri(final String rawBaseUri) {
       this.rawBaseUri = rawBaseUri;
     }
 
@@ -214,7 +220,7 @@ public class HttpRequestStatusLine {
       return rawRequestUri;
     }
 
-    public void setRawRequestUri(String rawRequestUri) {
+    public void setRawRequestUri(final String rawRequestUri) {
       this.rawRequestUri = rawRequestUri;
     }
 

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/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
new file mode 100644
index 0000000..6485a49
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/Line.java
@@ -0,0 +1,72 @@
+/*
+ * 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

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
index 81872a3..4e8138f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
@@ -18,11 +18,10 @@
  */
 package org.apache.olingo.server.core.serializer;
 
-import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStreamWriter;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -32,11 +31,10 @@ import org.apache.olingo.commons.api.http.HttpContentType;
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.batch.BatchException;
-import org.apache.olingo.server.api.batch.BatchException.MessageKeys;
+import org.apache.olingo.server.api.batch.exception.BatchSerializerExecption;
+import org.apache.olingo.server.api.batch.exception.BatchSerializerExecption.MessageKeys;
 import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
 import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
-import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
 
 public class BatchResponseSerializer {
   private static final int BUFFER_SIZE = 4096;
@@ -45,63 +43,59 @@ public class BatchResponseSerializer {
   private static final String SP = " ";
   private static final String CRLF = "\r\n";
 
-  public void toODataResponse(final List<ODataResponsePart> batchResponse, final ODataResponse response)
-      throws BatchException {
-    final String boundary = generateBoundary("batch");
+  public InputStream serialize(final List<ODataResponsePart> responses, final String boundary)
+      throws BatchSerializerExecption {
+    StringBuilder builder = createBody(responses, boundary);
 
-    setStatusCode(response);
-    ResponseWriter writer = createBody(batchResponse, boundary);
-
-    response.setContent(writer.toInputStream());
-    setHttpHeader(response, writer, boundary);
+    return new ByteArrayInputStream(builder.toString().getBytes());
   }
 
-  private ResponseWriter createBody(final List<ODataResponsePart> batchResponses, final String boundary)
-      throws BatchException {
-    final ResponseWriter writer = new ResponseWriter();
+  private StringBuilder createBody(final List<ODataResponsePart> batchResponses, final String boundary)
+      throws BatchSerializerExecption {
+    final StringBuilder builder = new StringBuilder();
 
     for (final ODataResponsePart part : batchResponses) {
-      writer.append(getDashBoundary(boundary));
+      builder.append(getDashBoundary(boundary));
 
       if (part.isChangeSet()) {
-        appendChangeSet(part, writer);
+        appendChangeSet(part, builder);
       } else {
-        appendBodyPart(part.getResponses().get(0), writer, false);
+        appendBodyPart(part.getResponses().get(0), builder, false);
       }
     }
-    writer.append(getCloseDelimiter(boundary));
+    builder.append(getCloseDelimiter(boundary));
 
-    return writer;
+    return builder;
   }
 
-  private void appendChangeSet(ODataResponsePart part, ResponseWriter writer) throws BatchException {
+  private void appendChangeSet(ODataResponsePart part, StringBuilder builder) throws BatchSerializerExecption {
     final String changeSetBoundary = generateBoundary("changeset");
 
-    appendChangeSetHeader(writer, changeSetBoundary);
-    writer.append(CRLF);
+    appendChangeSetHeader(builder, changeSetBoundary);
+    builder.append(CRLF);
 
     for (final ODataResponse response : part.getResponses()) {
-      writer.append(getDashBoundary(changeSetBoundary));
-      appendBodyPart(response, writer, true);
+      builder.append(getDashBoundary(changeSetBoundary));
+      appendBodyPart(response, builder, true);
     }
 
-    writer.append(getCloseDelimiter(changeSetBoundary));
-    writer.append(CRLF);
+    builder.append(getCloseDelimiter(changeSetBoundary));
+    builder.append(CRLF);
   }
 
-  private void appendBodyPart(ODataResponse response, ResponseWriter writer, boolean isChangeSet) 
-      throws BatchException {
+  private void appendBodyPart(ODataResponse response, StringBuilder builder, boolean isChangeSet)
+      throws BatchSerializerExecption {
     byte[] body = getBody(response);
 
-    appendBodyPartHeader(response, writer, isChangeSet);
-    writer.append(CRLF);
+    appendBodyPartHeader(response, builder, isChangeSet);
+    builder.append(CRLF);
 
-    appendStatusLine(response, writer);
-    appendResponseHeader(response, body.length, writer);
-    writer.append(CRLF);
+    appendStatusLine(response, builder);
+    appendResponseHeader(response, body.length, builder);
+    builder.append(CRLF);
 
-    writer.append(body);
-    writer.append(CRLF);
+    builder.append(new String(body));
+    builder.append(CRLF);
   }
 
   private byte[] getBody(final ODataResponse response) {
@@ -115,8 +109,8 @@ public class BatchResponseSerializer {
       try {
         while ((n = content.read(buffer, 0, buffer.length)) != -1) {
           out.write(buffer, 0, n);
-          out.flush();
         }
+        out.flush();
       } catch (IOException e) {
         throw new ODataRuntimeException(e);
       }
@@ -127,21 +121,21 @@ public class BatchResponseSerializer {
     }
   }
 
-  private void appendChangeSetHeader(ResponseWriter writer, final String changeSetBoundary) {
+  private void appendChangeSetHeader(StringBuilder builder, final String changeSetBoundary) {
     appendHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED.toString() + "; boundary="
-        + changeSetBoundary, writer);
+        + changeSetBoundary, builder);
   }
 
-  private void appendHeader(String name, String value, ResponseWriter writer) {
-    writer.append(name)
+  private void appendHeader(String name, String value, StringBuilder builder) {
+    builder.append(name)
         .append(COLON)
         .append(SP)
         .append(value)
         .append(CRLF);
   }
 
-  private void appendStatusLine(ODataResponse response, ResponseWriter writer) {
-    writer.append("HTTP/1.1")
+  private void appendStatusLine(ODataResponse response, StringBuilder builder) {
+    builder.append("HTTP/1.1")
         .append(SP)
         .append("" + response.getStatusCode())
         .append(SP)
@@ -149,43 +143,34 @@ public class BatchResponseSerializer {
         .append(CRLF);
   }
 
-  private void appendResponseHeader(ODataResponse response, int contentLength, ResponseWriter writer) {
+  private void appendResponseHeader(ODataResponse response, int contentLength, StringBuilder builder) {
     final Map<String, String> header = response.getHeaders();
 
     for (final String key : header.keySet()) {
       // Requests do never has a content id header
       if (!key.equalsIgnoreCase(BatchParserCommon.HTTP_CONTENT_ID)) {
-        appendHeader(key, header.get(key), writer);
+        appendHeader(key, header.get(key), builder);
       }
     }
 
-    appendHeader(HttpHeader.CONTENT_LENGTH, "" + contentLength, writer);
+    appendHeader(HttpHeader.CONTENT_LENGTH, "" + contentLength, builder);
   }
 
-  private void appendBodyPartHeader(ODataResponse response, ResponseWriter writer, boolean isChangeSet)
-      throws BatchException {
-    appendHeader(HttpHeader.CONTENT_TYPE, HttpContentType.APPLICATION_HTTP, writer);
-    appendHeader(BatchParserCommon.HTTP_CONTENT_TRANSFER_ENCODING, BatchParserCommon.BINARY_ENCODING, writer);
+  private void appendBodyPartHeader(ODataResponse response, StringBuilder builder, boolean isChangeSet)
+      throws BatchSerializerExecption {
+    appendHeader(HttpHeader.CONTENT_TYPE, HttpContentType.APPLICATION_HTTP, builder);
+    appendHeader(BatchParserCommon.HTTP_CONTENT_TRANSFER_ENCODING, BatchParserCommon.BINARY_ENCODING, builder);
 
     if (isChangeSet) {
       if (response.getHeaders().get(BatchParserCommon.HTTP_CONTENT_ID) != null) {
         appendHeader(BatchParserCommon.HTTP_CONTENT_ID, response.getHeaders().get(BatchParserCommon.HTTP_CONTENT_ID),
-            writer);
+            builder);
       } else {
-        throw new BatchException("Missing content id", MessageKeys.MISSING_CONTENT_ID, "");
+        throw new BatchSerializerExecption("Missing content id", MessageKeys.MISSING_CONTENT_ID);
       }
     }
   }
 
-  private void setHttpHeader(ODataResponse response, ResponseWriter writer, final String boundary) {
-    response.setHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED.toString() + "; boundary=" + boundary);
-    response.setHeader(HttpHeader.CONTENT_LENGTH, "" + writer.length());
-  }
-
-  private void setStatusCode(final ODataResponse response) {
-    response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
-  }
-
   private String getDashBoundary(String boundary) {
     return DOUBLE_DASH + boundary + CRLF;
   }
@@ -197,48 +182,4 @@ public class BatchResponseSerializer {
   private String generateBoundary(final String value) {
     return value + "_" + UUID.randomUUID().toString();
   }
-
-  private static class ResponseWriter {
-    private CircleStreamBuffer buffer = new CircleStreamBuffer();
-    private BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream()));
-    private int length = 0;
-
-    public ResponseWriter append(final String content) {
-      length += content.length();
-      try {
-        writer.write(content);
-      } catch (IOException e) {
-        throw new ODataRuntimeException(e);
-      }
-
-      return this;
-    }
-
-    public ResponseWriter append(final byte[] content) {
-      length += content.length;
-      try {
-        writer.flush();
-        buffer.getOutputStream().write(content, 0, content.length);
-      } catch (IOException e) {
-        throw new ODataRuntimeException(e);
-      }
-
-      return this;
-    }
-
-    public int length() {
-      return length;
-    }
-
-    public InputStream toInputStream() {
-      try {
-        writer.flush();
-        writer.close();
-      } catch (IOException e) {
-        throw new ODataRuntimeException(e);
-      }
-
-      return buffer.getInputStream();
-    }
-  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java
index 5b7ba78..81710e0 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerImpl.java
@@ -25,8 +25,7 @@ import java.util.List;
 
 import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.server.api.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;
 import org.apache.olingo.server.api.serializer.FixedFormatSerializer;
 import org.apache.olingo.server.api.serializer.PrimitiveValueSerializerOptions;
@@ -61,10 +60,12 @@ public class FixedFormatSerializerImpl implements FixedFormatSerializer {
     }
   }
 
-  //TODO: Signature
+  // TODO: Signature
   @Override
-  public void writeResponseParts(List<ODataResponsePart> batchResponses, ODataResponse response) throws BatchException {
-    BatchResponseSerializer writer = new BatchResponseSerializer();
-    writer.toODataResponse(batchResponses, response);
+  public InputStream batchResponse(final List<ODataResponsePart> batchResponses, final String boundary)
+      throws BatchSerializerExecption {
+    final BatchResponseSerializer serializer = new BatchResponseSerializer();
+
+    return serializer.serialize(batchResponses, boundary);
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index ece835d..296d554 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -96,23 +96,25 @@ SerializerException.MISSING_PROPERTY=The non-nullable property '%1$s' is missing
 SerializerException.WRONG_PROPERTY_VALUE=The value '%2$s' is not valid for property '%1$s'.
 SerializerException.WRONG_PRIMITIVE_VALUE=The value '%2$s' is not valid for the primitive type '%1$s' and the given facets.
 
-BatchException.INVALID_BOUNDARY=Invalid boundary at line '%1$s'.
-BatchException.INVALID_CHANGESET_METHOD=Invalid method: a ChangeSet cannot contain retrieve requests at line '%1$s'.
-BatchException.INVALID_CONTENT=Retrieve requests must not contain any body content '%1$s'.
-BatchException.INVALID_CONTENT_LENGTH=Invalid content length: content length have to be an integer and positive at line '%1$s'.
-BatchException.INVALID_CONTENT_TRANSFER_ENCODING=The Content-Transfer-Encoding should be binary: line '%1$s'.
-BatchException.INVALID_CONTENT_TYPE=Content-Type should be '%1$s'.
-BatchException.INVALID_HEADER=Invalid header: '%1$s' at line '%2$s'.
-BatchException.INVALID_HTTP_VERSION=Invalid HTTP version: The version have to be HTTP/1.1 at line '%1$s'.
-BatchException.INVALID_METHOD=Invalid HTTP method at line '%1$s'.
-BatchException.INVALID_QUERY_OPERATION_METHOD=Invalid method: a query operation can only contain retrieve requests at line '%1$s'.
-BatchException.INVALID_STATUS_LINE=Invalid HTTP status line at line '%1$s'.
-BatchException.INVALID_URI=Invalid URI at line '%1$s'.
-BatchException.FORBIDDEN_HEADER=Forbidden header at line '%1$s'.
-BatchException.MISSING_BLANK_LINE=Missing blank line at line '%1$s'.
-BatchException.MISSING_BOUNDARY_DELIMITER=Missing boundary delimiter at line '%1$s'.
-BatchException.MISSING_CLOSE_DELIMITER=Missing close delimiter at line '%1$s'.
-BatchException.MISSING_CONTENT_ID=Missing content-id at line '%1$s'.
-BatchException.MISSING_CONTENT_TRANSFER_ENCODING=Missing content transfer encoding at line '%1$s'.
-BatchException.MISSING_CONTENT_TYPE=Missing content-type at line '%1$s'.
-BatchException.MISSING_MANDATORY_HEADER=Missing mandatory header at line '%1$s'.
\ No newline at end of file
+BatchDeserializerException.INVALID_BOUNDARY=Invalid boundary at line '%1$s'.
+BatchDeserializerException.INVALID_CHANGESET_METHOD=Invalid method: a ChangeSet cannot contain retrieve requests at line '%1$s'.
+BatchDeserializerException.INVALID_CONTENT=Retrieve requests must not contain any body content '%1$s'.
+BatchDeserializerException.INVALID_CONTENT_LENGTH=Invalid content length: content length have to be an integer and positive at line '%1$s'.
+BatchDeserializerException.INVALID_CONTENT_TRANSFER_ENCODING=The Content-Transfer-Encoding should be binary: line '%1$s'.
+BatchDeserializerException.INVALID_CONTENT_TYPE=Content-Type should be '%1$s'.
+BatchDeserializerException.INVALID_HEADER=Invalid header: '%1$s' at line '%2$s'.
+BatchDeserializerException.INVALID_HTTP_VERSION=Invalid HTTP version: The version have to be HTTP/1.1 at line '%1$s'.
+BatchDeserializerException.INVALID_METHOD=Invalid HTTP method at line '%1$s'.
+BatchDeserializerException.INVALID_QUERY_OPERATION_METHOD=Invalid method: a query operation can only contain retrieve requests at line '%1$s'.
+BatchDeserializerException.INVALID_STATUS_LINE=Invalid HTTP status line at line '%1$s'.
+BatchDeserializerException.INVALID_URI=Invalid URI at line '%1$s'.
+BatchDeserializerException.FORBIDDEN_HEADER=Forbidden header at line '%1$s'.
+BatchDeserializerException.MISSING_BLANK_LINE=Missing blank line at line '%1$s'.
+BatchDeserializerException.MISSING_BOUNDARY_DELIMITER=Missing boundary delimiter at line '%1$s'.
+BatchDeserializerException.MISSING_CLOSE_DELIMITER=Missing close delimiter at line '%1$s'.
+BatchDeserializerException.MISSING_CONTENT_ID=Missing content-id at line '%1$s'.
+BatchDeserializerException.MISSING_CONTENT_TRANSFER_ENCODING=Missing content transfer encoding at line '%1$s'.
+BatchDeserializerException.MISSING_CONTENT_TYPE=Missing content-type at line '%1$s'.
+BatchDeserializerException.MISSING_MANDATORY_HEADER=Missing mandatory header at line '%1$s'.
+
+BatchSerializerExecption.MISSING_CONTENT_ID=Each request within a change set required exactly one content id.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java
index 8976316..9e29b83 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/MockedBatchHandlerTest.java
@@ -21,14 +21,16 @@ package org.apache.olingo.server.core.batchhandler;
 import static org.junit.Assert.*;
 
 import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
+import org.apache.olingo.commons.api.http.HttpContentType;
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpMethod;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
@@ -36,8 +38,10 @@ import org.apache.olingo.server.api.OData;
 import org.apache.olingo.server.api.ODataRequest;
 import org.apache.olingo.server.api.ODataResponse;
 import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.api.batch.BatchException;
 import org.apache.olingo.server.api.batch.BatchFacade;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException;
+import org.apache.olingo.server.api.batch.exception.BatchException;
+import org.apache.olingo.server.api.deserializer.batch.BatchOptions;
 import org.apache.olingo.server.api.deserializer.batch.BatchRequestPart;
 import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart;
 import org.apache.olingo.server.api.processor.BatchProcessor;
@@ -469,22 +473,7 @@ public class MockedBatchHandlerTest {
     assertEquals(45, line);
   }
 
-  private String checkChangeSetPartHeader(final List<String> response, int line) {
-    assertEquals(CRLF, response.get(line++));
-    assertTrue(response.get(line++).contains("--changeset_"));
-    assertEquals("Content-Type: application/http" + CRLF, response.get(line++));
-    assertEquals("Content-Transfer-Encoding: binary" + CRLF, response.get(line++));
-
-    assertTrue(response.get(line).contains("Content-Id:"));
-    String contentId = response.get(line).split(":")[1].trim();
-    line++;
-
-    assertEquals(CRLF, response.get(line++));
-
-    return contentId;
-  }
-
-  @Test(expected = BatchException.class)
+  @Test(expected = BatchDeserializerException.class)
   public void testInvalidMethod() throws Exception {
     final String content = ""
         + "--batch_12345" + CRLF
@@ -511,7 +500,7 @@ public class MockedBatchHandlerTest {
     batchHandler.process(request, response, true);
   }
 
-  @Test(expected = BatchException.class)
+  @Test(expected = BatchDeserializerException.class)
   public void testInvalidContentType() throws Exception {
     final String content = ""
         + "--batch_12345" + CRLF
@@ -541,6 +530,21 @@ public class MockedBatchHandlerTest {
   /*
    * Helper methods
    */
+  private String checkChangeSetPartHeader(final List<String> response, int line) {
+    assertEquals(CRLF, response.get(line++));
+    assertTrue(response.get(line++).contains("--changeset_"));
+    assertEquals("Content-Type: application/http" + CRLF, response.get(line++));
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, response.get(line++));
+
+    assertTrue(response.get(line).contains("Content-Id:"));
+    String contentId = response.get(line).split(":")[1].trim();
+    line++;
+
+    assertEquals(CRLF, response.get(line++));
+
+    return contentId;
+  }
+
   private Map<String, List<String>> getMimeHeader() {
     final Map<String, List<String>> header = new HashMap<String, List<String>>();
     header.put(HttpHeader.CONTENT_TYPE, Arrays.asList(new String[] { BATCH_CONTENT_TYPE }));
@@ -549,7 +553,7 @@ public class MockedBatchHandlerTest {
   }
 
   private ODataRequest buildODataRequest(final String content, final Map<String, List<String>> header)
-      throws UnsupportedEncodingException {
+      throws Exception {
     final ODataRequest request = new ODataRequest();
 
     for (final String key : header.keySet()) {
@@ -581,14 +585,14 @@ public class MockedBatchHandlerTest {
     }
 
     @Override
-    public ODataResponsePart executeChangeSet(BatchFacade operation, List<ODataRequest> requests,
+    public ODataResponsePart executeChangeSet(BatchFacade fascade, List<ODataRequest> requests,
         BatchRequestPart requestPart) {
       List<ODataResponse> responses = new ArrayList<ODataResponse>();
 
       for (ODataRequest request : requests) {
         try {
-          responses.add(operation.handleODataRequest(request, requestPart));
-        } catch (BatchException e) {
+          responses.add(fascade.handleODataRequest(request, requestPart));
+        } catch (Exception e) {
           fail();
         }
       }
@@ -597,9 +601,12 @@ public class MockedBatchHandlerTest {
     }
 
     @Override
-    public void executeBatch(BatchFacade operation, ODataRequest request, ODataResponse response)
-        throws SerializerException, BatchException {
-      final List<BatchRequestPart> parts = odata.createFixedFormatDeserializer().parseBatchRequest(request, true);
+    public void executeBatch(BatchFacade fascade, ODataRequest request, ODataResponse response)
+        throws BatchException, SerializerException {
+      final String boundary = getBoundary(request.getHeader(HttpHeader.CONTENT_TYPE));
+      final BatchOptions options = BatchOptions.with().isStrict(true).rawBaseUri(BASE_URI).build();
+      final List<BatchRequestPart> parts =
+          odata.createFixedFormatDeserializer().parseBatchRequest(request.getBody(), boundary, options);
       final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
 
       for (BatchRequestPart part : parts) {
@@ -615,10 +622,20 @@ public class MockedBatchHandlerTest {
           });
         }
 
-        responseParts.add(operation.handleBatchRequest(part));
+        responseParts.add(fascade.handleBatchRequest(part));
       }
 
-      odata.createFixedFormatSerializer().writeResponseParts(responseParts, response);
+      final String responeBoundary = "batch_" + UUID.randomUUID().toString();
+      final InputStream responseStream =
+          odata.createFixedFormatSerializer().batchResponse(responseParts, responeBoundary);
+      
+      response.setStatusCode(HttpStatusCode.ACCEPTED.getStatusCode());
+      response.setHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + ";boundary=" + responeBoundary);
+      response.setContent(responseStream);
+    }
+
+    private String getBoundary(String contentType) throws BatchDeserializerException {
+      return BatchParserCommon.getBoundary(contentType, 0);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchParserCommonTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchParserCommonTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchParserCommonTest.java
index 2191555..35998cb 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchParserCommonTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchParserCommonTest.java
@@ -24,10 +24,9 @@ import java.util.ArrayList;
 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.BatchParserCommon;
 import org.apache.olingo.server.core.deserializer.batch.Header;
-import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings.Line;
+import org.apache.olingo.server.core.deserializer.batch.Line;
 import org.junit.Test;
 
 public class BatchParserCommonTest {
@@ -35,7 +34,7 @@ public class BatchParserCommonTest {
   private static final String CRLF = "\r\n";
 
   @Test
-  public void testMultipleHeader() throws BatchException {
+  public void testMultipleHeader() throws Exception {
     String[] messageRaw = new String[] {
         "Content-Id: 1" + CRLF,
         "Content-Id: 2" + CRLF,
@@ -55,7 +54,7 @@ public class BatchParserCommonTest {
   }
   
   @Test
-  public void testMultipleHeaderSameValue() throws BatchException {
+  public void testMultipleHeaderSameValue() throws Exception {
     String[] messageRaw = new String[] {
         "Content-Id: 1" + CRLF,
         "Content-Id: 1" + CRLF,
@@ -74,7 +73,7 @@ public class BatchParserCommonTest {
   }
   
   @Test
-  public void testHeaderSperatedByComma() throws BatchException {
+  public void testHeaderSperatedByComma() throws Exception {
     String[] messageRaw = new String[] {
         "Content-Id: 1" + CRLF,
         "Upgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11" + CRLF,
@@ -96,7 +95,7 @@ public class BatchParserCommonTest {
   }
   
   @Test
-  public void testMultipleAcceptHeader() throws BatchException {
+  public void testMultipleAcceptHeader() throws Exception {
     String[] messageRaw = new String[] {
         "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF,
         "Accept: text/plain;q=0.3" + CRLF,
@@ -115,7 +114,7 @@ public class BatchParserCommonTest {
   }
   
   @Test
-  public void testMultipleAcceptHeaderSameValue() throws BatchException {
+  public void testMultipleAcceptHeaderSameValue() throws Exception {
     String[] messageRaw = new String[] {
         "Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1" + CRLF,
         "Accept: application/atomsvc+xml;q=0.8" + CRLF,
@@ -134,7 +133,7 @@ public class BatchParserCommonTest {
   }
   
   @Test
-  public void testMultipleAccepLanguagetHeader() throws BatchException {
+  public void testMultipleAccepLanguagetHeader() throws Exception {
     String[] messageRaw = new String[] {
         "Accept-Language:en-US,en;q=0.7,en-UK;q=0.9" + CRLF,
         "Accept-Language: de-DE;q=0.3" + CRLF,
@@ -152,7 +151,7 @@ public class BatchParserCommonTest {
   }
   
   @Test
-  public void testMultipleAccepLanguagetHeaderSameValue() throws BatchException {
+  public void testMultipleAccepLanguagetHeaderSameValue() throws Exception {
     String[] messageRaw = new String[] {
         "Accept-Language:en-US,en;q=0.7,en-UK;q=0.9" + CRLF,
         "Accept-Language:en-US,en;q=0.7" + CRLF,

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/babc3a61/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchRequestParserTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchRequestParserTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchRequestParserTest.java
index 68a219a..7beda1d 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchRequestParserTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/deserializer/BatchRequestParserTest.java
@@ -26,15 +26,14 @@ import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
 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.batch.exception.BatchDeserializerException;
+import org.apache.olingo.server.api.batch.exception.BatchDeserializerException.MessageKeys;
+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;
 import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
@@ -43,8 +42,8 @@ import org.junit.Test;
 public class BatchRequestParserTest {
 
   private static final String SERVICE_ROOT = "http://localhost/odata";
-  private static final String CONTENT_TYPE = "multipart/mixed;boundary=batch_8194-cf13-1f56";
   private static final String CRLF = "\r\n";
+  private static final String BOUNDARY = "batch_8194-cf13-1f56";
   private static final String MIME_HEADERS = "Content-Type: application/http" + CRLF
       + "Content-Transfer-Encoding: binary" + CRLF;
   private static final String GET_REQUEST = ""
@@ -55,7 +54,7 @@ public class BatchRequestParserTest {
       + CRLF;
 
   @Test
-  public void test() throws IOException, BatchException, URISyntaxException {
+  public void test() throws Exception {
     final InputStream in = readFile("/batchWithPost.batch");
     final List<BatchRequestPart> batchRequestParts = parse(in);
 
@@ -100,7 +99,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testImageInContent() throws IOException, BatchException, URISyntaxException {
+  public void testImageInContent() throws Exception {
     final InputStream contentInputStream = readFile("/batchWithContent.batch");
     final String content = StringUtil.toString(contentInputStream);
     final String batch = ""
@@ -156,7 +155,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testPostWithoutBody() throws IOException, BatchException, URISyntaxException {
+  public void testPostWithoutBody() throws Exception {
     final String batch = CRLF
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -190,87 +189,68 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testBoundaryParameterWithQuotas() throws BatchException, UnsupportedEncodingException {
+  public void testBoundaryParameterWithQuotas() throws Exception {
     final String contentType = "multipart/mixed; boundary=\"batch_1.2+34:2j)0?\"";
+    final String boundary = BatchParserCommon.getBoundary(contentType, 0);
     final String batch = ""
         + "--batch_1.2+34:2j)0?" + CRLF
         + GET_REQUEST
         + "--batch_1.2+34:2j)0?--";
     final BatchParser parser = new BatchParser();
+    final BatchOptions batchOptions = BatchOptions.with().isStrict(true).rawBaseUri(SERVICE_ROOT).build();
     final List<BatchRequestPart> batchRequestParts =
-        parser.parseBatchRequest(StringUtil.toInputStream(batch), contentType, SERVICE_ROOT, "", true);
+        parser.parseBatchRequest(StringUtil.toInputStream(batch), boundary, batchOptions);
 
     assertNotNull(batchRequestParts);
     assertFalse(batchRequestParts.isEmpty());
   }
 
   @Test
-  public void testBatchWithInvalidContentType() throws UnsupportedEncodingException {
+  public void testBatchWithInvalidContentType() throws Exception {
     final String invalidContentType = "multipart;boundary=batch_1740-bb84-2f7f";
-    final String batch = ""
-        + "--batch_1740-bb84-2f7f" + CRLF
-        + GET_REQUEST
-        + "--batch_1740-bb84-2f7f--";
-    final BatchParser parser = new BatchParser();
 
     try {
-      parser.parseBatchRequest(StringUtil.toInputStream(batch), invalidContentType, SERVICE_ROOT, "", true);
+      BatchParserCommon.getBoundary(invalidContentType, 0);
       fail();
-    } catch (BatchException e) {
-      assertMessageKey(e, BatchException.MessageKeys.INVALID_CONTENT_TYPE);
+    } catch (BatchDeserializerException e) {
+      assertMessageKey(e, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE);
     }
   }
 
   @Test
-  public void testContentTypeCharset() throws BatchException {
+  public void testContentTypeCharset() throws Exception {
     final String contentType = "multipart/mixed; charset=UTF-8;boundary=batch_14d1-b293-b99a";
-    final String batch = ""
-        + "--batch_14d1-b293-b99a" + CRLF
-        + GET_REQUEST
-        + "--batch_14d1-b293-b99a--";
-    final BatchParser parser = new BatchParser();
-    final List<BatchRequestPart> parts =
-        parser.parseBatchRequest(StringUtil.toInputStream(batch), contentType, SERVICE_ROOT, "", true);
+    final String boundary = BatchParserCommon.getBoundary(contentType, 0);
 
-    assertEquals(1, parts.size());
+    assertEquals("batch_14d1-b293-b99a", boundary);
   }
 
   @Test
-  public void testBatchWithoutBoundaryParameter() throws UnsupportedEncodingException {
+  public void testBatchWithoutBoundaryParameter() throws Exception {
     final String invalidContentType = "multipart/mixed";
-    final String batch = ""
-        + "--batch_1740-bb84-2f7f" + CRLF
-        + GET_REQUEST
-        + "--batch_1740-bb84-2f7f--";
-    final BatchParser parser = new BatchParser();
 
     try {
-      parser.parseBatchRequest(StringUtil.toInputStream(batch), invalidContentType, SERVICE_ROOT, "", true);
+      BatchParserCommon.getBoundary(invalidContentType, 0);
       fail();
-    } catch (BatchException e) {
-      assertMessageKey(e, BatchException.MessageKeys.INVALID_CONTENT_TYPE);
+    } catch (BatchDeserializerException e) {
+      assertMessageKey(e, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE);
     }
   }
 
   @Test
-  public void testBoundaryParameterWithoutQuota() throws UnsupportedEncodingException {
+  public void testBoundaryParameterWithoutQuota() throws Exception {
     final String invalidContentType = "multipart/mixed;boundary=batch_1740-bb:84-2f7f";
-    final String batch = ""
-        + "--batch_1740-bb:84-2f7f" + CRLF
-        + GET_REQUEST
-        + "--batch_1740-bb:84-2f7f--";
-    final BatchParser parser = new BatchParser();
 
     try {
-      parser.parseBatchRequest(StringUtil.toInputStream(batch), invalidContentType, SERVICE_ROOT, "", true);
+      BatchParserCommon.getBoundary(invalidContentType, 0);
       fail();
-    } catch (BatchException e) {
-      assertMessageKey(e, BatchException.MessageKeys.INVALID_BOUNDARY);
+    } catch (BatchDeserializerException e) {
+      assertMessageKey(e, BatchDeserializerException.MessageKeys.INVALID_BOUNDARY);
     }
   }
 
   @Test
-  public void testWrongBoundaryString() throws BatchException, UnsupportedEncodingException {
+  public void testWrongBoundaryString() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f5" + CRLF
         + GET_REQUEST
@@ -281,7 +261,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testMissingHttpVersion() throws UnsupportedEncodingException {
+  public void testMissingHttpVersion() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: application/http" + CRLF
@@ -293,11 +273,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_STATUS_LINE);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE);
   }
 
   @Test
-  public void testMissingHttpVersion2() throws UnsupportedEncodingException {
+  public void testMissingHttpVersion2() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: application/http" + CRLF
@@ -309,11 +289,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_HTTP_VERSION);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_HTTP_VERSION);
   }
 
   @Test
-  public void testMissingHttpVersion3() throws UnsupportedEncodingException {
+  public void testMissingHttpVersion3() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: application/http" + CRLF
@@ -325,11 +305,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_HTTP_VERSION);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_HTTP_VERSION);
   }
 
   @Test
-  public void testBoundaryWithoutHyphen() throws UnsupportedEncodingException {
+  public void testBoundaryWithoutHyphen() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + GET_REQUEST
@@ -337,11 +317,11 @@ public class BatchRequestParserTest {
         + GET_REQUEST
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_CONTENT);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT);
   }
 
   @Test
-  public void testNoBoundaryString() throws UnsupportedEncodingException {
+  public void testNoBoundaryString() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + GET_REQUEST
@@ -349,11 +329,11 @@ public class BatchRequestParserTest {
         + GET_REQUEST
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_CONTENT);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT);
   }
 
   @Test
-  public void testBatchBoundaryEqualsChangeSetBoundary() throws UnsupportedEncodingException {
+  public void testBatchBoundaryEqualsChangeSetBoundary() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed;boundary=batch_8194-cf13-1f56" + CRLF
@@ -372,11 +352,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_BLANK_LINE);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE);
   }
 
   @Test
-  public void testNoContentType() throws UnsupportedEncodingException {
+  public void testNoContentType() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
@@ -385,11 +365,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_CONTENT_TYPE);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE);
   }
 
   @Test
-  public void testMimeHeaderContentType() throws UnsupportedEncodingException {
+  public void testMimeHeaderContentType() throws Exception {
     final String batch = "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: text/plain" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
@@ -399,11 +379,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_CONTENT_TYPE);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE);
   }
 
   @Test
-  public void testMimeHeaderEncoding() throws UnsupportedEncodingException {
+  public void testMimeHeaderEncoding() throws Exception {
     String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: application/http" + CRLF
@@ -414,11 +394,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TRANSFER_ENCODING);
   }
 
   @Test
-  public void testGetRequestMissingCRLF() throws UnsupportedEncodingException {
+  public void testGetRequestMissingCRLF() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -429,11 +409,11 @@ public class BatchRequestParserTest {
         + CRLF // Belongs to the
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_BLANK_LINE);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE);
   }
 
   @Test
-  public void testInvalidMethodForBatch() throws UnsupportedEncodingException {
+  public void testInvalidMethodForBatch() throws Exception {
     final String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
         + CRLF
@@ -442,22 +422,22 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_QUERY_OPERATION_METHOD);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_QUERY_OPERATION_METHOD);
   }
 
   @Test
-  public void testNoBoundaryFound() throws UnsupportedEncodingException {
+  public void testNoBoundaryFound() throws Exception {
     final String batch = "batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
         + CRLF
         + "POST Employees('1')/EmployeeName HTTP/1.1" + CRLF
         + CRLF;
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_CLOSE_DELIMITER);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
   }
 
   @Test
-  public void testEmptyRequest() throws BatchException, UnsupportedEncodingException {
+  public void testEmptyRequest() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56--";
 
@@ -466,14 +446,14 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testBadRequest() throws UnsupportedEncodingException {
+  public void testBadRequest() throws Exception {
     final String batch = "This is a bad request. There is no syntax and also no semantic";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_CLOSE_DELIMITER);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
   }
 
   @Test
-  public void testNoMethod() throws UnsupportedEncodingException {
+  public void testNoMethod() throws Exception {
     final String batch = "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
         + CRLF
@@ -482,11 +462,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_STATUS_LINE);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE);
   }
 
   @Test
-  public void testInvalidMethodForChangeset() throws UnsupportedEncodingException {
+  public void testInvalidMethodForChangeset() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -504,11 +484,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_CHANGESET_METHOD);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CHANGESET_METHOD);
   }
 
   @Test
-  public void testInvalidChangeSetBoundary() throws UnsupportedEncodingException, BatchException {
+  public void testInvalidChangeSetBoundary() throws Exception {
     final String batch = "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
         + CRLF
@@ -532,7 +512,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testNestedChangeset() throws UnsupportedEncodingException {
+  public void testNestedChangeset() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -556,11 +536,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_CONTENT_TYPE);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_TYPE);
   }
 
   @Test
-  public void testMissingContentTransferEncoding() throws UnsupportedEncodingException {
+  public void testMissingContentTransferEncoding() throws Exception {
     final String batch = "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
         + CRLF
@@ -577,11 +557,11 @@ public class BatchRequestParserTest {
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_CONTENT_TRANSFER_ENCODING);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TRANSFER_ENCODING);
   }
 
   @Test
-  public void testMissingContentType() throws UnsupportedEncodingException {
+  public void testMissingContentType() throws Exception {
     final String batch = "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_f980-1cb6-94dd" + CRLF
         + CRLF
@@ -598,31 +578,31 @@ public class BatchRequestParserTest {
         + "--changeset_f980-1cb6-94dd--" + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_CONTENT_TYPE);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE);
   }
 
   @Test
-  public void testNoCloseDelimiter() throws BatchException, UnsupportedEncodingException {
+  public void testNoCloseDelimiter() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + GET_REQUEST;
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_CLOSE_DELIMITER);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
   }
 
   @Test
-  public void testNoCloseDelimiter2() throws BatchException, UnsupportedEncodingException {
+  public void testNoCloseDelimiter2() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
         + CRLF
         + "GET Employees('1')/EmployeeName HTTP/1.1" + CRLF;
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_CLOSE_DELIMITER);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
   }
 
   @Test
-  public void testInvalidUri() throws UnsupportedEncodingException {
+  public void testInvalidUri() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -632,11 +612,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_URI);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_URI);
   }
 
   @Test
-  public void testUriWithAbsolutePath() throws BatchException, UnsupportedEncodingException {
+  public void testUriWithAbsolutePath() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -661,7 +641,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testUriWithAbsolutePathMissingHostHeader() throws BatchException, UnsupportedEncodingException {
+  public void testUriWithAbsolutePathMissingHostHeader() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -675,7 +655,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testUriWithAbsolutePathMissingHostDulpicatedHeader() throws BatchException, UnsupportedEncodingException {
+  public void testUriWithAbsolutePathMissingHostDulpicatedHeader() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -691,7 +671,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testUriWithAbsolutePathOtherHost() throws BatchException, UnsupportedEncodingException {
+  public void testUriWithAbsolutePathOtherHost() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -706,7 +686,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testUriWithAbsolutePathWrongPath() throws BatchException, UnsupportedEncodingException {
+  public void testUriWithAbsolutePathWrongPath() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -721,14 +701,14 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testNoCloseDelimiter3() throws UnsupportedEncodingException {
+  public void testNoCloseDelimiter3() throws Exception {
     final String batch = "--batch_8194-cf13-1f56" + CRLF + GET_REQUEST + "--batch_8194-cf13-1f56-"/* no hyphen */;
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.MISSING_CLOSE_DELIMITER);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CLOSE_DELIMITER);
   }
 
   @Test
-  public void testNegativeContentLengthChangeSet() throws BatchException, IOException {
+  public void testNegativeContentLengthChangeSet() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -751,7 +731,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testNegativeContentLengthRequest() throws BatchException, IOException {
+  public void testNegativeContentLengthRequest() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -774,7 +754,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testContentLengthGreatherThanBodyLength() throws BatchException, IOException {
+  public void testContentLengthGreatherThanBodyLength() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -806,7 +786,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testContentLengthSmallerThanBodyLength() throws BatchException, IOException {
+  public void testContentLengthSmallerThanBodyLength() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -838,7 +818,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testNonNumericContentLength() throws UnsupportedEncodingException {
+  public void testNonNumericContentLength() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -856,11 +836,11 @@ public class BatchRequestParserTest {
         + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_HEADER);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_HEADER);
   }
 
   @Test
-  public void testNonStrictParser() throws BatchException, IOException {
+  public void testNonStrictParser() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_8194-cf13-1f56" + CRLF
@@ -893,7 +873,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testNonStrictParserMoreCRLF() throws UnsupportedEncodingException {
+  public void testNonStrictParserMoreCRLF() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed;boundary=changeset_8194-cf13-1f56" + CRLF
@@ -909,11 +889,11 @@ public class BatchRequestParserTest {
         + "--changeset_8194-cf13-1f56--" + CRLF
         + "--batch_8194-cf13-1f56--";
 
-    parseInvalidBatchBody(batch, BatchException.MessageKeys.INVALID_STATUS_LINE, false);
+    parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE, false);
   }
 
   @Test
-  public void testContentId() throws BatchException, UnsupportedEncodingException {
+  public void testContentId() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -970,7 +950,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testNoContentId() throws BatchException, UnsupportedEncodingException {
+  public void testNoContentId() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -1006,7 +986,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testPreamble() throws BatchException, IOException {
+  public void testPreamble() throws Exception {
     final String batch = ""
         + "This is a preamble and must be ignored" + CRLF
         + CRLF
@@ -1068,7 +1048,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testContentTypeCaseInsensitive() throws BatchException, IOException {
+  public void testContentTypeCaseInsensitive() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: muLTiParT/mixed; boundary=changeset_f980-1cb6-94dd" + CRLF
@@ -1090,7 +1070,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testContentTypeBoundaryCaseInsensitive() throws BatchException, IOException {
+  public void testContentTypeBoundaryCaseInsensitive() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + "Content-Type: multipart/mixed; bOunDaRy=changeset_f980-1cb6-94dd" + CRLF
@@ -1115,7 +1095,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testEpilog() throws BatchException, IOException {
+  public void testEpilog() throws Exception {
     String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -1178,13 +1158,13 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testLargeBatch() throws BatchException, IOException {
+  public void testLargeBatch() throws Exception {
     final InputStream in = readFile("/batchLarge.batch");
     parse(in);
   }
 
   @Test
-  public void testForddenHeaderAuthorisation() throws UnsupportedEncodingException {
+  public void testForddenHeaderAuthorisation() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -1199,7 +1179,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testForddenHeaderExpect() throws UnsupportedEncodingException {
+  public void testForddenHeaderExpect() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -1214,7 +1194,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testForddenHeaderFrom() throws UnsupportedEncodingException {
+  public void testForddenHeaderFrom() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -1229,7 +1209,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testForddenHeaderRange() throws UnsupportedEncodingException {
+  public void testForddenHeaderRange() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -1244,7 +1224,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testForddenHeaderMaxForwards() throws UnsupportedEncodingException {
+  public void testForddenHeaderMaxForwards() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -1259,7 +1239,7 @@ public class BatchRequestParserTest {
   }
 
   @Test
-  public void testForddenHeaderTE() throws UnsupportedEncodingException {
+  public void testForddenHeaderTE() throws Exception {
     final String batch = ""
         + "--batch_8194-cf13-1f56" + CRLF
         + MIME_HEADERS
@@ -1273,50 +1253,50 @@ public class BatchRequestParserTest {
     parseInvalidBatchBody(batch, MessageKeys.FORBIDDEN_HEADER);
   }
 
-  private List<BatchRequestPart> parse(final InputStream in, final boolean isStrict) throws BatchException {
+  private List<BatchRequestPart> parse(final InputStream in, final boolean isStrict) throws Exception {
     final BatchParser parser = new BatchParser();
+    final BatchOptions options = BatchOptions.with().isStrict(isStrict).rawBaseUri(SERVICE_ROOT).build();
     final List<BatchRequestPart> batchRequestParts =
-        parser.parseBatchRequest(in, CONTENT_TYPE, SERVICE_ROOT, "", isStrict);
+        parser.parseBatchRequest(in, BOUNDARY, options);
 
     assertNotNull(batchRequestParts);
 
     return batchRequestParts;
   }
 
-  private List<BatchRequestPart> parse(final InputStream in) throws BatchException {
+  private List<BatchRequestPart> parse(final InputStream in) throws Exception {
     return parse(in, true);
   }
 
-  private List<BatchRequestPart> parse(final String batch) throws BatchException, UnsupportedEncodingException {
+  private List<BatchRequestPart> parse(final String batch) throws Exception {
     return parse(batch, true);
   }
 
-  private List<BatchRequestPart> parse(final String batch, final boolean isStrict) throws BatchException,
-      UnsupportedEncodingException {
+  private List<BatchRequestPart> parse(final String batch, final boolean isStrict) throws Exception {
     return parse(StringUtil.toInputStream(batch), isStrict);
   }
 
   private void parseInvalidBatchBody(final String batch, final MessageKeys key, final boolean isStrict)
-      throws UnsupportedEncodingException {
+      throws Exception {
     final BatchParser parser = new BatchParser();
-
+    final BatchOptions options = BatchOptions.with().isStrict(isStrict).rawBaseUri(SERVICE_ROOT).build();
     try {
-      parser.parseBatchRequest(StringUtil.toInputStream(batch), CONTENT_TYPE, SERVICE_ROOT, "", isStrict);
+      parser.parseBatchRequest(StringUtil.toInputStream(batch), BOUNDARY, options);
       fail("No exception thrown. Expect: " + key.toString());
-    } catch (BatchException e) {
+    } catch (BatchDeserializerException e) {
       assertMessageKey(e, key);
     }
   }
 
-  private void parseInvalidBatchBody(final String batch, final MessageKeys key) throws UnsupportedEncodingException {
+  private void parseInvalidBatchBody(final String batch, final MessageKeys key) throws Exception {
     parseInvalidBatchBody(batch, key, true);
   }
 
-  private void assertMessageKey(final BatchException e, final MessageKeys key) {
+  private void assertMessageKey(final BatchDeserializerException e, final MessageKeys key) {
     assertEquals(key, e.getMessageKey());
   }
 
-  private InputStream readFile(final String fileName) throws IOException {
+  private InputStream readFile(final String fileName) throws Exception {
     final InputStream in = ClassLoader.class.getResourceAsStream(fileName);
     if (in == null) {
       throw new IOException("Requested file '" + fileName + "' was not found.");