Author: dkatayev
Date: 2010-06-22 05:23:36 -0400 (Tue, 22 Jun 2010)
New Revision: 2676
Added:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
Log:
EXOJCR-774 If-Modified-Since management fixed,
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java 2010-06-21
17:06:59 UTC (rev 2675)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java 2010-06-22
09:23:36 UTC (rev 2676)
@@ -20,7 +20,9 @@
import org.exoplatform.common.http.HTTPStatus;
import org.exoplatform.common.util.HierarchicalProperty;
+import org.exoplatform.commons.utils.ISO8601;
import org.exoplatform.services.jcr.webdav.Range;
+import org.exoplatform.services.jcr.webdav.WebDavConst;
import org.exoplatform.services.jcr.webdav.resource.CollectionResource;
import org.exoplatform.services.jcr.webdav.resource.FileResource;
import org.exoplatform.services.jcr.webdav.resource.Resource;
@@ -40,8 +42,11 @@
import java.io.InputStream;
import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -82,7 +87,7 @@
* @return the instance of javax.ws.rs.core.Response
*/
public Response get(Session session, String path, String version, String baseURI,
List<Range> ranges,
- String ifModifiedSince, HashMap<MediaType, String> cahceControls)
+ String ifModifiedSince, HashMap<MediaType, String> cacheControls)
{
if (version == null)
{
@@ -125,9 +130,18 @@
}
// check before any other reads
- if ((ifModifiedSince != null) &&
(ifModifiedSince.equals(lastModifiedProperty.getValue())))
+
+ if (ifModifiedSince != null)
{
- return Response.notModified().entity("Not Modified").build();
+ DateFormat dateFormat = new
SimpleDateFormat(WebDavConst.DateFormat.IF_MODIFIED_SINCE_PATTERN);
+ Date lastModifiedDate =
dateFormat.parse(lastModifiedProperty.getValue());
+
+ dateFormat = new SimpleDateFormat(WebDavConst.DateFormat.MODIFICATION);
+ Date ifModifiedSinceDate = dateFormat.parse(ifModifiedSince);
+
+ if(ifModifiedSinceDate.getTime() >= lastModifiedDate.getTime()){
+ return Response.notModified().entity("Not
Modified").build();
+ }
}
HierarchicalProperty contentLengthProperty =
resource.getProperty(FileResource.GETCONTENTLENGTH);
@@ -148,7 +162,7 @@
return Response.ok().header(HttpHeaders.CONTENT_LENGTH,
Long.toString(contentLength)).header(
ExtHttpHeaders.ACCEPT_RANGES,
"bytes").header(ExtHttpHeaders.LAST_MODIFIED,
lastModifiedProperty.getValue()).header(ExtHttpHeaders.CACHE_CONTROL,
- generateCacheControl(cahceControls,
contentType)).entity(istream).type(contentType).build();
+ generateCacheControl(cacheControls,
contentType)).entity(istream).type(contentType).build();
}
// one range
Copied:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java
(from rev 2675,
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCashing.java)
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java 2010-06-22
09:23:36 UTC (rev 2676)
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.webdav.ext;
+
+import org.exoplatform.common.http.HTTPStatus;
+import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
+import org.exoplatform.services.jcr.webdav.WebDavConst;
+import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
+import org.exoplatform.services.jcr.webdav.utils.TestUtils;
+import org.exoplatform.services.rest.ExtHttpHeaders;
+import org.exoplatform.services.rest.impl.ContainerResponse;
+import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedMap;
+
+/**
+ * Created by The eXo Platform SAS Author : Dmytro Katayev
+ * work.visor.ck(a)gmail.com Aug 13, 2008
+ */
+public class TestCaching extends BaseStandaloneTest
+{
+ private String path = TestUtils.getFileName();
+
+ private String fileContent = TestUtils.getFileContent();
+
+ private Node node;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ InputStream inputStream = new ByteArrayInputStream(fileContent.getBytes());
+ node = TestUtils.addContent(session, path, inputStream, defaultFileNodeType,
"");
+ }
+
+ public void testNotModifiedSince() throws Exception
+ {
+ Node contentNode = node.getNode("jcr:content");
+ Property lastModifiedProperty =
contentNode.getProperty("jcr:lastModified");
+
+ SimpleDateFormat dateFormat = new
SimpleDateFormat(WebDavConst.DateFormat.IF_MODIFIED_SINCE_PATTERN);
+ Calendar lastModifiedDate = lastModifiedProperty.getDate();
+
+ lastModifiedDate.roll(Calendar.WEEK_OF_MONTH, -1);
+ // Rollback If-Modified-Since date a week earlier.
+ String ifModifiedDate = dateFormat.format(lastModifiedDate.getTime());
+
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ headers.add(ExtHttpHeaders.IF_MODIFIED_SINCE, ifModifiedDate);
+ ContainerResponse response = service(WebDAVMethods.GET, getPathWS() + path,
"", headers, null);
+
+ assertEquals(HTTPStatus.OK, response.getStatus());
+ }
+
+ public void testIfModifiedSince() throws Exception
+ {
+ Node contentNode = node.getNode("jcr:content");
+ Property lastModifiedProperty =
contentNode.getProperty("jcr:lastModified");
+
+ SimpleDateFormat dateFormat = new
SimpleDateFormat(WebDavConst.DateFormat.IF_MODIFIED_SINCE_PATTERN);
+ Calendar lastModifiedDate = lastModifiedProperty.getDate();
+
+ lastModifiedDate.add(Calendar.WEEK_OF_MONTH, 1);
+ String ifModifiedDate = dateFormat.format(lastModifiedDate.getTime());
+
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ headers.add(ExtHttpHeaders.IF_MODIFIED_SINCE, ifModifiedDate);
+ ContainerResponse response = service(WebDAVMethods.GET, getPathWS() + path,
"", headers, null);
+
+ assertEquals(HTTPStatus.NOT_MODIFIED, response.getStatus());
+ }
+
+ public void testCacheConf() throws Exception
+ {
+ ArrayList<CacheControlType> testValues = new
ArrayList<CacheControlType>();
+ testValues.add(new CacheControlType("text/xml",
"max-age=1800"));
+ testValues.add(new CacheControlType("text/pdf",
"max-age=777"));
+ testValues.add(new CacheControlType("image/jpg",
"max-age=3600"));
+ testValues.add(new CacheControlType("image/gif",
"max-age=555"));
+ testValues.add(new CacheControlType("test/test", "no-cache"));
+ testValues.add(new CacheControlType("*/*", "no-cache"));
+
+ Node contentNode = node.getNode("jcr:content");
+
+ for (CacheControlType cacheControlType : testValues)
+ {
+ contentNode.setProperty("jcr:mimeType",
cacheControlType.getContentType());
+ contentNode.getSession().save();
+ ContainerResponse response = service(WebDAVMethods.GET, getPathWS() + path,
"", null, null);
+ String cacheControlHeader =
response.getHttpHeaders().get(HttpHeaders.CACHE_CONTROL).toString();
+ cacheControlHeader = cacheControlHeader.substring(1, cacheControlHeader.length()
- 1);
+ assertEquals(cacheControlHeader, cacheControlType.getCacheValue());
+ }
+ }
+
+ @Override
+ protected String getRepositoryName()
+ {
+ return null;
+ }
+
+}
Property changes on:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain