From: markt Date: Mon, 6 Jul 2009 21:06:13 +0000 (+0000) Subject: Convert the WebDAV fix valve to a filter. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ef26226941125f07be06836573babeebc7e5f651;p=tomcat7.0 Convert the WebDAV fix valve to a filter. Based on a patch provided by Xie Xiaodong as part of GSOC 2009 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@791616 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/filters/WebdavFixFilter.java b/java/org/apache/catalina/filters/WebdavFixFilter.java new file mode 100644 index 000000000..2afb04fbc --- /dev/null +++ b/java/org/apache/catalina/filters/WebdavFixFilter.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.catalina.filters; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * 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: + * + * + * 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 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. + */ + @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(HttpServletRequest request) { + StringBuffer location = + new StringBuffer(request.getRequestURL().length()); + location.append(request.getScheme()); + location.append("://"); + 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 + // problems with BASIC authentication + location.append(request.getServerPort()); + location.append(request.getRequestURI()); + return location.toString(); + } + +} diff --git a/java/org/apache/catalina/valves/WebdavFixValve.java b/java/org/apache/catalina/valves/WebdavFixValve.java deleted file mode 100644 index f38d5c867..000000000 --- a/java/org/apache/catalina/valves/WebdavFixValve.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.catalina.valves; - -import java.io.IOException; - -import javax.servlet.ServletException; - -import org.apache.catalina.valves.ValveBase; -import org.apache.catalina.connector.Request; -import org.apache.catalina.connector.Response; - -/** - * Valve 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: - * - * To use this valve add the following <Valve - * className="org.apache.catalina.valves.WebdavFixValve" /> - * to your Engine, Host or Context as - * required. Normally, this valve would be used at the Context - * level. - * - * @version $Revision$, $Date$ - */ - -public class WebdavFixValve - extends ValveBase { - - /** - * 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); - } - } - - private String buildRedirect(Request request) { - StringBuffer location = - new StringBuffer(request.getRequestURL().length()); - location.append(request.getScheme()); - location.append("://"); - location.append(request.getHost().getName()); - 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 - // problems with BASIC authentication - location.append(request.getServerPort()); - location.append(request.getRequestURI()); - return location.toString(); - } -} diff --git a/webapps/docs/config/filter.xml b/webapps/docs/config/filter.xml index 99a329a92..d1875bb0b 100644 --- a/webapps/docs/config/filter.xml +++ b/webapps/docs/config/filter.xml @@ -77,7 +77,39 @@

The Add Default Character Set Filter does not support any initialization - parameters

+ parameters.

+ +
+ + + + +
+ + + +

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.

+ +
+ + + +

The filter class name for the WebDAV Fix Filter is + org.apache.catalina.filters.WebdavFixFilter + .

+ +
+ + + +

The WebDAV Fix Filter does not support any initialization parameters.

+ +
diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml index 955731722..f1b0cfdfa 100644 --- a/webapps/docs/config/valve.xml +++ b/webapps/docs/config/valve.xml @@ -449,42 +449,6 @@
-
- - - -

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.

- -

This Valve may be used at the Engine, Host or - Context level as required. Normally, this Valve would be used - at the Context level.

- -
- - - -

The WebDAV Fix Valve supports the following - configuration attributes:

- - - - -

Java class name of the implementation to use. This MUST be set to - org.apache.catalina.valves.WebdavFixValve.

-
- -
- -
- -
- -