OLINGO-855: adding support for odata-isolation header support acknowledgement to ServiceHandler interface

This commit is contained in:
Ramesh Reddy 2016-01-25 09:20:54 -06:00
parent b9512eda4b
commit b317b9006d
6 changed files with 45 additions and 0 deletions

View File

@ -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";
}

View File

@ -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

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -556,4 +556,9 @@ public class TripPinHandler implements ServiceHandler {
updateEntity(request, entity, merge, entityETag, response);
}
}
@Override
public boolean supportsDataIsolation() {
return false;
}
}

View File

@ -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());
}
}