[OLINGO-663] technical service uses UUIDs as ETags Change-Id: Ie34c22a817919afe2563a2f5d221e7d4495afda9
Signed-off-by: Christian Amend <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/44ec5787 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/44ec5787 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/44ec5787 Branch: refs/heads/OLINGO-642_OSGi-Sample Commit: 44ec57874d5937d167bd6f75f1796464ab564787 Parents: 36e09cf Author: Klaus Straubinger <[email protected]> Authored: Tue Jun 9 13:42:40 2015 +0200 Committer: Christian Amend <[email protected]> Committed: Tue Jun 9 13:55:48 2015 +0200 ---------------------------------------------------------------------- .../fit/tecsvc/client/BatchClientITCase.java | 10 +++++----- .../olingo/fit/tecsvc/http/BasicBatchITCase.java | 2 +- .../olingo/server/tecsvc/TechnicalServlet.java | 15 ++------------- .../olingo/server/tecsvc/data/DataProvider.java | 11 ++++++++--- .../tecsvc/processor/TechnicalProcessor.java | 18 +++++++++--------- 5 files changed, 25 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/44ec5787/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java index 7be6ab6..72a4ef3 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java @@ -170,7 +170,7 @@ public class BatchClientITCase extends AbstractTestITCase { assertEquals(1, oDataResonse.getHeader("OData-Version").size()); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals(1, oDataResonse.getHeader("Content-Length").size()); - assertEquals("583", oDataResonse.getHeader("Content-Length").toArray()[0]); + assertEquals("605", oDataResonse.getHeader("Content-Length").toArray()[0]); assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType()); } @@ -202,7 +202,7 @@ public class BatchClientITCase extends AbstractTestITCase { assertEquals(1, oDataResonse.getHeader("OData-Version").size()); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals(1, oDataResonse.getHeader("Content-Length").size()); - assertEquals("583", oDataResonse.getHeader("Content-Length").toArray()[0]); + assertEquals("605", oDataResonse.getHeader("Content-Length").toArray()[0]); assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType()); } @@ -234,7 +234,7 @@ public class BatchClientITCase extends AbstractTestITCase { assertEquals(1, oDataResonse.getHeader("OData-Version").size()); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals(1, oDataResonse.getHeader("Content-Length").size()); - assertEquals("583", oDataResonse.getHeader("Content-Length").toArray()[0]); + assertEquals("605", oDataResonse.getHeader("Content-Length").toArray()[0]); assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType()); // Check second get request @@ -334,7 +334,7 @@ public class BatchClientITCase extends AbstractTestITCase { assertEquals(1, oDataResonse.getHeader("OData-Version").size()); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals(1, oDataResonse.getHeader("Content-Length").size()); - assertEquals("583", oDataResonse.getHeader("Content-Length").toArray()[0]); + assertEquals("605", oDataResonse.getHeader("Content-Length").toArray()[0]); assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType()); // Check second get request @@ -357,7 +357,7 @@ public class BatchClientITCase extends AbstractTestITCase { assertEquals(1, oDataResonse.getHeader("OData-Version").size()); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals(1, oDataResonse.getHeader("Content-Length").size()); - assertEquals("491", oDataResonse.getHeader("Content-Length").toArray()[0]); + assertEquals("513", oDataResonse.getHeader("Content-Length").toArray()[0]); assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType()); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/44ec5787/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java index c434703..65d8830 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java @@ -60,7 +60,7 @@ public class BasicBatchITCase extends AbstractBaseTestITCase { assertEquals("HTTP/1.1 200 OK", reader.readLine()); assertEquals("OData-Version: 4.0", reader.readLine()); assertEquals("Content-Type: application/json;odata.metadata=minimal", reader.readLine()); - assertEquals("Content-Length: 583", reader.readLine()); + assertEquals("Content-Length: 605", reader.readLine()); blankLine(reader); reader.close(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/44ec5787/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java index 40433f3..9c1d502 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/TechnicalServlet.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.URI; import java.util.Collections; import java.util.List; +import java.util.UUID; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -56,7 +57,7 @@ public class TechnicalServlet extends HttpServlet { * therefore any change must be deployed, resulting in re-loading of this class, * giving this field a new and hopefully unique value.</p> */ - private static final String metadataETag = getETag(); + private static final String metadataETag = "W/\"" + UUID.randomUUID() + "\""; @Override protected void service(final HttpServletRequest request, final HttpServletResponse response) @@ -89,16 +90,4 @@ public class TechnicalServlet extends HttpServlet { throw new ServletException(e); } } - - private static String getETag() { - String time = "" + System.nanoTime(); - if (time.length() > 14) { - time = time.substring(0, 14); - } else { - while (time.length() < 14) { - time = "0" + time; - } - } - return "W/\"" + time + "\""; - } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/44ec5787/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java index 911ab25..fe06a1c 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java @@ -27,6 +27,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.UUID; import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Entity; @@ -282,7 +283,7 @@ public class DataProvider { public void updateETag(Entity entity) { if (entity.getETag() != null) { - entity.setETag("W/\"" + System.nanoTime() + "\""); + entity.setETag("W/\"" + UUID.randomUUID() + "\""); } } @@ -407,7 +408,7 @@ public class DataProvider { if (edmProperty.isPrimitive()) { if (newProperty != null || !patch) { final Object value = newProperty == null ? null : newProperty.getValue(); - property.setValue(property.getValueType(), value); + updatePropertyValue(property, value); } } else if (edmProperty.isCollection()) { // Updating collection properties means replacing all entries with the given ones. @@ -441,6 +442,10 @@ public class DataProvider { } } + public void updatePropertyValue(Property property, final Object value) { + property.setValue(property.getValueType(), value); + } + private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue, final boolean patch) throws DataProviderException { final ComplexValue result = new ComplexValue(); @@ -486,7 +491,7 @@ public class DataProvider { entity.getProperties().remove(entity.getProperty(MEDIA_PROPERTY_NAME)); entity.addProperty(DataCreator.createPrimitive(MEDIA_PROPERTY_NAME, media)); entity.setMediaContentType(type); - entity.setMediaETag("W/\"" + System.nanoTime() + "\""); + entity.setMediaETag("W/\"" + UUID.randomUUID() + "\""); } public EntityCollection readFunctionEntitySet(final EdmFunction function, final List<UriParameter> parameters) http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/44ec5787/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java index c95091d..f3012d9 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java @@ -109,7 +109,7 @@ public abstract class TechnicalProcessor implements Processor { return entitySet; } - + /** * Reads an entity as specified in the resource path, including navigation. * If there is navigation and the navigation ends on an entity collection, @@ -118,13 +118,13 @@ public abstract class TechnicalProcessor implements Processor { protected Entity readEntity(final UriInfoResource uriInfo) throws ODataApplicationException { return readEntity(uriInfo, false); } - + /** * If ignoreLastNavigation is set to false see {@link #readEntity(UriInfoResource)} * otherwise returns the second last entity (Ignores the last navigation) * If no such entity exists throws an ODataApplicationException */ - protected Entity readEntity(final UriInfoResource uriInfo, final boolean ignoreLastNavigation) + protected Entity readEntity(final UriInfoResource uriInfo, final boolean ignoreLastNavigation) throws ODataApplicationException { final List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); @@ -155,19 +155,19 @@ public abstract class TechnicalProcessor implements Processor { if (entity == null) { throw new ODataApplicationException("Nothing found.", HttpStatusCode.NOT_FOUND.getStatusCode(), Locale.ROOT); } - + int readAtMostNavigations = resourcePaths.size(); - if(ignoreLastNavigation) { + if (ignoreLastNavigation) { readAtMostNavigations = 0; - for(int i = 1; i <resourcePaths.size(); i++) { - if(resourcePaths.get(i) instanceof UriResourceNavigation) { + for (int i = 1; i < resourcePaths.size(); i++) { + if (resourcePaths.get(i) instanceof UriResourceNavigation) { readAtMostNavigations++; } else { break; } } } - + int navigationCount = 0; while (++navigationCount < readAtMostNavigations && resourcePaths.get(navigationCount) instanceof UriResourceNavigation) { @@ -205,7 +205,7 @@ public abstract class TechnicalProcessor implements Processor { } } } - + protected UriResourceNavigation getLastNavigation(final UriInfoResource uriInfo) { final List<UriResource> resourcePaths = uriInfo.getUriResourceParts(); int navigationCount = 1;
