olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rare...@apache.org
Subject olingo-odata4 git commit: OLINGO-1316: allowing multipart/mixed as contentType for batch requests
Date Tue, 20 Nov 2018 18:06:17 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/master fd481c11d -> df332b338


OLINGO-1316: allowing multipart/mixed as contentType for batch requests


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

Branch: refs/heads/master
Commit: df332b3384ef2d51daf395eb541d77af9dd8b9f1
Parents: fd481c1
Author: Ramesh Reddy <rareddy@jboss.org>
Authored: Tue Nov 20 12:05:54 2018 -0600
Committer: Ramesh Reddy <rareddy@jboss.org>
Committed: Tue Nov 20 12:05:54 2018 -0600

----------------------------------------------------------------------
 .../olingo/server/core/ServiceDispatcher.java   | 23 +++++++++++------
 .../server/example/TripPinServiceTest.java      | 26 ++++++++++++++++++++
 .../server/core/ContentNegotiatorTest.java      |  8 ++++++
 3 files changed, 49 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/df332b33/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
index c6c3a79..7f06e95 100644
--- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
+++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceDispatcher.java
@@ -51,6 +51,7 @@ import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty;
 import org.apache.olingo.server.api.uri.UriResourceRef;
 import org.apache.olingo.server.api.uri.UriResourceSingleton;
 import org.apache.olingo.server.api.uri.UriResourceValue;
+import org.apache.olingo.server.api.uri.queryoption.FormatOption;
 import org.apache.olingo.server.core.requests.ActionRequest;
 import org.apache.olingo.server.core.requests.BatchRequest;
 import org.apache.olingo.server.core.requests.DataRequest;
@@ -79,11 +80,9 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor {
   }
 
   public void execute(ODataRequest odRequest, ODataResponse odResponse) {
-    ContentType contentType = ContentType.JSON;
+    FormatOption formatOption = null;
+    ODataException oDataException = null;
     try {
-      contentType = ContentNegotiator.doContentNegotiation(null,
-          odRequest, this.customContentSupport, RepresentationType.ERROR);
-      
       String path = odRequest.getRawODataPath();      
       String query = odRequest.getRawQueryPath();      
       if(path.indexOf("$entity") != -1) {
@@ -92,16 +91,24 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor {
         UriInfo uriInfo = new Parser(this.metadata.getEdm(), odata)
           .parseUri(path, query, null, odRequest.getRawBaseUri());
         
-        contentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
-            odRequest, this.customContentSupport, RepresentationType.ERROR);      
+        formatOption = uriInfo.getFormatOption();
         
         internalExecute(uriInfo, odRequest, odResponse);
       }
+      return;
     } catch(ODataLibraryException e) {
-      handleException(e, contentType, odRequest, odResponse);
+    	oDataException = e;
     } catch(ODataApplicationException e) {
-      handleException(e, contentType, odRequest, odResponse);
+    	oDataException = e;
+    }
+    ContentType contentType = ContentType.JSON;
+    try {
+      contentType = ContentNegotiator.doContentNegotiation(formatOption, 
+          odRequest, this.customContentSupport, RepresentationType.ERROR);
+    } catch (ContentNegotiatorException e) {
+      // ignore, default to JSON
     }
+    handleException(oDataException, contentType, odRequest, odResponse);
   }
   
   protected void handleException(ODataException e, ContentType contentType,

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/df332b33/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
index bbbaa9e..fdc0e4a 100644
--- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
@@ -63,6 +63,7 @@ public class TripPinServiceTest {
   private static String baseURL;
   private static DefaultHttpClient http = new DefaultHttpClient();
   private static final int TOMCAT_PORT = 9900;
+  private static final String CRLF = "\r\n";
 
   @BeforeClass
   public static void beforeTest() throws Exception {
@@ -808,4 +809,29 @@ public class TripPinServiceTest {
     HttpResponse response = httpSend(request, 412);
     EntityUtils.consumeQuietly(response.getEntity());
   }  
+  
+  @Test
+  public void batchAccept() throws Exception {
+  	final String batchtUrl = baseURL + "/$batch";
+  	
+  	final String content = ""
+        + "--batch_12345" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "GET Airlines('FM') HTTP/1.1" + CRLF
+        + CRLF
+        + CRLF
+        + "--batch_12345--";
+  	
+    HttpPost request = new HttpPost(batchtUrl);
+    StringEntity stringEntity = new StringEntity(content);
+    stringEntity.setContentType("multipart/mixed;boundary=batch_12345");
+    request.setEntity(stringEntity);
+    // multipart/mixed should work as an Accept value
+    request.setHeader("Accept", "multipart/mixed");
+    HttpResponse response = httpSend(request, 202);
+    EntityUtils.consumeQuietly(response.getEntity());
+  }
+  
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/df332b33/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
index 8e91cd1..167fa7e 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
@@ -55,6 +55,7 @@ public class ContentNegotiatorTest {
   static final private String ACCEPT_CASE_WILDCARD1 = "*/*";
   static final private String ACCEPT_CASE_WILDCARD2 = "application/*";
   static final private String ACCEPT_CASE_JSON_IEEE754 = ACCEPT_CASE_JSON + ";IEEE754Compatible=true";
+  static final private String ACCEPT_CASE_MULTIPART_MIXED = ContentType.MULTIPART_MIXED.toContentTypeString();
 
   //@formatter:off (Eclipse formatter)
   //CHECKSTYLE:OFF (Maven checkstyle)
@@ -335,4 +336,11 @@ public class ContentNegotiatorTest {
     assertTrue(ContentNegotiator.isSupported(ContentType.create("a/b"), 
         createCustomContentTypeSupport("a/b"), RepresentationType.BINARY));
   }
+  
+  @Test
+  public void checBatchkSupport() throws Exception {
+    testContentNegotiation(new String[] { ACCEPT_CASE_MULTIPART_MIXED, null, ACCEPT_CASE_MULTIPART_MIXED,
null },
+        RepresentationType.BATCH);
+  }
+  
 }


Mime
View raw message