funkman 2004/09/18 18:20:10
Modified: catalina/src/share/org/apache/catalina/servlets
DefaultServlet.java WebdavServlet.java
Log:
md5Helper, md5Encoder, and normalize are used by WebdavServlet,
not DefaultServelt so move them into WebdavServlet.
Remove unused method appendParameters
Revision Changes Path
1.28 +16 -120
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java
Index: DefaultServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- DefaultServlet.java 29 Aug 2004 16:46:12 -0000 1.27
+++ DefaultServlet.java 19 Sep 2004 01:20:10 -0000 1.28
@@ -1,12 +1,12 @@
/*
* Copyright 1999,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.
@@ -32,8 +32,6 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -56,7 +54,6 @@
import javax.xml.transform.stream.StreamSource;
import org.apache.catalina.Globals;
-import org.apache.catalina.util.MD5Encoder;
import org.apache.catalina.util.ServerInfo;
import org.apache.catalina.util.StringManager;
import org.apache.catalina.util.URLEncoder;
@@ -113,18 +110,6 @@
/**
- * MD5 message digest provider.
- */
- protected static MessageDigest md5Helper;
-
-
- /**
- * The MD5 helper object for this class.
- */
- protected static final MD5Encoder md5Encoder = new MD5Encoder();
-
-
- /**
* Array containing the safe characters set.
*/
protected static URLEncoder urlEncoder;
@@ -259,13 +244,6 @@
", output buffer size=" + output);
}
- // Load the MD5 helper used to calculate signatures.
- try {
- md5Helper = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- throw new UnavailableException("No MD5");
- }
-
// Load the proxy dir context.
try {
resources = (ProxyDirContext) getServletContext()
@@ -288,7 +266,7 @@
if (resources == null) {
throw new UnavailableException("No resources");
}
-
+
}
@@ -345,7 +323,7 @@
serveResource(request, response, true);
} catch( IOException ex ) {
// we probably have this check somewhere else too.
- if( ex.getMessage() != null
+ if( ex.getMessage() != null
&& ex.getMessage().indexOf("Broken pipe") >= 0 ) {
// ignore it.
}
@@ -619,71 +597,6 @@
/**
- * Return a context-relative path, beginning with a "/", that represents
- * the canonical version of the specified path after ".." and "." elements
- * are resolved out. If the specified path attempts to go outside the
- * boundaries of the current context (i.e. too many ".." path elements
- * are present), return <code>null</code> instead.
- *
- * @param path Path to be normalized
- */
- protected String normalize(String path) {
-
- if (path == null)
- return null;
-
- // Create a place for the normalized path
- String normalized = path;
-
- if (normalized == null)
- return (null);
-
- if (normalized.equals("/."))
- return "/";
-
- // Normalize the slashes and add leading slash if necessary
- if (normalized.indexOf('\\') >= 0)
- normalized = normalized.replace('\\', '/');
- if (!normalized.startsWith("/"))
- normalized = "/" + normalized;
-
- // Resolve occurrences of "//" in the normalized path
- while (true) {
- int index = normalized.indexOf("//");
- if (index < 0)
- break;
- normalized = normalized.substring(0, index) +
- normalized.substring(index + 1);
- }
-
- // Resolve occurrences of "/./" in the normalized path
- while (true) {
- int index = normalized.indexOf("/./");
- if (index < 0)
- break;
- normalized = normalized.substring(0, index) +
- normalized.substring(index + 2);
- }
-
- // Resolve occurrences of "/../" in the normalized path
- while (true) {
- int index = normalized.indexOf("/../");
- if (index < 0)
- break;
- if (index == 0)
- return (null); // Trying to go outside our context
- int index2 = normalized.lastIndexOf('/', index - 1);
- normalized = normalized.substring(0, index2) +
- normalized.substring(index + 3);
- }
-
- // Return the normalized path that we have completed
- return (normalized);
-
- }
-
-
- /**
* URL rewriter.
*
* @param path Path which has to be rewiten
@@ -798,17 +711,17 @@
response.setHeader("ETag", getETag(cacheEntry.attributes));
// Last-Modified header
- response.setHeader("Last-Modified",
+ response.setHeader("Last-Modified",
cacheEntry.attributes.getLastModifiedHttp());
// Get content length
contentLength = cacheEntry.attributes.getContentLength();
- // Special case for zero length files, which would cause a
+ // Special case for zero length files, which would cause a
// (silent) ISE when setting the output buffer size
if (contentLength == 0L) {
content = false;
}
-
+
}
ServletOutputStream ostream = null;
@@ -856,7 +769,7 @@
if (content) {
// Serve the directory browser
- renderResult =
+ renderResult =
render(request.getContextPath(), cacheEntry);
}
@@ -1141,23 +1054,6 @@
}
- /**
- * Append the request parameters to the redirection string before calling
- * sendRedirect.
- */
- protected String appendParameters(HttpServletRequest request,
- String redirectPath) {
-
- StringBuffer result = new StringBuffer(rewriteUrl(redirectPath));
-
- String query = request.getQueryString ();
- if (query != null)
- result.append ("?").append (query);
-
- return result.toString();
-
- }
-
/**
* Decide which way to render. HTML or XML.
@@ -1497,7 +1393,7 @@
* Return the xsl template inputstream (if possible)
*/
protected InputStream findXsltInputStream(DirContext directory) {
-
+
if (localXsltFile!=null) {
try {
Object obj = directory.lookup(localXsltFile);
@@ -1544,7 +1440,7 @@
}
-
+
// -------------------------------------------------------- Private Methods
@@ -1726,17 +1622,17 @@
* output stream, and ensure that both streams are closed before returning
* (even in the face of an exception).
*
- * @param resourceInfo The resource information
+ * @param resourceInfo The resource information
* @param ostream The output stream to write to
*
* @exception IOException if an input/output error occurs
*/
- private void copy(CacheEntry cacheEntry, InputStream is,
+ private void copy(CacheEntry cacheEntry, InputStream is,
ServletOutputStream ostream)
throws IOException {
IOException exception = null;
- InputStream resourceInputStream = null;
+ InputStream resourceInputStream = null;
// Optimization: If the binary content has already been loaded, send
// it directly
@@ -1901,7 +1797,7 @@
while ( (exception == null) && (ranges.hasMoreElements()) ) {
InputStream resourceInputStream = cacheEntry.resource.streamContent();
- InputStream istream =
+ InputStream istream =
new BufferedInputStream(resourceInputStream, input);
Range currentRange = (Range) ranges.nextElement();
1.19 +111 -21
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java
Index: WebdavServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets/WebdavServlet.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- WebdavServlet.java 16 Sep 2004 23:19:54 -0000 1.18
+++ WebdavServlet.java 19 Sep 2004 01:20:10 -0000 1.19
@@ -1,12 +1,12 @@
/*
* Copyright 1999,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.
@@ -21,6 +21,8 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
@@ -34,6 +36,7 @@
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
@@ -41,6 +44,7 @@
import javax.xml.parsers.ParserConfigurationException;
import org.apache.catalina.util.DOMWriter;
+import org.apache.catalina.util.MD5Encoder;
import org.apache.catalina.util.RequestUtil;
import org.apache.catalina.util.XMLWriter;
import org.apache.naming.resources.CacheEntry;
@@ -55,6 +59,7 @@
import org.xml.sax.SAXException;
+
/**
* Servlet which adds support for WebDAV level 2. All the basic HTTP requests
* are handled by the DefaultServlet.
@@ -68,7 +73,7 @@
// -------------------------------------------------------------- Constants
-
+
private static final String METHOD_HEAD = "HEAD";
private static final String METHOD_PROPFIND = "PROPFIND";
@@ -141,6 +146,19 @@
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+ /**
+ * MD5 message digest provider.
+ */
+ protected static MessageDigest md5Helper;
+
+
+ /**
+ * The MD5 helper object for this class.
+ */
+ protected static final MD5Encoder md5Encoder = new MD5Encoder();
+
+
+
static {
creationDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
}
@@ -204,6 +222,14 @@
;
}
+
+ // Load the MD5 helper used to calculate signatures.
+ try {
+ md5Helper = MessageDigest.getInstance("MD5");
+ } catch (NoSuchAlgorithmException e) {
+ throw new UnavailableException("No MD5");
+ }
+
}
@@ -301,7 +327,7 @@
throws ServletException, IOException {
resp.addHeader("DAV", "1,2");
-
+
StringBuffer methodsAllowed = determineMethodsAllowed(resources,
req);
@@ -321,7 +347,7 @@
// Get allowed methods
StringBuffer methodsAllowed = determineMethodsAllowed(resources,
req);
-
+
resp.addHeader("Allow", methodsAllowed.toString());
resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
return;
@@ -441,7 +467,7 @@
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
resp.setContentType("text/xml; charset=UTF-8");
// Create multistatus object
- XMLWriter generatedXML =
+ XMLWriter generatedXML =
new XMLWriter(resp.getWriter());
generatedXML.writeXMLHeader();
generatedXML.writeElement
@@ -525,7 +551,7 @@
// collection
String lockPath = currentPath;
if (lockPath.endsWith("/"))
- lockPath =
+ lockPath =
lockPath.substring(0, lockPath.length() - 1);
Vector currentLockNullResources =
(Vector) lockNullResources.get(lockPath);
@@ -622,7 +648,7 @@
// Get allowed methods
StringBuffer methodsAllowed = determineMethodsAllowed(resources,
req);
-
+
resp.addHeader("Allow", methodsAllowed.toString());
resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
@@ -634,7 +660,7 @@
try {
Document document = documentBuilder.parse
(new InputSource(req.getInputStream()));
- // TODO : Process this request body
+ // TODO : Process this request body
resp.sendError(WebdavStatus.SC_NOT_IMPLEMENTED);
return;
@@ -798,7 +824,7 @@
// If multiple timeouts, just use the first
if (commaPos != -1) {
lockDurationStr = lockDurationStr.substring(0,commaPos);
- }
+ }
if (lockDurationStr.startsWith("Second-")) {
lockDuration =
(new Integer(lockDurationStr.substring(7))).intValue();
@@ -1309,6 +1335,70 @@
}
+ /**
+ * Return a context-relative path, beginning with a "/", that represents
+ * the canonical version of the specified path after ".." and "." elements
+ * are resolved out. If the specified path attempts to go outside the
+ * boundaries of the current context (i.e. too many ".." path elements
+ * are present), return <code>null</code> instead.
+ *
+ * @param path Path to be normalized
+ */
+ protected String normalize(String path) {
+
+ if (path == null)
+ return null;
+
+ // Create a place for the normalized path
+ String normalized = path;
+
+ if (normalized == null)
+ return (null);
+
+ if (normalized.equals("/."))
+ return "/";
+
+ // Normalize the slashes and add leading slash if necessary
+ if (normalized.indexOf('\\') >= 0)
+ normalized = normalized.replace('\\', '/');
+ if (!normalized.startsWith("/"))
+ normalized = "/" + normalized;
+
+ // Resolve occurrences of "//" in the normalized path
+ while (true) {
+ int index = normalized.indexOf("//");
+ if (index < 0)
+ break;
+ normalized = normalized.substring(0, index) +
+ normalized.substring(index + 1);
+ }
+
+ // Resolve occurrences of "/./" in the normalized path
+ while (true) {
+ int index = normalized.indexOf("/./");
+ if (index < 0)
+ break;
+ normalized = normalized.substring(0, index) +
+ normalized.substring(index + 2);
+ }
+
+ // Resolve occurrences of "/../" in the normalized path
+ while (true) {
+ int index = normalized.indexOf("/../");
+ if (index < 0)
+ break;
+ if (index == 0)
+ return (null); // Trying to go outside our context
+ int index2 = normalized.lastIndexOf('/', index - 1);
+ normalized = normalized.substring(0, index2) +
+ normalized.substring(index + 3);
+ }
+
+ // Return the normalized path that we have completed
+ return (normalized);
+
+ }
+
// -------------------------------------------------------- Private Methods
@@ -1457,7 +1547,7 @@
if (firstSeparator < 0) {
destinationPath = "/";
} else {
- destinationPath =
+ destinationPath =
destinationPath.substring(firstSeparator);
}
}
@@ -1776,7 +1866,7 @@
Enumeration enumeration = null;
try {
- enumeration = resources.list(path);
+ enumeration = resources.list(path);
} catch (NamingException e) {
errorList.put(path, new Integer
(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
@@ -1952,7 +2042,7 @@
(null, "getcontentlength",
String.valueOf(cacheEntry.attributes.getContentLength()));
String contentType = getServletContext().getMimeType
- (cacheEntry.name);
+ (cacheEntry.name);
if (contentType != null) {
generatedXML.writeProperty(null, "getcontenttype",
contentType);
@@ -2495,11 +2585,11 @@
/**
* Determines the methods normally allowed for the resource.
- *
+ *
*/
private StringBuffer determineMethodsAllowed(DirContext resources,
HttpServletRequest req) {
-
+
StringBuffer methodsAllowed = new StringBuffer();
boolean exists = true;
Object object = null;
@@ -2518,15 +2608,15 @@
methodsAllowed.append("OPTIONS, GET, HEAD, POST, DELETE, TRACE");
methodsAllowed.append(", PROPPATCH, COPY, MOVE, LOCK, UNLOCK");
-
+
if (listings) {
methodsAllowed.append(", PROPFIND");
}
-
+
if (!(object instanceof DirContext)) {
methodsAllowed.append(", PUT");
}
-
+
return methodsAllowed;
}
@@ -2575,7 +2665,7 @@
result += "Scope:" + scope + "\n";
result += "Depth:" + depth + "\n";
result += "Owner:" + owner + "\n";
- result += "Expiration:"
+ result += "Expiration:"
+ FastHttpDateFormat.formatDate(expiresAt, null) + "\n";
Enumeration tokensList = tokens.elements();
while (tokensList.hasMoreElements()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]