[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:
Klaus Straubinger 2015-06-09 13:42:40 +02:00 committed by Christian Amend
parent 36e09cf190
commit 44ec57874d
5 changed files with 25 additions and 31 deletions

View File

@ -170,7 +170,7 @@ public class BatchClientITCase extends AbstractTestITCase {
assertEquals(1, oDataResonse.getHeader("OData-Version").size()); assertEquals(1, oDataResonse.getHeader("OData-Version").size());
assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]);
assertEquals(1, oDataResonse.getHeader("Content-Length").size()); 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()); 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(1, oDataResonse.getHeader("OData-Version").size());
assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]);
assertEquals(1, oDataResonse.getHeader("Content-Length").size()); 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()); 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(1, oDataResonse.getHeader("OData-Version").size());
assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]);
assertEquals(1, oDataResonse.getHeader("Content-Length").size()); 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()); assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType());
// Check second get request // Check second get request
@ -334,7 +334,7 @@ public class BatchClientITCase extends AbstractTestITCase {
assertEquals(1, oDataResonse.getHeader("OData-Version").size()); assertEquals(1, oDataResonse.getHeader("OData-Version").size());
assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]);
assertEquals(1, oDataResonse.getHeader("Content-Length").size()); 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()); assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType());
// Check second get request // Check second get request
@ -357,7 +357,7 @@ public class BatchClientITCase extends AbstractTestITCase {
assertEquals(1, oDataResonse.getHeader("OData-Version").size()); assertEquals(1, oDataResonse.getHeader("OData-Version").size());
assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]); assertEquals("4.0", oDataResonse.getHeader("OData-Version").toArray()[0]);
assertEquals(1, oDataResonse.getHeader("Content-Length").size()); 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()); assertEquals("application/json;odata.metadata=minimal", oDataResonse.getContentType());
} }

View File

@ -60,7 +60,7 @@ public class BasicBatchITCase extends AbstractBaseTestITCase {
assertEquals("HTTP/1.1 200 OK", reader.readLine()); assertEquals("HTTP/1.1 200 OK", reader.readLine());
assertEquals("OData-Version: 4.0", reader.readLine()); assertEquals("OData-Version: 4.0", reader.readLine());
assertEquals("Content-Type: application/json;odata.metadata=minimal", 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); blankLine(reader);
reader.close(); reader.close();

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; 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, * therefore any change must be deployed, resulting in re-loading of this class,
* giving this field a new and hopefully unique value.</p> * 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 @Override
protected void service(final HttpServletRequest request, final HttpServletResponse response) protected void service(final HttpServletRequest request, final HttpServletResponse response)
@ -89,16 +90,4 @@ public class TechnicalServlet extends HttpServlet {
throw new ServletException(e); 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 + "\"";
}
} }

View File

@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Entity;
@ -282,7 +283,7 @@ public class DataProvider {
public void updateETag(Entity entity) { public void updateETag(Entity entity) {
if (entity.getETag() != null) { 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 (edmProperty.isPrimitive()) {
if (newProperty != null || !patch) { if (newProperty != null || !patch) {
final Object value = newProperty == null ? null : newProperty.getValue(); final Object value = newProperty == null ? null : newProperty.getValue();
property.setValue(property.getValueType(), value); updatePropertyValue(property, value);
} }
} else if (edmProperty.isCollection()) { } else if (edmProperty.isCollection()) {
// Updating collection properties means replacing all entries with the given ones. // 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, private ComplexValue createComplexValue(final EdmProperty edmProperty, final ComplexValue complexValue,
final boolean patch) throws DataProviderException { final boolean patch) throws DataProviderException {
final ComplexValue result = new ComplexValue(); final ComplexValue result = new ComplexValue();
@ -486,7 +491,7 @@ public class DataProvider {
entity.getProperties().remove(entity.getProperty(MEDIA_PROPERTY_NAME)); entity.getProperties().remove(entity.getProperty(MEDIA_PROPERTY_NAME));
entity.addProperty(DataCreator.createPrimitive(MEDIA_PROPERTY_NAME, media)); entity.addProperty(DataCreator.createPrimitive(MEDIA_PROPERTY_NAME, media));
entity.setMediaContentType(type); entity.setMediaContentType(type);
entity.setMediaETag("W/\"" + System.nanoTime() + "\""); entity.setMediaETag("W/\"" + UUID.randomUUID() + "\"");
} }
public EntityCollection readFunctionEntitySet(final EdmFunction function, final List<UriParameter> parameters) public EntityCollection readFunctionEntitySet(final EdmFunction function, final List<UriParameter> parameters)

View File

@ -157,10 +157,10 @@ public abstract class TechnicalProcessor implements Processor {
} }
int readAtMostNavigations = resourcePaths.size(); int readAtMostNavigations = resourcePaths.size();
if(ignoreLastNavigation) { if (ignoreLastNavigation) {
readAtMostNavigations = 0; readAtMostNavigations = 0;
for(int i = 1; i <resourcePaths.size(); i++) { for (int i = 1; i < resourcePaths.size(); i++) {
if(resourcePaths.get(i) instanceof UriResourceNavigation) { if (resourcePaths.get(i) instanceof UriResourceNavigation) {
readAtMostNavigations++; readAtMostNavigations++;
} else { } else {
break; break;