Author: markt
Date: Mon Jul  6 21:06:13 2009
New Revision: 791616

URL: http://svn.apache.org/viewvc?rev=791616&view=rev
Log:
Convert the WebDAV fix valve to a filter.
Based on a patch provided by Xie Xiaodong as part of GSOC 2009

Added:
    tomcat/trunk/java/org/apache/catalina/filters/WebdavFixFilter.java
      - copied, changed from r791216, 
tomcat/trunk/java/org/apache/catalina/valves/WebdavFixValve.java
Removed:
    tomcat/trunk/java/org/apache/catalina/valves/WebdavFixValve.java
Modified:
    tomcat/trunk/webapps/docs/config/filter.xml
    tomcat/trunk/webapps/docs/config/valve.xml

Copied: tomcat/trunk/java/org/apache/catalina/filters/WebdavFixFilter.java 
(from r791216, tomcat/trunk/java/org/apache/catalina/valves/WebdavFixValve.java)
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/filters/WebdavFixFilter.java?p2=tomcat/trunk/java/org/apache/catalina/filters/WebdavFixFilter.java&p1=tomcat/trunk/java/org/apache/catalina/valves/WebdavFixValve.java&r1=791216&r2=791616&rev=791616&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/WebdavFixValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/filters/WebdavFixFilter.java Mon Jul  
6 21:06:13 2009
@@ -15,58 +15,76 @@
  * limitations under the License.
  */
 
-package org.apache.catalina.valves;
+package org.apache.catalina.filters;
 
 import java.io.IOException;
 
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
 import javax.servlet.ServletException;
-
-import org.apache.catalina.valves.ValveBase;
-import org.apache.catalina.connector.Request;
-import org.apache.catalina.connector.Response;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 /**
- * Valve that attempts to force MS WebDAV clients connecting on port 80 to use
+ * Filter that attempts to force MS WebDAV clients connecting on port 80 to use
  * a WebDAV client that actually works. Other workarounds that might help
  * include:
  * <ul>
- *   <li>Specifing the port, even if it is port 80, when trying to 
connect.</li>
- *   <li>Canceling the first authentication dialog box and then trying to
+ *   <li>Specifying the port, even if it is port 80, when trying to 
connect.</li>
+ *   <li>Cancelling the first authentication dialog box and then trying to
  *       reconnect.</li>
  * </ul>
- * To use this valve add the following <code>&lt;Valve
- * className="org.apache.catalina.valves.WebdavFixValve" /&gt;</code>
- * to your <code>Engine</code>, <code>Host</code> or <code>Context</code> as
- * required. Normally, this valve would be used at the <code>Context</code>
- * level.
- *
- * @version $Revision$, $Date$
+ * 
+ * Generally each different version of the MS client has a different set of
+ * problems.
+ * TODO: Update this filter to recognise specific MS clients and apply the
+ *       appropriate workarounds for that particular client
+ *       
+ * As a filter, this is configured in web.xml like any other Filter. You 
usually
+ * want to map this filter to whatever your WebDAV servlet is mapped to.
  */
 
