[exo-jcr-commits] exo-jcr SVN: r435 - in jcr/trunk/exo.jcr.component.webdav/src: main/java/org/exoplatform/services/jcr/webdav/command and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Oct 27 11:02:24 EDT 2009


Author: dkatayev
Date: 2009-10-27 11:02:22 -0400 (Tue, 27 Oct 2009)
New Revision: 435

Added:
   jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCashing.java
Modified:
   jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavConst.java
   jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
   jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java
   jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java
   jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-178 TestCache added

Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavConst.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavConst.java	2009-10-27 14:52:30 UTC (rev 434)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavConst.java	2009-10-27 15:02:22 UTC (rev 435)
@@ -280,16 +280,6 @@
        */
       public static final String NO_CACHE = "no-cache";
 
-      /**
-       * Cache-Control value for images.
-       */
-      public static final String IMAGE_CACHE = "max-age=3600, must-revalidate";
-
-      /**
-       * Cache-Control value for audio-files.
-       */
-      public static final String AUDIO_CACHE = "max-age=118000, must-revalidate";
-
    }
 
    /**

Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java	2009-10-27 14:52:30 UTC (rev 434)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java	2009-10-27 15:02:22 UTC (rev 435)
@@ -134,7 +134,7 @@
    
    public static final String INIT_PARAM_CACHE_CONTROL = "cache-control";
    
-   private HashMap<String, String> cacheControlMap = new HashMap<String, String>();
+   public static HashMap<String, String> cacheControlMap = new HashMap<String, String>();
 
    /**
     * Logger.
@@ -256,12 +256,6 @@
          autoVersionType = pAutoVersion.getValue();
          log.info(INIT_PARAM_AUTO_VERSION + " = " + autoVersionType);
       }
-      
-      
-//      <value-param>
-//         <name>cache-control</name>
-//         <value>^(gif|jpg|png)$:max-age=3600;^(image/jpeg|text/html)$:max-age=1800</value>
-//      </value-param>
 
       ValueParam pCacheControl = params.getValueParam(INIT_PARAM_CACHE_CONTROL);
       if (pCacheControl != null)
@@ -269,9 +263,14 @@
          String cacheControlValue = pCacheControl.getValue();
          for (String element : cacheControlValue.split(";"))
          {
-            String mask = element.split(":")[0];
+            String contentTypes = element.split(":")[0];
             String value = element.split(":")[1];
-            cacheControlMap.put(mask, value);
+            String[] types = contentTypes.split(",");
+            for (String type : types)
+            {
+               cacheControlMap.put(type, value);
+            }
+            
          }
          log.info(INIT_PARAM_CACHE_CONTROL + " = " + pCacheControl);
       }
@@ -540,7 +539,7 @@
          String uri =
             uriInfo.getBaseUriBuilder().path(getClass()).path(repoName).path(workspaceName(repoPath)).build()
                .toString();
-         return new GetCommand().get(session, path(repoPath), version, uri, ranges, ifModifiedSince);
+         return new GetCommand().get(session, path(repoPath), version, uri, ranges, ifModifiedSince, cacheControlMap);
 
       }
       catch (PathNotFoundException exc)

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	2009-10-27 14:52:30 UTC (rev 434)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/GetCommand.java	2009-10-27 15:02:22 UTC (rev 435)
@@ -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.WebDavServiceImpl;
 import org.exoplatform.services.jcr.webdav.WebDavConst.CacheConstants;
 import org.exoplatform.services.jcr.webdav.resource.CollectionResource;
 import org.exoplatform.services.jcr.webdav.resource.FileResource;
@@ -40,6 +41,7 @@
 
 import java.io.InputStream;
 import java.net.URI;
+import java.util.HashMap;
 import java.util.List;
 
 import javax.jcr.Node;
@@ -78,7 +80,7 @@
     * @param ranges ranges
     * @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)
+   public Response get(Session session, String path, String version, String baseURI, List<Range> ranges, String ifModifiedSince, HashMap<String, String> cahceControls)
    {
 
       if (version == null)
@@ -140,10 +142,11 @@
             if (ranges.size() == 0)
             {
 
+
                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(contentType)).entity(istream).type(contentType).build();
+                  generateCacheControl(cahceControls, contentType)).entity(istream).type(contentType).build();
 
             }
 
@@ -264,17 +267,18 @@
     * @param contentType content type
     * @return Cache-Control value
     */
