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 2015/11/05 16:34:47 UTC

olingo-odata2 git commit: [OLINGO-813] Fix nullpointer in BatchHandler

Repository: olingo-odata2
Updated Branches:
  refs/heads/master d69117779 -> f8bbd747c


[OLINGO-813] Fix nullpointer in BatchHandler


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/f8bbd747
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/f8bbd747
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/f8bbd747

Branch: refs/heads/master
Commit: f8bbd747cf0a5ab3d2b35751ad167e36bf2f8b42
Parents: d691177
Author: Christian Amend <ch...@sap.com>
Authored: Thu Nov 5 16:24:35 2015 +0100
Committer: Christian Amend <ch...@sap.com>
Committed: Thu Nov 5 16:28:04 2015 +0100

----------------------------------------------------------------------
 .../odata2/core/batch/BatchHandlerImpl.java     |  4 +++
 .../apache/olingo/odata2/fit/ref/BatchTest.java |  7 +++++
 .../resources/batchWithWrongContentId.batch     | 33 ++++++++++++++++++++
 3 files changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f8bbd747/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHandlerImpl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHandlerImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHandlerImpl.java
index d2d4cee..6b8f13d 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHandlerImpl.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchHandlerImpl.java
@@ -116,6 +116,10 @@ public class BatchHandlerImpl implements BatchHandler {
   private ODataRequest modifyRequest(final ODataRequest request, final List<PathSegment> odataSegments)
       throws ODataException {
     String contentId = contentIdMap.get(odataSegments.get(0).getPath());
+    if (contentId == null) {
+      //invalid content ID. But throwing an exception here is wrong so we use the base request and fail later
+      return request;
+    }
     PathInfoImpl pathInfo = new PathInfoImpl();
     try {
       List<PathSegment> modifiedODataSegments = new ArrayList<PathSegment>();

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f8bbd747/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java
index a6a297d..11c3d44 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/BatchTest.java
@@ -102,6 +102,13 @@ public class BatchTest extends AbstractRefTest {
   }
 
   @Test
+  public void testWrongContentId() throws Exception {
+    HttpResponse response = execute("/batchWithWrongContentId.batch", "batch_cf90-46e5-1246");
+    String responseBody = StringHelper.inputStreamToString(response.getEntity().getContent(), true);
+    assertTrue(responseBody.contains("HTTP/1.1 404 Not Found"));
+  }
+  
+  @Test
   public void testGPPG() throws Exception {
     HttpResponse response = execute("/batchWithContentIdPart2.batch", "batch_cf90-46e5-1246");
     String responseBody = StringHelper.inputStreamToString(response.getEntity().getContent(), true);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f8bbd747/odata2-lib/odata-fit/src/test/resources/batchWithWrongContentId.batch
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/resources/batchWithWrongContentId.batch b/odata2-lib/odata-fit/src/test/resources/batchWithWrongContentId.batch
new file mode 100644
index 0000000..4fc9a19
--- /dev/null
+++ b/odata2-lib/odata-fit/src/test/resources/batchWithWrongContentId.batch
@@ -0,0 +1,33 @@
+--batch_cf90-46e5-1246
+Content-Type: multipart/mixed; boundary=changeset_824f-ce08-1e9d
+
+--changeset_824f-ce08-1e9d
+Content-Type: application/http
+Content-Transfer-Encoding: binary
+Content-ID: employee
+
+POST Employees HTTP/1.1
+Content-ID: employee
+Content-Type: application/octet-stream
+Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
+MaxDataServiceVersion: 2.0
+
+
+--changeset_824f-ce08-1e9d
+Content-Type: application/http
+Content-Transfer-Encoding: binary
+Content-Id: AAA
+
+PUT $wrong/EmployeeName HTTP/1.1
+Content-Length: 100000
+Accept: application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
+DataServiceVersion: 1.0
+Content-Id: AAA
+Content-Type: application/json;odata=verbose
+MaxDataServiceVersion: 2.0
+
+{"EmployeeName":"Robert Fall"}
+
+--changeset_824f-ce08-1e9d--
+
+--batch_cf90-46e5-1246--
\ No newline at end of file