You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2005/08/17 20:02:08 UTC

svn commit: r233223 - in /portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver: ContentFilter.java ContentLocatingResponseWrapper.java

Author: weaver
Date: Wed Aug 17 11:02:06 2005
New Revision: 233223

URL: http://svn.apache.org/viewcvs?rev=233223&view=rev
Log:
JS2-303.  Added some efficiency checks, i.e. if we are dealing with non-stale, cached content don't even bother with writing to the response.

Modified:
    portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java
    portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java

Modified: portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java?rev=233223&r1=233222&r2=233223&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java (original)
+++ portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentFilter.java Wed Aug 17 11:02:06 2005
@@ -18,9 +18,15 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.StringTokenizer;
+import java.util.TimeZone;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -61,7 +67,14 @@
     protected String[] urlHints;
 
     protected boolean useCache;
-
+    
+    static DateFormat HEADER_DATE_FORMAT = new SimpleDateFormat("EEE, d MMM yyyy hh:mm:ss zzz");
+    
+    public ContentFilter()
+    {
+        HEADER_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
+    }
+    
     /**
      * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
      */
@@ -117,7 +130,7 @@
                 
                 SimpleContentLocator contentLocator = new SimpleContentLocator(this.contentDir, urlHints, useCache, httpRequest
                         .getContextPath(), requestURI, getContentSearchPathes(httpRequest));
-
+                 
                 ContentLocatingResponseWrapper respWrapper = new ContentLocatingResponseWrapper(httpResponse,
                         contentLocator);
                 
@@ -127,16 +140,23 @@
                 chain.doFilter(reqWrapper, respWrapper);
                 if(!respWrapper.wasLocationAttempted() && !respWrapper.outputStreamCalled && !respWrapper.writerCalled)
                 {
-                    try
-                    {                   
-                        httpResponse.setContentLength((int) contentLocator.writeToOutputStream(httpResponse.getOutputStream()));
-                        httpResponse.setStatus(HttpServletResponse.SC_OK);
+                    try                    
+                    {         
+                        if(resourceContentRequired(httpRequest, contentLocator))
+                        {
+                            httpResponse.setContentLength((int) contentLocator.writeToOutputStream(httpResponse.getOutputStream()));
+                            httpResponse.setStatus(HttpServletResponse.SC_OK);
+                        }
+                        else
+                        {
+                            httpResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+                        }
+                                      
                     }
                     catch (FileNotFoundException e)
                     {
                         httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
-                    }
-                   
+                    }                   
                     
                 }
 
@@ -171,5 +191,28 @@
             //        .setAttribute(SESSION_THEME_ATTR, contentPathes);
         }
         return contentPathes;
+    }
+    
+    protected boolean resourceContentRequired(HttpServletRequest request, ContentLocator contentLocator)
+    {
+        String dateString = request.getHeader("If-Modified-Since");
+        if (dateString != null)
+        {
+            try
+            {
+                Date ifModifiedSince = HEADER_DATE_FORMAT.parse(dateString);
+                Date lastModified = contentLocator.getLastModified();
+                return lastModified.after(ifModifiedSince);
+            }
+            catch (ParseException e)
+            {
+                // Unreadable date string
+                return true;
+            }
+        }
+        else
+        {
+            return true;
+        }
     }
 }

Modified: portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java?rev=233223&r1=233222&r2=233223&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java (original)
+++ portals/jetspeed-2/trunk/content-server/src/java/org/apache/jetspeed/contentserver/ContentLocatingResponseWrapper.java Wed Aug 17 11:02:06 2005
@@ -1,8 +1,17 @@
 /*
- * Created on Aug 10, 2004
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Generation - Code and Comments
+ * Copyright 2000-2001,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.apache.jetspeed.contentserver;
 
@@ -49,11 +58,9 @@
     {
         super(response);
         this.contentLocator = contentLocator;
-        this.response = response;
+        this.response = response;    
         
-        DateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy hh:mm:ss zzz");
-        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
-        this.response.setHeader("Last-Modified", dateFormat.format(contentLocator.getLastModified()));
+        this.response.setHeader("Last-Modified", ContentFilter.HEADER_DATE_FORMAT.format(contentLocator.getLastModified()));
         this.response.setHeader("Cache-Control", "max-age=3600, must-revalidate, proxy-revalidate");
         this.response.setHeader("Apache-Jetspeed-Info", "real-path="+this.contentLocator.getBasePath());
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org