summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-atom-runtime/src
diff options
context:
space:
mode:
authornash <nash@13f79535-47bb-0310-9956-ffa450edef68>2010-10-26 19:03:33 +0000
committernash <nash@13f79535-47bb-0310-9956-ffa450edef68>2010-10-26 19:03:33 +0000
commit958f042702b2b8fa766b6117da4212e4bfb58edd (patch)
tree1637d81bb798798c402e8772992ec86b059d1f4c /sca-java-2.x/trunk/modules/binding-atom-runtime/src
parent1dab0ca69239714516a971406fa6053d0db61137 (diff)
TUSCANY-3742: Fix time comparison for If-Modified-Since and If-Unmodified-Since (merged 1.x commit r1027658)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1027684 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-atom-runtime/src')
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java14
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java26
2 files changed, 29 insertions, 11 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
index 20fb9309d5..f2ad84bfd5 100644
--- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
@@ -279,7 +279,7 @@ class AtomBindingListenerServlet extends HttpServlet {
if ( predicate != null ) {
try {
Date predicateDate = dateFormat.parse( predicate );
- if ( predicateDate.compareTo( feedUpdated ) < 0 ) {
+ if ( predicateDate.compareTo( exactSeconds(feedUpdated) ) < 0 ) {
// Match, should short circuit
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
return;
@@ -292,7 +292,7 @@ class AtomBindingListenerServlet extends HttpServlet {
if ( predicate != null ) {
try {
Date predicateDate = dateFormat.parse( predicate );
- if ( predicateDate.compareTo( feedUpdated ) > 0 ) {
+ if ( predicateDate.compareTo( exactSeconds(feedUpdated) ) >= 0 ) {
// Match, should short circuit
response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
return;
@@ -891,5 +891,13 @@ class AtomBindingListenerServlet extends HttpServlet {
}
}
-
+ /**
+ * Round a date down to an exact number of seconds
+ * @param date with millisecond precision
+ * @return date rounded down to nearest second
+ */
+ private Date exactSeconds(Date date) {
+ return new Date(date.getTime() / 1000 * 1000);
+ }
+
}
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
index 34131f6195..89f182b7fc 100644
--- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/test/java/org/apache/tuscany/sca/binding/atom/ProviderFeedEntityTagsTestCase.java
@@ -175,7 +175,7 @@ public class ProviderFeedEntityTagsTestCase {
}
}
- // @Test @Ignore Intermitently fails, see TUSCANY-3299
+ @Test
public void testUnmodifiedGetIfUnModified() throws Exception {
//System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified");
// Feed request with predicates
@@ -187,8 +187,9 @@ public class ProviderFeedEntityTagsTestCase {
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
try {
- // Should return 304 - Feed not provided since feed is modified since.
- Assert.assertEquals(304, res.getStatus());
+ // Should return 200 - Feed provided since feed is unmodified since.
+ Assert.assertEquals(200, res.getStatus());
+ Assert.assertEquals(ResponseType.SUCCESS, res.getType());
} finally {
res.release();
}
@@ -276,7 +277,7 @@ public class ProviderFeedEntityTagsTestCase {
Date thisLastModified = res.getLastModified();
Assert.assertNotNull( thisLastModified );
- // Should return 200 - value since feed is changed
+ // Should return 200 - value since feed matches eTag
Assert.assertEquals(200, res.getStatus());
Assert.assertEquals(ResponseType.SUCCESS, res.getType());
@@ -290,12 +291,12 @@ public class ProviderFeedEntityTagsTestCase {
@Test
public void testModifiedGetIfUnModified() throws Exception {
- //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfUnModified");
+ //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfUnModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
- opts.setHeader( "If-Unmodified-Since", dateFormat.format( new Date() ));
+ opts.setHeader( "If-Unmodified-Since", dateFormat.format( previousSecond(lastModified) ));
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
@@ -309,12 +310,12 @@ public class ProviderFeedEntityTagsTestCase {
@Test
public void testModifiedGetIfModified() throws Exception {
- //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedUnmodifiedGetIfModified");
+ //System.out.println(">>>ProviderFeedEntityTagsTestCase.testFeedModifiedGetIfModified");
// Feed request with predicates
RequestOptions opts = new RequestOptions();
final String contentType = "application/atom+xml";
opts.setContentType(contentType);
- opts.setHeader( "If-Modified-Since", dateFormat.format( lastModified ));
+ opts.setHeader( "If-Modified-Since", dateFormat.format( previousSecond(lastModified) ));
ClientResponse res = client.get(providerURI, opts);
Assert.assertNotNull(res);
@@ -383,4 +384,13 @@ public class ProviderFeedEntityTagsTestCase {
}
}
}
+
+ /**
+ * Subtract one second from a date
+ * @param date with millisecond precision
+ * @return date with one second subtracted
+ */
+ private Date previousSecond(Date date) {
+ return new Date(date.getTime() - 1000);
+ }
}