-   private String generateCacheControl(String contentType)
+   private String generateCacheControl(HashMap<String, String> controls, String contentType)
    {
-      if (contentType.contains("image"))
+      
+      
+      if (controls.containsKey(contentType))
       {
-         return CacheConstants.IMAGE_CACHE;
+         return controls.get(contentType);
       }
-      else if (contentType.contains("audio"))
+      else
       {
-         return CacheConstants.AUDIO_CACHE;
+         return CacheConstants.NO_CACHE;
       }
-      return CacheConstants.NO_CACHE;
    }
 
 }

Modified: jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java	2009-10-27 14:52:30 UTC (rev 434)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestGet.java	2009-10-27 15:02:22 UTC (rev 435)
@@ -24,22 +24,12 @@
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringWriter;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-import java.util.TimeZone;
 
-import javax.jcr.Node;
-import javax.jcr.Property;
-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.InputHeadersMap;
-import org.exoplatform.services.rest.impl.MultivaluedMapImpl;
 
 /**
  * Created by The eXo Platform SAS Author : Dmytro Katayev
@@ -51,15 +41,13 @@
    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, "");
+      TestUtils.addContent(session, path, inputStream, defaultFileNodeType, "");
    }
 
    public void testSimpleGet() throws Exception
@@ -76,19 +64,6 @@
       assertEquals(fileContent, str);
    }
    
-   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 testNotFoundGet() throws Exception
    {
       ContainerResponse response = service(WebDAVMethods.GET, getPathWS() + "/not-found" + path, "", null, null);

Added: 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/TestCashing.java	                        (rev 0)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCashing.java	2009-10-27 15:02:22 UTC (rev 435)
@@ -0,0 +1,96 @@
+/*
+ * 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.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 at 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 {
+      Node contentNode = node.getNode("jcr:content");
+      contentNode.setProperty("jcr:mimeType", "text/xml");
+      contentNode.getSession().save();
+      ContainerResponse response = service(WebDAVMethods.GET, getPathWS() + path, "", null, null);
+      String cacheControlHeader = response.getHttpHeaders().get(HttpHeaders.CACHE_CONTROL).toString();
+      assertEquals(cacheControlHeader, "[max-age=1800]");
+      
+      contentNode.setProperty("jcr:mimeType", "image/jpeg");
+      contentNode.getSession().save();
+      response = service(WebDAVMethods.GET, getPathWS() + path, "", null, null);
+      cacheControlHeader = response.getHttpHeaders().get(HttpHeaders.CACHE_CONTROL).toString();
+      assertEquals(cacheControlHeader, "[max-age=3600]");
+   }
+
+   @Override
+   protected String getRepositoryName()
+   {
+      return null;
+   }
+
+}


Property changes on: jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/ext/TestCashing.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml	2009-10-27 14:52:30 UTC (rev 434)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/resources/conf/standalone/test-configuration.xml	2009-10-27 15:02:22 UTC (rev 435)
@@ -182,9 +182,13 @@
          <value-param>
             <name>update-policy</name>
             <value>create-version</value>
-            <!--value>replace</value -->
-            <!-- value>add</value -->
          </value-param>
+         
+         <value-param>
+            <name>cache-control</name>
+            <value>image/jpeg,image/png:max-age=3600;text/html,text/xml:max-age=1800</value>
+         </value-param>         
+         
       </init-params>
    </component>
 



More information about the exo-jcr-commits mailing list