-public class WebdavFixValve
-    extends ValveBase {
+public class WebdavFixFilter implements Filter {
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+    }
+
+       @Override
+       public void destroy() {
+       }
 
     /**
      * Check for the broken MS WebDAV client and if detected issue a re-direct
      * that hopefully will cause the non-broken client to be used.
      */
-    public void invoke(Request request, Response response)
-        throws IOException, ServletException {
-
-        String ua = request.getHeader("User-Agent");
-        if (ua != null && ua.contains("MiniRedir")) {
-            response.sendRedirect(buildRedirect(request));
-        } else {
-            getNext().invoke(request, response);
+       @Override
+       public void doFilter(ServletRequest request, ServletResponse response,
+                       FilterChain chain) throws IOException, ServletException 
{
+           if (!(request instanceof HttpServletRequest) ||
+                   !(response instanceof HttpServletResponse)) {
+            chain.doFilter(request, response);
+            return;
         }
-    }
+               HttpServletRequest httpRequest = ((HttpServletRequest) request);
+               HttpServletResponse httpResponse = ((HttpServletResponse) 
response);
+               String ua = httpRequest.getHeader("User-Agent");
+               if (ua != null && ua.contains("MiniRedir")) {
+                       httpResponse.sendRedirect(buildRedirect(httpRequest));
+               } else {
+                       chain.doFilter(request, response);
+               }               
+       }
 
-    private String buildRedirect(Request request) {
+    private String buildRedirect(HttpServletRequest request) {
         StringBuffer location =
             new StringBuffer(request.getRequestURL().length());
         location.append(request.getScheme());
         location.append("://");
-        location.append(request.getHost().getName());
+        location.append(request.getServerName());
         location.append(':');
         // If we include the port, even if it is 80, then MS clients will use
         // a WebDAV client that works rather than the MiniRedir that has
@@ -75,4 +93,5 @@
         location.append(request.getRequestURI());
         return location.toString();
     }
+
 }

Modified: tomcat/trunk/webapps/docs/config/filter.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/filter.xml?rev=791616&r1=791615&r2=791616&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/filter.xml (original)
+++ tomcat/trunk/webapps/docs/config/filter.xml Mon Jul  6 21:06:13 2009
@@ -77,7 +77,39 @@
   <subsection name="Initialisation parameters">
 
     <p>The Add Default Character Set Filter does not support any initialization
-    parameters</p>
+    parameters.</p>
+
+  </subsection>
+
+</section>
+
+
+<section name="WebDAV Fix Filter">
+
+  <subsection name="Introduction">
+
+    <p>Microsoft operating systems have two WebDAV clients. One is used with
+    port 80, the other is used for all other ports. The implementation used 
with
+    port 80 does not adhere to the WebDAV specification and fails when trying 
to
+    communicate with the Tomcat WebDAV Servlet. This Filter provides a fix for
+    this by forcing the use of the WebDAV implementation that works, even when
+    connecting via port 80.</p>
+    
+  </subsection>
+
+  <subsection name="Filter Class Name">
+
+    <p>The filter class name for the WebDAV Fix Filter is
+    <strong><code>org.apache.catalina.filters.WebdavFixFilter</code>
+    </strong>.</p>
+
+  </subsection>
+
+  <subsection name="Initialisation parameters">
+
+    <p>The WebDAV Fix Filter does not support any initialization 
parameters.</p>
+
+  </subsection>
 
   </subsection>
 

Modified: tomcat/trunk/webapps/docs/config/valve.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/valve.xml?rev=791616&r1=791615&r2=791616&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/valve.xml (original)
+++ tomcat/trunk/webapps/docs/config/valve.xml Mon Jul  6 21:06:13 2009
@@ -449,42 +449,6 @@
 </section>
 
 
-<section name="WebDAV Fix Valve">
-
-  <subsection name="Introduction">
-
-    <p>Microsoft operating systems have two WebDAV clients. One is used with
-    port 80, the other is used for all other ports. The implementation used 
with
-    port 80 does not adhere to the WebDAV specification and fails when trying 
to
-    communicate with the Tomcat WebDAV Servlet. This valve provides a fix for
-    this by forcing the use of the WebDAV implementation that works, even when
-    connecting via port 80.</p>
-    
-    <p>This Valve may be used at the <code>Engine</code>, <code>Host</code> or
-    <code>Context</code> level as required. Normally, this Valve would be used
-    at the <code>Context</code> level.</p>
-
-  </subsection>
-
-  <subsection name="Attributes">
-
-    <p>The <strong>WebDAV Fix Valve</strong> supports the following
-    configuration attributes:</p>
-
-    <attributes>
-
-      <attribute name="className" required="true">
-        <p>Java class name of the implementation to use.  This MUST be set to
-        <strong>org.apache.catalina.valves.WebdavFixValve</strong>.</p>
-      </attribute>
-
-    </attributes>
-
-  </subsection>
-
-</section>
-
-
 <section name="Add Default Character Set Valve">
 
   <subsection name="Introduction">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to