Repository: olingo-odata4 Updated Branches: refs/heads/master b9512eda4 -> b317b9006
OLINGO-855: adding support for odata-isolation header support acknowledgement to ServiceHandler interface Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/b317b900 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/b317b900 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/b317b900 Branch: refs/heads/master Commit: b317b9006d9a71c58a5b4a0f62558b11acba3dae Parents: b9512ed Author: Ramesh Reddy <rare...@jboss.org> Authored: Mon Jan 25 09:20:54 2016 -0600 Committer: Ramesh Reddy <rare...@jboss.org> Committed: Mon Jan 25 09:20:54 2016 -0600 ---------------------------------------------------------------------- .../apache/olingo/commons/api/http/HttpHeader.java | 2 ++ .../apache/olingo/server/core/ServiceDispatcher.java | 9 +++++++++ .../org/apache/olingo/server/core/ServiceHandler.java | 14 ++++++++++++++ .../server/core/legacy/ProcessorServiceHandler.java | 5 +++++ .../apache/olingo/server/example/TripPinHandler.java | 5 +++++ .../olingo/server/example/TripPinServiceTest.java | 10 ++++++++++ 6 files changed, 45 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b317b900/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 f33dbb0..91c65ca 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 @@ -176,4 +176,6 @@ public interface HttpHeader { String ODATA_MAX_VERSION = "OData-MaxVersion"; /** Custom Header defined in the OData standard. */ String ODATA_ENTITY_ID = "OData-EntityID"; + /** Custom Header defined in the OData standard. */ + String ODATA_ISOLATION= "OData-Isolation"; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b317b900/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 45de757..cb718e1 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 @@ -24,6 +24,8 @@ import java.net.URISyntaxException; import java.net.URL; 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.OData; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ODataRequest; @@ -81,6 +83,13 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor { new UriValidator().validate(uriInfo, odRequest.getMethod()); + // part1, 8.2.6 + String isolation = odRequest.getHeader(HttpHeader.ODATA_ISOLATION); + if (isolation != null && isolation.equals("snapshot") && !this.handler.supportsDataIsolation()) { + odResponse.setStatusCode(HttpStatusCode.PRECONDITION_FAILED.getStatusCode()); + return; + } + visit(uriInfo); // this should cover for any unsupported calls until they are implemented http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b317b900/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java index 68043de..ba96f94 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java @@ -282,4 +282,18 @@ public interface ServiceHandler extends Processor { */ void crossJoin(DataRequest dataRequest, List<String> entitySetNames, ODataResponse response) throws ODataLibraryException, ODataApplicationException; + + /** + * Snapshot isolation guarantees that all data returned for a request, including multiple requests within + * a batch or results retrieved across multiple pages, will be consistent as of a single point in time. + * Only data modifications made within the request (for example, by a data modification request + * within the same batch) are visible. The effect is as if the request generates a "snapshot" of + * the committed data as it existed at the start of the request. for more info see OData V4, Part1 8.2.6 + * + * The contract for this interface is if it returns true, whenever the service deals with $skiptoken based + * results, they MUST be from same snapshot of the original request. false, the framework will automatically + * returns a 412. + * @return + */ + boolean supportsDataIsolation(); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b317b900/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java index b65f19c..db62c0a 100644 --- a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java +++ b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/legacy/ProcessorServiceHandler.java @@ -437,4 +437,9 @@ public class ProcessorServiceHandler implements ServiceHandler { throw new ODataHandlerException("not implemented", ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED); } + + @Override + public boolean supportsDataIsolation() { + return false; + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b317b900/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java index db06558..fea02e9 100644 --- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java +++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinHandler.java @@ -556,4 +556,9 @@ public class TripPinHandler implements ServiceHandler { updateEntity(request, entity, merge, entityETag, response); } } + + @Override + public boolean supportsDataIsolation() { + return false; + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b317b900/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 ef5376d..3beb274 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 @@ -42,6 +42,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; +import org.apache.olingo.commons.api.http.HttpHeader; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; @@ -732,4 +733,13 @@ public class TripPinServiceTest { HttpResponse response = httpGET(editUrl, 200); EntityUtils.consumeQuietly(response.getEntity()); } + + @Test + public void dataIsolation() throws Exception { + String url = baseURL + "/People"; + HttpRequest request = new HttpGet(url); + request.setHeader(HttpHeader.ODATA_ISOLATION, "snapshot"); + HttpResponse response = httpSend(request, 412); + EntityUtils.consumeQuietly(response.getEntity()); + } }