olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ram...@apache.org
Subject olingo-odata2 git commit: [OLINGO-1136]Making Batch odata request headers available for every batch request
Date Fri, 09 Jun 2017 06:21:19 GMT
Repository: olingo-odata2
Updated Branches:
  refs/heads/master fcf0ce8d7 -> f829d06db


[OLINGO-1136]Making Batch odata request headers available for every batch request


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

Branch: refs/heads/master
Commit: f829d06dbe5adfe7e980862b6b9c1a5b817f512f
Parents: fcf0ce8
Author: ramya vasanth <ramya.vasanth@sap.com>
Authored: Fri Jun 9 11:51:08 2017 +0530
Committer: ramya vasanth <ramya.vasanth@sap.com>
Committed: Fri Jun 9 11:51:08 2017 +0530

----------------------------------------------------------------------
 .../odata2/core/batch/BatchHandlerImpl.java     |  6 ++++
 .../olingo/odata2/fit/basic/BasicBatchTest.java | 33 ++++++++++++++++++++
 2 files changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f829d06d/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 64f8e22..cfc5df6 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
@@ -48,6 +48,7 @@ public class BatchHandlerImpl implements BatchHandler {
   private ODataServiceFactory factory;
   private ODataService service;
   private Map<String, String> contentIdMap;
+  private static final String BATCH_ODATA_REQUEST_HEADERS = "batchODataRequestHeaders";
 
   public BatchHandlerImpl(final ODataServiceFactory factory, final ODataService service)
{
     this.factory = factory;
@@ -184,6 +185,11 @@ public class BatchHandlerImpl implements BatchHandler {
     ODataContext parentContext = service.getProcessor().getContext();
     context.setBatchParentContext(parentContext);
     context.setService(service);
+    if (parentContext != null && parentContext.getParameter(BATCH_ODATA_REQUEST_HEADERS)
!= null) {
+      context.setParameter(BATCH_ODATA_REQUEST_HEADERS, parentContext.getParameter(BATCH_ODATA_REQUEST_HEADERS));
+    } else if (parentContext != null && parentContext.getRequestHeaders() != null)
{
+      context.setParameter(BATCH_ODATA_REQUEST_HEADERS, parentContext.getRequestHeaders());
+    }
     service.getProcessor().setContext(context);
     return new ODataRequestHandler(factory, service, context);
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/f829d06d/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
index 4567501..ecf4590 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java
@@ -30,6 +30,7 @@ import java.io.OutputStreamWriter;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
 import org.apache.http.HttpEntity;
@@ -135,6 +136,31 @@ public class BasicBatchTest extends AbstractBasicTest {
   }
 
   @Test
+  public void testBatchWithODataBatchRequestHeaders() throws Exception {
+    final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + "$batch"));
+    post.setHeader("Content-Type", "multipart/mixed;boundary=batch_98c1-8b13-36bb");
+    post.setHeader("testHeader", "abc123");
+    HttpEntity entity = new StringEntity(REQUEST_PAYLOAD);
+    post.setEntity(entity);
+    HttpResponse response = getHttpClient().execute(post);
+
+    assertNotNull(response);
+    assertEquals(202, response.getStatusLine().getStatusCode());
+    assertEquals("HTTP/1.1", response.getProtocolVersion().toString());
+    assertTrue(response.containsHeader("Content-Length"));
+    assertTrue(response.containsHeader("Content-Type"));
+    assertTrue(response.containsHeader("DataServiceVersion"));
+    assertTrue(response.getEntity().getContentType().getValue().matches(REG_EX));
+    assertNotNull(response.getEntity().getContent());
+
+    String body = StringHelper.inputStreamToString(response.getEntity().getContent(), true);
+    assertTrue(body.contains("Content-Id: mimeHeaderContentId1"));
+    assertTrue(body.contains("Content-Id: requestHeaderContentId1"));
+    assertTrue(body.contains("Content-Id: mimeHeaderContentId2"));
+    assertTrue(body.contains("Content-Id: requestHeaderContentId2"));
+  }
+  
+  @Test
   public void testBatchUriEncoded() throws Exception {
     final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + "%24batch"));
     post.setHeader("Content-Type", "multipart/mixed;boundary=batch_98c1-8b13-36bb");
@@ -275,6 +301,7 @@ public class BasicBatchTest extends AbstractBasicTest {
   }
 
   static class TestSingleProc extends ODataSingleProcessor {
+    @SuppressWarnings("unchecked")
     @Override
     public ODataResponse executeBatch(final BatchHandler handler, final String requestContentType,
         final InputStream content) {
@@ -292,6 +319,12 @@ public class BasicBatchTest extends AbstractBasicTest {
             EntityProvider.parseBatchRequest(requestContentType, content, batchProperties);
         for (BatchRequestPart batchPart : batchParts) {
           batchResponseParts.add(handler.handleBatchPart(batchPart));
+          List<String> customHeader = ((ArrayList<String>)((HashMap<String,
Object>)getContext().
+              getParameter("batchODataRequestHeaders")).get("testheader"));
+          if (getContext().getParameter("batchODataRequestHeaders") != null && 
+              customHeader != null) {
+            assertEquals("abc123", customHeader.get(0));
+          }
         }
         batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
       } catch (URISyntaxException e) {


Mime
View raw message