[OLINGO-663] Default metadata etag generation fix

ETag value based on nano seconds will always be 14 characters long from
now on.
This commit is contained in:
Christian Amend 2015-06-08 14:14:42 +02:00
parent a604fa78f2
commit c35076fbe9
3 changed files with 19 additions and 7 deletions

View File

@ -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("582", oDataResonse.getHeader("Content-Length").toArray()[0]);
assertEquals("583", 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("582", oDataResonse.getHeader("Content-Length").toArray()[0]);
assertEquals("583", 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("582", oDataResonse.getHeader("Content-Length").toArray()[0]);
assertEquals("583", 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("582", oDataResonse.getHeader("Content-Length").toArray()[0]);
assertEquals("583", 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("490", oDataResonse.getHeader("Content-Length").toArray()[0]);
assertEquals("491", oDataResonse.getHeader("Content-Length").toArray()[0]);
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("OData-Version: 4.0", reader.readLine());
assertEquals("Content-Type: application/json;odata.metadata=minimal", reader.readLine());
assertEquals("Content-Length: 582", reader.readLine());
assertEquals("Content-Length: 583", reader.readLine());
blankLine(reader);
reader.close();

View File

@ -56,7 +56,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 = "W/\"" + System.nanoTime() + "\"";
private static final String metadataETag = getETag();
@Override
protected void service(final HttpServletRequest request, final HttpServletResponse response)
@ -89,4 +89,16 @@ 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 + "\"";
}
}