Author: dkatayev
Date: 2010-06-22 05:47:01 -0400 (Tue, 22 Jun 2010)
New Revision: 2679
Added:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java
Removed:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCashing.java
Modified:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavConst.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/util/NodeTypeUtil.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
Log:
EXOJCR-774 If-Modified-Since management fixed
Modified:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavConst.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavConst.java 2010-06-22
09:29:38 UTC (rev 2678)
+++
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavConst.java 2010-06-22
09:47:01 UTC (rev 2679)
@@ -464,6 +464,11 @@
* Last modification date psttern.
*/
public static final String MODIFICATION = "EEE, dd MMM yyyy HH:mm:ss z";
+
+ /**
+ * If-Modified-Since date psttern.
+ */
+ public static final String IF_MODIFIED_SINCE_PATTERN = "EEE, d MMM yyyy
HH:mm:ss z";
}
/**
Modified:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java 2010-06-22
09:29:38 UTC (rev 2678)
+++
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java 2010-06-22
09:47:01 UTC (rev 2679)
@@ -21,6 +21,7 @@
import org.exoplatform.common.http.HTTPStatus;
import org.exoplatform.common.util.HierarchicalProperty;
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 +41,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;
@@ -125,9 +129,17 @@
}
// 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);
Modified:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java 2010-06-22
09:29:38 UTC (rev 2678)
+++
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java 2010-06-22
09:47:01 UTC (rev 2679)
@@ -18,6 +18,10 @@
*/
package org.exoplatform.services.jcr.webdav.command;
+import org.exoplatform.common.http.HTTPStatus;
+import org.exoplatform.services.jcr.webdav.lock.NullResourceLocksHolder;
+import org.exoplatform.services.jcr.webdav.util.TextUtil;
+
import java.io.InputStream;
import java.util.Calendar;
import java.util.List;
@@ -30,10 +34,6 @@
import javax.jcr.lock.LockException;
import javax.ws.rs.core.Response;
-import org.exoplatform.common.http.HTTPStatus;
-import org.exoplatform.services.jcr.webdav.lock.NullResourceLocksHolder;
-import org.exoplatform.services.jcr.webdav.util.TextUtil;
-
/**
* Created by The eXo Platform SAS Author : <a
* href="gavrikvetal(a)gmail.com">Vitaly Guly</a>.
Modified:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/util/NodeTypeUtil.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/util/NodeTypeUtil.java 2010-06-22
09:29:38 UTC (rev 2678)
+++
jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/util/NodeTypeUtil.java 2010-06-22
09:47:01 UTC (rev 2679)
@@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.nodetype.NodeType;
Modified:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java 2010-06-22
09:29:38 UTC (rev 2678)
+++
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java 2010-06-22
09:47:01 UTC (rev 2679)
@@ -18,6 +18,12 @@
*/
package org.exoplatform.services.jcr.webdav.command;
+import org.exoplatform.common.http.HTTPStatus;
+import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
+import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
+import org.exoplatform.services.jcr.webdav.utils.TestUtils;
+import org.exoplatform.services.rest.impl.ContainerResponse;
+
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
@@ -25,12 +31,6 @@
import java.io.Reader;
import java.io.StringWriter;
-import org.exoplatform.common.http.HTTPStatus;
-import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
-import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
-import org.exoplatform.services.jcr.webdav.utils.TestUtils;
-import org.exoplatform.services.rest.impl.ContainerResponse;
-
/**
* Created by The eXo Platform SAS Author : Dmytro Katayev
* work.visor.ck(a)gmail.com Aug 13, 2008
Modified:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2010-06-22
09:29:38 UTC (rev 2678)
+++
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2010-06-22
09:47:01 UTC (rev 2679)
@@ -26,7 +26,6 @@
import org.exoplatform.services.jcr.webdav.command.propfind.PropFindResponseEntity;
import org.exoplatform.services.jcr.webdav.utils.TestUtils;
import org.exoplatform.services.rest.impl.ContainerResponse;
-import org.exoplatform.services.rest.impl.InputHeadersMap;
import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
import java.io.ByteArrayInputStream;
Added:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java
(rev 0)
+++
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java 2010-06-22
09:47:01 UTC (rev 2679)
@@ -0,0 +1,127 @@
+/*
+ * 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 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/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCaching.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCashing.java
===================================================================
---
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCashing.java 2010-06-22
09:29:38 UTC (rev 2678)
+++
jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCashing.java 2010-06-22
09:47:01 UTC (rev 2679)
@@ -1,104 +0,0 @@
-/*
- * 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 java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.exoplatform.common.http.HTTPStatus;
-import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
-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;
-
-/**
- * Created by The eXo Platform SAS Author : Dmytro Katayev
- * work.visor.ck(a)gmail.com Aug 13, 2008
- */
-public class TestCashing 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 testIfModifiedSince() throws Exception
- {
- Node contentNode = node.getNode("jcr:content");
- Property lastModifiedProperty =
contentNode.getProperty("jcr:lastModified");
- String formatPattern = "EEE, dd MMM yyyy HH:mm:ss z";
- SimpleDateFormat dateFormat = new SimpleDateFormat(formatPattern, Locale.ENGLISH);
- dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
- String lastModified = dateFormat.format(lastModifiedProperty.getDate().getTime());
- MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
- headers.add(ExtHttpHeaders.IF_MODIFIED_SINCE, lastModified);
- 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;
- }
-
-}