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/20 16:58:21 UTC

olingo-odata4 git commit: [OLINGO-472] IOExceptions, ChangeSetSorter removed

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


[OLINGO-472] IOExceptions, ChangeSetSorter removed

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/402e847a
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/402e847a
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/402e847a

Branch: refs/heads/master
Commit: 402e847a8ca22aa9d64f097a90e0f87709e921a1
Parents: 51acf8a
Author: Christian Holzer <c....@sap.com>
Authored: Thu Nov 20 16:47:08 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Nov 20 16:51:04 2014 +0100

----------------------------------------------------------------------
 .../api/serializer/FixedFormatSerializer.java   |   6 +-
 .../core/batchhandler/BatchChangeSetSorter.java | 156 ------------------
 .../server/core/batchhandler/BatchHandler.java  |   2 +-
 .../core/batchhandler/BatchPartHandler.java     |  90 ++--------
 .../BatchReferenceRewriter.java                 | 116 +++++++++++++
 .../referenceRewriting/UriMapping.java          |  34 ++++
 .../serializer/BatchResponseSerializer.java     |  72 ++++----
 .../serializer/FixedFormatSerializerImpl.java   |   4 +-
 .../batchhandler/BatchChangeSetSorterTest.java  | 165 -------------------
 .../batchhandler/MockedBatchHandlerTest.java    |  94 +++++------
 .../processor/TechnicalBatchProcessor.java      |  30 ++--
 11 files changed, 265 insertions(+), 504 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/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 b711651..35780ed 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
@@ -18,7 +18,6 @@
  */
 package org.apache.olingo.server.api.serializer;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
@@ -52,7 +51,6 @@ public interface FixedFormatSerializer {
       throws SerializerException;
 
   // TODO: Document
-  // TODO: Delete IOException
-  void writeResponseParts(List<ODataResponsePart> batchResponses, ODataResponse response) throws BatchException,
-      IOException;
+  // TODO: Return type
+  void writeResponseParts(List<ODataResponsePart> batchResponses, ODataResponse response) throws BatchException;
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchChangeSetSorter.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchChangeSetSorter.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchChangeSetSorter.java
deleted file mode 100644
index 6c63606..0000000
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchChangeSetSorter.java
+++ /dev/null
@@ -1,156 +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 java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-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.core.deserializer.batch.BatchParserCommon;
-
-public class BatchChangeSetSorter {
-  private static final String REG_EX_REFERENCE = "\\$(.*)(/.*)?";
-
-  final List<ODataRequest> orderdList = new ArrayList<ODataRequest>();
-
-  private static Pattern referencePattern = Pattern.compile(REG_EX_REFERENCE);
-  private Set<String> knownContentIds = new HashSet<String>();
-  private Map<String, List<ODataRequest>> requestReferenceMapping = new HashMap<String, List<ODataRequest>>();
-
-  public BatchChangeSetSorter(List<ODataRequest> requests) throws BatchException {
-    sort(requests);
-  }
-
-  public List<ODataRequest> getOrderdRequests() {
-    return orderdList;
-  }
-
-  private List<ODataRequest> sort(final List<ODataRequest> requests) throws BatchException {
-    extractUrlReference(requests);
-    
-    // Add requests without reference (roots)
-    final List<ODataRequest> requestsWithoutReferences = getRequestsWithoutReferences();
-    orderdList.addAll(requestsWithoutReferences);
-    addRequestsToKnownContentIds(requestsWithoutReferences);
-    
-    // Find all requests which can be processed (parent request has been processed)
-    // Compare level order
-    boolean areRequestsProcessed = true;
-    while (requestsToProcessAvailable() && areRequestsProcessed) {
-      areRequestsProcessed = processNextLevel();
-    }
-
-    // Check if there are some requests which are not connected to a tree
-    if (requestsToProcessAvailable()) {
-      throw new BatchException("Invalid content id", MessageKeys.INVALID_CONTENT_ID, 0);
-    }
-
-    return orderdList;
-  }
-
-  private boolean requestsToProcessAvailable() {
-    return requestReferenceMapping.keySet().size() != 0;
-  }
-
-  private boolean processNextLevel() {
-    final List<ODataRequest> addedRequests = getRemainingRequestsWithKownContentId();
-    addRequestsToKnownContentIds(addedRequests);
-    orderdList.addAll(addedRequests);
-
-    return addedRequests.size() != 0;
-  }
-
-  private List<ODataRequest> getRemainingRequestsWithKownContentId() {
-    List<ODataRequest> result = new ArrayList<ODataRequest>();
-
-    for (String contextId : knownContentIds) {
-      final List<ODataRequest> requestsToProcess = requestReferenceMapping.get(contextId);
-      if (requestsToProcess != null && requestsToProcess.size() != 0) {
-        result.addAll(requestsToProcess);
-        requestReferenceMapping.remove(contextId);
-      }
-    }
-
-    return result;
-  }
-
-  private List<ODataRequest> getRequestsWithoutReferences() {
-    List<ODataRequest> requests = requestReferenceMapping.get(null);
-    requestReferenceMapping.remove(null);
-    
-    requests = (requests == null) ? new ArrayList<ODataRequest>() : requests;
-    return requests;
-  }
-
-  private void addRequestsToKnownContentIds(List<ODataRequest> requestsWithoutReference) {
-    for (ODataRequest request : requestsWithoutReference) {
-      final String contentId = getContentIdFromHeader(request);
-      if (contentId != null) {
-        knownContentIds.add(contentId);
-      }
-    }
-  }
-
-  private String getContentIdFromHeader(ODataRequest request) {
-    return request.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
-  }
-
-  private void extractUrlReference(List<ODataRequest> requests) {
-    for (ODataRequest request : requests) {
-      final String reference = getReferenceInURI(request);
-      addRequestToReferenceMapping(reference, request);
-    }
-  }
-
-  private void addRequestToReferenceMapping(final String reference, final ODataRequest request) {
-    List<ODataRequest> requestList = requestReferenceMapping.get(reference);
-    requestList = (requestList == null) ? new ArrayList<ODataRequest>() : requestList;
-
-    requestList.add(request);
-    requestReferenceMapping.put(reference, requestList);
-  }
-
-  public static String getReferenceInURI(ODataRequest request) {
-    Matcher matcher = referencePattern.matcher(removeSlash(removeSlash(request.getRawODataPath(), true), false));
-    return (matcher.matches()) ? matcher.group(1) : null;
-  }
-
-  private static String removeSlash(String rawODataPath, boolean first) {
-    final int indexOfSlash = rawODataPath.indexOf("/");
-    if(first) {
-      return (indexOfSlash == 0) ? rawODataPath.substring(1) : rawODataPath;
-    } else {
-      return (indexOfSlash != -1) ? rawODataPath.substring(0, indexOfSlash) : rawODataPath;
-    }
-  }
-
-  public static void replaceContentIdReference(ODataRequest request, String contentId, String resourceUri) {
-    final String newUri = request.getRawODataPath().replace("/$" + contentId, resourceUri);
-    request.setRawODataPath(newUri);
-    request.setRawRequestUri(request.getRawBaseUri() + "/" + newUri);
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/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 35c7d63..9b3ece1 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
@@ -33,7 +33,7 @@ import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
 public class BatchHandler {
   private final BatchProcessor batchProcessor;
   private final ODataHandler oDataHandler;
-
+  
   public BatchHandler(final ODataHandler oDataHandler, final BatchProcessor batchProcessor) {
 
     this.batchProcessor = batchProcessor;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/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 71b5870..734dfb4 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchPartHandler.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchPartHandler.java
@@ -18,12 +18,6 @@
  */
 package org.apache.olingo.server.core.batchhandler;
 
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.olingo.commons.api.ODataRuntimeException;
-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;
@@ -32,36 +26,32 @@ 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;
+import org.apache.olingo.server.core.batchhandler.referenceRewriting.BatchReferenceRewriter;
 import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
-import org.apache.olingo.server.core.deserializer.batch.HttpRequestStatusLine.ODataURI;
 
 public class BatchPartHandler {
-
-  private ODataHandler oDataHandler;
-  private BatchProcessor batchProcessor;
-  private BatchFacade batchOperation;
-  private Map<BatchRequestPart, UriMapping> uriMapping = new HashMap<BatchRequestPart, UriMapping>();
-
+  private final ODataHandler oDataHandler;
+  private final BatchProcessor batchProcessor;
+  private final BatchFacade batchOperation;
+  private final BatchReferenceRewriter rewriter;
+  
   public BatchPartHandler(final ODataHandler oDataHandler, final BatchProcessor processor,
       final BatchFacade batchOperation) {
     this.oDataHandler = oDataHandler;
     this.batchProcessor = processor;
     this.batchOperation = batchOperation;
+    rewriter = new BatchReferenceRewriter();
   }
 
   public ODataResponse handleODataRequest(ODataRequest request, BatchRequestPart requestPart) throws BatchException {
     final ODataResponse response;
 
     if (requestPart.isChangeSet()) {
-      final UriMapping mapping = replaceReference(request, requestPart);
+      rewriter.replaceReference(request, requestPart);
 
       response = oDataHandler.process(request);
-
-      // Store resource URI
-      final String resourceUri = getODataPath(request, response);
-      final String contentId = request.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
-
-      mapping.addMapping(contentId, resourceUri);
+      
+      rewriter.addMapping(request, response, requestPart);
     } else {
       response = oDataHandler.process(request);
     }
@@ -75,51 +65,6 @@ public class BatchPartHandler {
     return response;
   }
 
-  private String getODataPath(ODataRequest request, ODataResponse response) throws BatchException {
-    String resourceUri = null;
-
-    if (request.getMethod() == HttpMethod.POST) {
-      // Create entity
-      // The URI of the new resource will be generated by the server and published in the location header
-      ODataURI uri = new ODataURI(response.getHeaders().get(HttpHeader.LOCATION), request.getRawBaseUri());
-      resourceUri = uri.getRawODataPath();
-    } else {
-      // Update, Upsert (PUT, PATCH, Delete)
-      // These methods still addresses a given resource, so we use the URI given by the request
-      resourceUri = request.getRawODataPath();
-    }
-
-    return resourceUri;
-  }
-
-  private UriMapping replaceReference(ODataRequest request, BatchRequestPart requestPart) {
-    final UriMapping mapping = getUriMappingOrDefault(requestPart);
-    final String reference = BatchChangeSetSorter.getReferenceInURI(request);
-
-    if (reference != null) {
-      final String replacement = mapping.getUri(reference);
-
-      if (replacement != null) {
-        BatchChangeSetSorter.replaceContentIdReference(request, reference, replacement);
-      } else {
-        throw new ODataRuntimeException("Required Content-Id for reference \"" + reference + "\" not found.");
-      }
-    }
-
-    return mapping;
-  }
-
-  private UriMapping getUriMappingOrDefault(final BatchRequestPart requestPart) {
-    UriMapping mapping = uriMapping.get(requestPart);
-
-    if (mapping == null) {
-      mapping = new UriMapping();
-    }
-    uriMapping.put(requestPart, mapping);
-
-    return mapping;
-  }
-
   public ODataResponsePart handleBatchRequest(BatchRequestPart request) throws BatchException {
     if (request.isChangeSet()) {
       return handleChangeSet(request);
@@ -131,20 +76,7 @@ public class BatchPartHandler {
   }
 
   private ODataResponsePart handleChangeSet(BatchRequestPart request) throws BatchException {
-    final BatchChangeSetSorter sorter = new BatchChangeSetSorter(request.getRequests());
-
-    return batchProcessor.executeChangeSet(batchOperation, sorter.getOrderdRequests(), request);
+    return batchProcessor.executeChangeSet(batchOperation, request.getRequests(), request);
   }
 
-  private static class UriMapping {
-    private Map<String, String> uriMapping = new HashMap<String, String>();
-
-    public void addMapping(final String contentId, final String uri) {
-      uriMapping.put(contentId, uri);
-    }
-
-    public String getUri(final String contentId) {
-      return uriMapping.get(contentId);
-    }
-  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/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
new file mode 100644
index 0000000..2acf45c
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/BatchReferenceRewriter.java
@@ -0,0 +1,116 @@
+/*
+ * 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.referenceRewriting;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.olingo.commons.api.ODataRuntimeException;
+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.deserializer.batch.BatchRequestPart;
+import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
+import org.apache.olingo.server.core.deserializer.batch.HttpRequestStatusLine.ODataURI;
+
+public class BatchReferenceRewriter {
+  private static final String REG_EX_REFERENCE = "\\$(.*)(/.*)?";
+  private static final Pattern REFERENCE_PATTERN = Pattern.compile(REG_EX_REFERENCE);
+
+  private Map<BatchRequestPart, UriMapping> uriMapping = new HashMap<BatchRequestPart, UriMapping>();
+
+  public String getReferenceInURI(ODataRequest request) {
+    Matcher matcher = REFERENCE_PATTERN.matcher(removeSlash(removeSlash(request.getRawODataPath(), true), false));
+
+    return (matcher.matches()) ? matcher.group(1) : null;
+  }
+
+  public void replaceContentIdReference(ODataRequest request, String contentId, String resourceUri) {
+    final String newUri = request.getRawODataPath().replace("/$" + contentId, resourceUri);
+    request.setRawODataPath(newUri);
+    request.setRawRequestUri(request.getRawBaseUri() + "/" + newUri);
+  }
+
+  public UriMapping replaceReference(ODataRequest request, BatchRequestPart requestPart) {
+    final UriMapping mapping = getUriMappingOrDefault(requestPart);
+    final String reference = getReferenceInURI(request);
+
+    if (reference != null) {
+      final String replacement = mapping.getUri(reference);
+
+      if (replacement != null) {
+        replaceContentIdReference(request, reference, replacement);
+      } else {
+        throw new ODataRuntimeException("Required Content-Id for reference \"" + reference + "\" not found.");
+      }
+    }
+
+    return mapping;
+  }
+
+  private UriMapping getUriMappingOrDefault(final BatchRequestPart requestPart) {
+    UriMapping mapping = uriMapping.get(requestPart);
+
+    if (mapping == null) {
+      mapping = new UriMapping();
+    }
+    uriMapping.put(requestPart, mapping);
+
+    return mapping;
+  }
+
+  public void addMapping(ODataRequest request, ODataResponse response, BatchRequestPart requestPart)
+      throws BatchException {
+    final UriMapping mapping = getUriMappingOrDefault(requestPart);
+    final String resourceUri = getODataPath(request, response);
+    final String contentId = request.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
+
+    mapping.addMapping(contentId, resourceUri);
+  }
+  
+  private String getODataPath(ODataRequest request, ODataResponse response) throws BatchException {
+    String resourceUri = null;
+
+    if (request.getMethod() == HttpMethod.POST) {
+      // Create entity
+      // The URI of the new resource will be generated by the server and published in the location header
+      ODataURI uri = new ODataURI(response.getHeaders().get(HttpHeader.LOCATION), request.getRawBaseUri());
+      resourceUri = uri.getRawODataPath();
+    } else {
+      // Update, Upsert (PUT, PATCH, Delete)
+      // These methods still addresses a given resource, so we use the URI given by the request
+      resourceUri = request.getRawODataPath();
+    }
+
+    return resourceUri;
+  }
+  
+  private String removeSlash(String rawODataPath, boolean first) {
+    final int indexOfSlash = rawODataPath.indexOf("/");
+    if (first) {
+      return (indexOfSlash == 0) ? rawODataPath.substring(1) : rawODataPath;
+    } else {
+      return (indexOfSlash != -1) ? rawODataPath.substring(0, indexOfSlash) : rawODataPath;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/UriMapping.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/UriMapping.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/UriMapping.java
new file mode 100644
index 0000000..76ee215
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/referenceRewriting/UriMapping.java
@@ -0,0 +1,34 @@
+/*
+ * 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.referenceRewriting;
+
+import java.util.HashMap;
+import java.util.Map;
+
+class UriMapping {
+  private Map<String, String> uriMapping = new HashMap<String, String>();
+
+  public void addMapping(final String contentId, final String uri) {
+    uriMapping.put(contentId, uri);
+  }
+
+  public String getUri(final String contentId) {
+    return uriMapping.get(contentId);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/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 6f7255c..81872a3 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
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.olingo.commons.api.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpContentType;
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
@@ -45,7 +46,7 @@ public class BatchResponseSerializer {
   private static final String CRLF = "\r\n";
 
   public void toODataResponse(final List<ODataResponsePart> batchResponse, final ODataResponse response)
-      throws IOException, BatchException {
+      throws BatchException {
     final String boundary = generateBoundary("batch");
 
     setStatusCode(response);
@@ -56,7 +57,7 @@ public class BatchResponseSerializer {
   }
 
   private ResponseWriter createBody(final List<ODataResponsePart> batchResponses, final String boundary)
-      throws IOException, BatchException {
+      throws BatchException {
     final ResponseWriter writer = new ResponseWriter();
 
     for (final ODataResponsePart part : batchResponses) {
@@ -73,7 +74,7 @@ public class BatchResponseSerializer {
     return writer;
   }
 
-  private void appendChangeSet(ODataResponsePart part, ResponseWriter writer) throws IOException, BatchException {
+  private void appendChangeSet(ODataResponsePart part, ResponseWriter writer) throws BatchException {
     final String changeSetBoundary = generateBoundary("changeset");
 
     appendChangeSetHeader(writer, changeSetBoundary);
@@ -88,10 +89,10 @@ public class BatchResponseSerializer {
     writer.append(CRLF);
   }
 
-  private void appendBodyPart(ODataResponse response, ResponseWriter writer, boolean isChangeSet) throws IOException,
-      BatchException {
+  private void appendBodyPart(ODataResponse response, ResponseWriter writer, boolean isChangeSet) 
+      throws BatchException {
     byte[] body = getBody(response);
-    
+
     appendBodyPartHeader(response, writer, isChangeSet);
     writer.append(CRLF);
 
@@ -103,31 +104,35 @@ public class BatchResponseSerializer {
     writer.append(CRLF);
   }
 
-  private byte[] getBody(final ODataResponse response) throws IOException {
+  private byte[] getBody(final ODataResponse response) {
     final InputStream content = response.getContent();
     final ByteArrayOutputStream out = new ByteArrayOutputStream();
-    
+
     if (content != null) {
       byte[] buffer = new byte[BUFFER_SIZE];
       int n;
 
-      while ((n = content.read(buffer, 0, buffer.length)) != -1) {
-        out.write(buffer, 0, n);
+      try {
+        while ((n = content.read(buffer, 0, buffer.length)) != -1) {
+          out.write(buffer, 0, n);
+          out.flush();
+        }
+      } catch (IOException e) {
+        throw new ODataRuntimeException(e);
       }
-      out.flush();
-      
+
       return out.toByteArray();
     } else {
       return new byte[0];
     }
   }
 
-  private void appendChangeSetHeader(ResponseWriter writer, final String changeSetBoundary) throws IOException {
+  private void appendChangeSetHeader(ResponseWriter writer, final String changeSetBoundary) {
     appendHeader(HttpHeader.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED.toString() + "; boundary="
         + changeSetBoundary, writer);
   }
 
-  private void appendHeader(String name, String value, ResponseWriter writer) throws IOException {
+  private void appendHeader(String name, String value, ResponseWriter writer) {
     writer.append(name)
         .append(COLON)
         .append(SP)
@@ -135,7 +140,7 @@ public class BatchResponseSerializer {
         .append(CRLF);
   }
 
-  private void appendStatusLine(ODataResponse response, ResponseWriter writer) throws IOException {
+  private void appendStatusLine(ODataResponse response, ResponseWriter writer) {
     writer.append("HTTP/1.1")
         .append(SP)
         .append("" + response.getStatusCode())
@@ -144,8 +149,7 @@ public class BatchResponseSerializer {
         .append(CRLF);
   }
 
-  private void appendResponseHeader(ODataResponse response, int contentLength, ResponseWriter writer)
-      throws IOException {
+  private void appendResponseHeader(ODataResponse response, int contentLength, ResponseWriter writer) {
     final Map<String, String> header = response.getHeaders();
 
     for (final String key : header.keySet()) {
@@ -159,7 +163,7 @@ public class BatchResponseSerializer {
   }
 
   private void appendBodyPartHeader(ODataResponse response, ResponseWriter writer, boolean isChangeSet)
-      throws BatchException, IOException {
+      throws BatchException {
     appendHeader(HttpHeader.CONTENT_TYPE, HttpContentType.APPLICATION_HTTP, writer);
     appendHeader(BatchParserCommon.HTTP_CONTENT_TRANSFER_ENCODING, BatchParserCommon.BINARY_ENCODING, writer);
 
@@ -199,18 +203,26 @@ public class BatchResponseSerializer {
     private BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream()));
     private int length = 0;
 
-    public ResponseWriter append(final String content) throws IOException {
+    public ResponseWriter append(final String content) {
       length += content.length();
-      writer.write(content);
-      
+      try {
+        writer.write(content);
+      } catch (IOException e) {
+        throw new ODataRuntimeException(e);
+      }
+
       return this;
     }
 
-    public ResponseWriter append(final byte[] content) throws IOException {
+    public ResponseWriter append(final byte[] content) {
       length += content.length;
-      writer.flush();
-      buffer.getOutputStream().write(content, 0, content.length);
-      
+      try {
+        writer.flush();
+        buffer.getOutputStream().write(content, 0, content.length);
+      } catch (IOException e) {
+        throw new ODataRuntimeException(e);
+      }
+
       return this;
     }
 
@@ -218,9 +230,13 @@ public class BatchResponseSerializer {
       return length;
     }
 
-    public InputStream toInputStream() throws IOException {
-      writer.flush();
-      writer.close();
+    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/402e847a/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 e165b75..5b7ba78 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
@@ -19,7 +19,6 @@
 package org.apache.olingo.server.core.serializer;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
@@ -64,8 +63,7 @@ public class FixedFormatSerializerImpl implements FixedFormatSerializer {
 
   //TODO: Signature
   @Override
-  public void writeResponseParts(List<ODataResponsePart> batchResponses, ODataResponse response) throws BatchException,
-      IOException {
+  public void writeResponseParts(List<ODataResponsePart> batchResponses, ODataResponse response) throws BatchException {
     BatchResponseSerializer writer = new BatchResponseSerializer();
     writer.toODataResponse(batchResponses, response);
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/BatchChangeSetSorterTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/BatchChangeSetSorterTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/BatchChangeSetSorterTest.java
deleted file mode 100644
index 7b73e43..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/batchhandler/BatchChangeSetSorterTest.java
+++ /dev/null
@@ -1,165 +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 static org.junit.Assert.*;
-
-import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-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.core.batchhandler.BatchChangeSetSorter;
-import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon;
-import org.junit.Test;
-
-public class BatchChangeSetSorterTest {
-
-  private static final String BASE_URI = "http://localhost/odata.src";
-  
-  @Test
-  public void test() throws BatchException {
-    final List<ODataRequest> changeSet = new ArrayList<ODataRequest>();
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "$1/Adress", "2"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "/Employees", "1"));
-    
-   BatchChangeSetSorter sorter = new BatchChangeSetSorter(changeSet);
-   final List<ODataRequest> sortedChangeSet = sorter.getOrderdRequests();
-   
-   assertEquals(2, sortedChangeSet.size());
-   assertEquals("1", getContentId(sortedChangeSet.get(0)));
-   assertEquals("2", getContentId(sortedChangeSet.get(1)));
-  }
-  
-  private String getContentId(ODataRequest request) {
-    return request.getHeader(BatchParserCommon.HTTP_CONTENT_ID);
-  }
-  
-  @Test
-  public void testNoContentId() throws BatchException {
-    final List<ODataRequest> changeSet = new ArrayList<ODataRequest>();
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "$1/Department", "2"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employees", "1"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employee('2')/Address"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employee('3')/Address"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "$2/Manager", "3"));
-    
-    BatchChangeSetSorter sorter = new BatchChangeSetSorter(changeSet);
-   final List<ODataRequest> sortedChangeSet = sorter.getOrderdRequests();
-   
-   assertEquals(5, sortedChangeSet.size());
-   assertEquals("1", getContentId(sortedChangeSet.get(0)));
-   assertEquals(null, getContentId(sortedChangeSet.get(1)));
-   assertEquals(null, getContentId(sortedChangeSet.get(2)));
-   assertEquals("2", getContentId(sortedChangeSet.get(3)));
-   assertEquals("3", getContentId(sortedChangeSet.get(4)));
-  }
-  
-  @SuppressWarnings("unused")
-  @Test(expected=BatchException.class)
-  public void testContentIdNotAvailable() throws BatchException {
-    final List<ODataRequest> changeSet = new ArrayList<ODataRequest>();
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "$1/Department", "2"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employees", "1"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employee('2')/Address"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employee('3')/Address"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "$4/Manager", "3")); //4 is not available
-    
-   BatchChangeSetSorter sorter = new BatchChangeSetSorter(changeSet);
-   final List<ODataRequest> sortedChangeSet = sorter.getOrderdRequests();
-  }
-  
-  @Test
-  public void testStringAsContentId() throws BatchException {
-    final List<ODataRequest> changeSet = new ArrayList<ODataRequest>();
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "$One/Department", "Two"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employees", "One"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employee('2')/Address"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "Employee('3')/Address"));
-    changeSet.add(createRequest(HttpMethod.POST, BASE_URI, "$Two/Manager", "Three"));
-    
-   BatchChangeSetSorter sorter = new BatchChangeSetSorter(changeSet);
-   final List<ODataRequest> sortedChangeSet = sorter.getOrderdRequests();
-   
-   assertEquals(5, sortedChangeSet.size());
-   assertEquals("One", getContentId(sortedChangeSet.get(0)));
-   assertEquals(null, getContentId(sortedChangeSet.get(1)));
-   assertEquals(null, getContentId(sortedChangeSet.get(2)));
-   assertEquals("Two", getContentId(sortedChangeSet.get(3)));
-   assertEquals("Three", getContentId(sortedChangeSet.get(4)));
-  }
-  
-  @Test
-  public void testRewriting() {
-    final String CONTENT_ID = "1";
-    final String ODATA_PATH ="/$" + CONTENT_ID + "/Address";
-    final String RESOURCE_URI = "Employee('1')";
-    final ODataRequest request = createRequest(HttpMethod.POST, BASE_URI, ODATA_PATH);
-    
-    BatchChangeSetSorter.replaceContentIdReference(request, CONTENT_ID, RESOURCE_URI);
-    assertEquals(BASE_URI + "/" + "Employee('1')/Address", request.getRawRequestUri());
-    assertEquals("Employee('1')/Address", request.getRawODataPath());
-  }
-  
-  @Test
-  public void testRewritingNoContentId() {
-    final String CONTENT_ID = "1";
-    final String ODATA_PATH = /* "$" + CONTENT_ID + */ "Address";
-    final String RESOURCE_URI = "Employee('1')";
-    final ODataRequest request = createRequest(HttpMethod.POST, BASE_URI, ODATA_PATH);
-    
-    BatchChangeSetSorter.replaceContentIdReference(request, CONTENT_ID, RESOURCE_URI);
-    assertEquals(BASE_URI + "/" + "Address", request.getRawRequestUri());
-    assertEquals("Address", request.getRawODataPath());
-  }
-  
-  @Test
-  public void testWrongRewriting() {
-    final String CONTENT_ID = "1";
-    final String ODATA_PATH = /*"$1" */ "$2" + "/Address";
-    final String RESOURCE_URI = "Employee('1')";
-    final ODataRequest request = createRequest(HttpMethod.POST, BASE_URI, ODATA_PATH);
-    
-    BatchChangeSetSorter.replaceContentIdReference(request, CONTENT_ID, RESOURCE_URI);
-    assertEquals(BASE_URI + "/" + "$2/Address", request.getRawRequestUri());
-    assertEquals("$2/Address", request.getRawODataPath());
-  }
-  
-  private ODataRequest createRequest(HttpMethod method, String baseUrl, String oDataPath) {
-    return createRequest(method, baseUrl, oDataPath, null);
-  }
-  
-  private ODataRequest createRequest(HttpMethod method, String baseUrl, String oDataPath, String contentId) {
-    final ODataRequest request = new ODataRequest();
-    request.setBody(new ByteArrayInputStream(new byte[0]));
-    request.setMethod(HttpMethod.GET);
-    request.setRawBaseUri(baseUrl);
-    request.setRawODataPath(oDataPath);
-    request.setRawRequestUri(baseUrl + "/" + oDataPath);
-    request.setRawQueryPath("");
-    
-    if(contentId != null) {
-      request.addHeader(BatchParserCommon.HTTP_CONTENT_ID, Arrays.asList(new String[] { contentId }));
-    }
-    return request;
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/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 c814184..8976316 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,7 +21,6 @@ package org.apache.olingo.server.core.batchhandler;
 import static org.junit.Assert.*;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
@@ -30,7 +29,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.olingo.commons.api.ODataRuntimeException;
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpMethod;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
@@ -85,46 +83,46 @@ public class MockedBatchHandlerTest {
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 4" + CRLF
+        + "Content-Id: 3" + CRLF
         + CRLF
-        + "PUT /$3/PropertyInt32 HTTP/1.1" + CRLF // Absolute URI with separate Host header and ref.
-        + "Host: http://localhost:8080/odata" + CRLF
+        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF // Relative URI
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 5" + CRLF
+        + "Content-Id: 4" + CRLF
         + CRLF
-        + "POST http://localhost:8080/odata/$1/NavPropertyETTwoPrimMany HTTP/1.1" + CRLF // Absolute URI with ref.
+        + "PUT /$3/PropertyInt32 HTTP/1.1" + CRLF // Absolute URI with separate Host header and ref.
+        + "Host: http://localhost:8080/odata" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 2" + CRLF
+        + "Content-Id: 1" + CRLF
         + CRLF
-        + "POST $1/NavPropertyETTwoPrimMany HTTP/1.1" + CRLF // Relative URI with ref.
+        + "POST http://localhost:8080/odata/ESAllPrim HTTP/1.1" + CRLF // Absolute URI
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 1" + CRLF
+        + "Content-Id: 5" + CRLF
         + CRLF
-        + "POST http://localhost:8080/odata/ESAllPrim HTTP/1.1" + CRLF // Absolute URI
+        + "POST http://localhost:8080/odata/$1/NavPropertyETTwoPrimMany HTTP/1.1" + CRLF // Absolute URI with ref.
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 3" + CRLF
+        + "Content-Id: 2" + CRLF
         + CRLF
-        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF // Relative URI
+        + "POST $1/NavPropertyETTwoPrimMany HTTP/1.1" + CRLF // Relative URI with ref.
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
@@ -251,19 +249,19 @@ public class MockedBatchHandlerTest {
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 2" + CRLF
+        + "Content-Id: 1" + CRLF
         + CRLF
-        + "POST /$1/NavPropertyETTwoPrimMany HTTP/1.1" + CRLF
-        + "Host: http://localhost:8080/odata" + CRLF
+        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 1" + CRLF
+        + "Content-Id: 2" + CRLF
         + CRLF
-        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF
+        + "POST /$1/NavPropertyETTwoPrimMany HTTP/1.1" + CRLF
+        + "Host: http://localhost:8080/odata" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
@@ -275,19 +273,19 @@ public class MockedBatchHandlerTest {
         + "--changeset_54321" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 2" + CRLF
+        + "Content-Id: 1" + CRLF
         + CRLF
-        + "POST /$1/NavPropertyETTwoPrimMany HTTP/1.1" + CRLF
-        + "Host: http://localhost:8080/odata" + CRLF
+        + "PUT ESAllPrim(2) HTTP/1.1" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_54321" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 1" + CRLF
+        + "Content-Id: 2" + CRLF
         + CRLF
-        + "PUT ESAllPrim(2) HTTP/1.1" + CRLF
+        + "POST /$1/NavPropertyETTwoPrimMany HTTP/1.1" + CRLF
+        + "Host: http://localhost:8080/odata" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
@@ -377,9 +375,9 @@ public class MockedBatchHandlerTest {
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 4" + CRLF
+        + "Content-Id: 1" + CRLF
         + CRLF
-        + "POST $3/NavPropertyETTwoPrimOne HTTP/1.1" + CRLF
+        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
@@ -396,18 +394,18 @@ public class MockedBatchHandlerTest {
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 1" + CRLF
+        + "Content-Id: 3" + CRLF
         + CRLF
-        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF
+        + "POST $2/NavPropertyETAllPrimMany HTTP/1.1" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_12345" + CRLF
         + "Content-Type: application/http" + CRLF
         + "Content-Transfer-Encoding: binary" + CRLF
-        + "Content-Id: 3" + CRLF
+        + "Content-Id: 4" + CRLF
         + CRLF
-        + "POST $2/NavPropertyETAllPrimMany HTTP/1.1" + CRLF
+        + "POST $3/NavPropertyETTwoPrimOne HTTP/1.1" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
@@ -601,30 +599,26 @@ public class MockedBatchHandlerTest {
     @Override
     public void executeBatch(BatchFacade operation, ODataRequest request, ODataResponse response)
         throws SerializerException, BatchException {
-      try {
-        final List<BatchRequestPart> parts = odata.createFixedFormatDeserializer().parseBatchRequest(request, true);
-        final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
-
-        for (BatchRequestPart part : parts) {
-          for (final ODataRequest oDataRequest : part.getRequests()) {
-            // Mock the processor for a given requests
-            when(oDataHandler.process(oDataRequest)).then(new Answer<ODataResponse>() {
-              @Override
-              public ODataResponse answer(InvocationOnMock invocation) throws Throwable {
-                Object[] arguments = invocation.getArguments();
-
-                return buildResponse((ODataRequest) arguments[0]);
-              }
-            });
-          }
-
-          responseParts.add(operation.handleBatchRequest(part));
+      final List<BatchRequestPart> parts = odata.createFixedFormatDeserializer().parseBatchRequest(request, true);
+      final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
+
+      for (BatchRequestPart part : parts) {
+        for (final ODataRequest oDataRequest : part.getRequests()) {
+          // Mock the processor for a given requests
+          when(oDataHandler.process(oDataRequest)).then(new Answer<ODataResponse>() {
+            @Override
+            public ODataResponse answer(InvocationOnMock invocation) throws Throwable {
+              Object[] arguments = invocation.getArguments();
+
+              return buildResponse((ODataRequest) arguments[0]);
+            }
+          });
         }
 
-        odata.createFixedFormatSerializer().writeResponseParts(responseParts, response);
-      } catch (IOException e) {
-        throw new ODataRuntimeException(e);
+        responseParts.add(operation.handleBatchRequest(part));
       }
+
+      odata.createFixedFormatSerializer().writeResponseParts(responseParts, response);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/402e847a/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 b1dce91..d4c9873 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,7 +18,6 @@
  */
 package org.apache.olingo.server.tecsvc.processor;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -48,29 +47,24 @@ public class TechnicalBatchProcessor extends TechnicalProcessor implements Batch
       throws SerializerException, BatchException {
     boolean continueOnError = shouldContinueOnError(request);
 
-    try {
+    final List<BatchRequestPart> parts = odata.createFixedFormatDeserializer().parseBatchRequest(request, true);
+    final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
 
-      final List<BatchRequestPart> parts = odata.createFixedFormatDeserializer().parseBatchRequest(request, true);
-      final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
+    for (BatchRequestPart part : parts) {
+      final ODataResponsePart responsePart = operation.handleBatchRequest(part);
+      responseParts.add(responsePart); // Also add failed responses
 
-      for (BatchRequestPart part : parts) {
-        final ODataResponsePart responsePart = operation.handleBatchRequest(part);
-        responseParts.add(responsePart); // Also add failed responses
+      if (responsePart.getResponses().get(0).getStatusCode() >= 400
+          && !continueOnError) {
 
-        if (responsePart.getResponses().get(0).getStatusCode() >= 400
-            && !continueOnError) {
+        // Perform some additions actions
+        // ...
 
-          // Perform some additions actions
-          // ...
-
-          break; // Stop processing, but serialize all recent requests
-        }
+        break; // Stop processing, but serialize all recent requests
       }
-
-      odata.createFixedFormatSerializer().writeResponseParts(responseParts, response); // Serialize responses
-    } catch (IOException e) {
-      throw new ODataRuntimeException(e);
     }
+
+    odata.createFixedFormatSerializer().writeResponseParts(responseParts, response); // Serialize responses
   }
 
   private boolean shouldContinueOnError(ODataRequest request) {