mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-06 16:49:09 +00:00
[OLINGO-663] technical service uses UUIDs as ETags
Change-Id: Ie34c22a817919afe2563a2f5d221e7d4495afda9 Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
parent
36e09cf190
commit
44ec57874d
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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 + "\"";
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user