You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2001/03/06 18:09:13 UTC
cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method GetMethod.java
juergen 01/03/06 09:09:13
Modified: src/webdav/server/org/apache/slide/webdav/method
GetMethod.java
Log:
removed a redundant get content call, which read the content in case of a head command.
Revision Changes Path
1.4 +154 -156 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/GetMethod.java
Index: GetMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/GetMethod.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GetMethod.java 2001/02/11 20:39:24 1.3
+++ GetMethod.java 2001/03/06 17:09:08 1.4
@@ -1,13 +1,13 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/GetMethod.java,v 1.3 2001/02/11 20:39:24 remm Exp $
- * $Revision: 1.3 $
- * $Date: 2001/02/11 20:39:24 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/GetMethod.java,v 1.4 2001/03/06 17:09:08 juergen Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/03/06 17:09:08 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -15,7 +15,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -23,15 +23,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
@@ -59,7 +59,7 @@
*
* [Additional notices, if required by prior licensing conditions]
*
- */
+ */
package org.apache.slide.webdav.method;
@@ -82,7 +82,7 @@
/**
* GET method.
- *
+ *
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
*/
public class GetMethod extends WebdavMethod {
@@ -142,12 +142,12 @@
/**
* GET Method constructor.
- *
+ *
* @param token Namespace access token
* @param req HTTP request
* @param resp HTTP response
*/
- public GetMethod(GenericServlet servlet, NamespaceAccessToken token,
+ public GetMethod(GenericServlet servlet, NamespaceAccessToken token,
HttpServletRequest req, HttpServletResponse resp) {
super(servlet, token, req, resp);
}
@@ -159,7 +159,7 @@
/**
* Parse XML request.
*/
- protected void parseRequest()
+ protected void parseRequest()
throws WebdavException {
resourcePath = requestUri;
if (resourcePath == null) {
@@ -170,10 +170,10 @@
/**
* Execute request.
- *
+ *
* @exception WebdavException Can't access resource
*/
- protected void executeRequest()
+ protected void executeRequest()
throws WebdavException {
try {
@@ -181,13 +181,13 @@
// Then we must get object contents ...
ObjectNode object = structure.retrieve(slideToken, resourcePath);
- NodeRevisionDescriptors revisionDescriptors =
+ NodeRevisionDescriptors revisionDescriptors =
content.retrieve(slideToken, resourcePath);
if (revisionDescriptors.hasRevisions()) {
// Retrieve latest revision descriptor
- NodeRevisionDescriptor revisionDescriptor =
+ NodeRevisionDescriptor revisionDescriptor =
content.retrieve(slideToken, revisionDescriptors);
if (isCollection(revisionDescriptor)) {
@@ -199,7 +199,7 @@
} else {
- ResourceInfo resourceInfo =
+ ResourceInfo resourceInfo =
new ResourceInfo(resourcePath, revisionDescriptor);
// Checking If headers
@@ -207,10 +207,8 @@
return;
ServletOutputStream os = resp.getOutputStream();
- NodeRevisionContent revisionContent =
- content.retrieve(slideToken, revisionDescriptors,
- revisionDescriptor);
- InputStream is = null;
+ InputStream is = null;
+
if (printContent) {
is = content.retrieve
(slideToken, revisionDescriptors,
@@ -222,10 +220,10 @@
// ETag header
resp.setHeader("ETag", getETag(resourceInfo, true));
resp.addHeader
- ("Last-Modified",
+ ("Last-Modified",
revisionDescriptor.getCreationDate().toString());
- if ( ((ranges == null) || (ranges.isEmpty()))
+ if ( ((ranges == null) || (ranges.isEmpty()))
&& (req.getHeader("Range") == null) ) {
resp.setContentType
@@ -233,7 +231,7 @@
resp.setContentLength
((int) revisionDescriptor.getContentLength());
- // Copy the input stream to our output stream
+ // Copy the input stream to our output stream
// (if requested)
if (printContent) {
resp.setBufferSize(output);
@@ -252,9 +250,9 @@
if (ranges.size() == 1) {
Range range = (Range) ranges.elementAt(0);
- resp.addHeader("Content-Range", "bytes "
+ resp.addHeader("Content-Range", "bytes "
+ range.start
- + "-" + range.end + "/"
+ + "-" + range.end + "/"
+ range.length);
resp.setContentType
(revisionDescriptor.getContentType());
@@ -272,8 +270,8 @@
if (printContent) {
resp.setBufferSize(output);
- copy(resourceInfo, is, os,
- ranges.elements(),
+ copy(resourceInfo, is, os,
+ ranges.elements(),
revisionDescriptor.getContentType());
}
@@ -296,45 +294,45 @@
// 404 - Not found
System.out.println(e.getMessage());
resp.setStatus(WebdavStatus.SC_NOT_FOUND);
- } catch (RevisionContentNotFoundException e) {
+ } catch (RevisionContentNotFoundException e) {
// 404 - Not found
System.out.println(e.getMessage());
resp.setStatus(WebdavStatus.SC_NOT_FOUND);
- } catch (ObjectLockedException e) {
+ } catch (ObjectLockedException e) {
// Locked
System.out.println(e.getMessage());
resp.setStatus(WebdavStatus.SC_LOCKED);
- } catch (RevisionDescriptorNotFoundException e) {
+ } catch (RevisionDescriptorNotFoundException e) {
// 404 - Not found
System.out.println(e.getMessage());
resp.setStatus(WebdavStatus.SC_NOT_FOUND);
- } catch (ObjectNotFoundException e) {
+ } catch (ObjectNotFoundException e) {
// 404 - Not found
System.out.println(e.getMessage());
resp.setStatus(WebdavStatus.SC_NOT_FOUND);
- } catch (LinkedObjectNotFoundException e) {
+ } catch (LinkedObjectNotFoundException e) {
// 404 - Not found
System.out.println(e.getMessage());
resp.setStatus(WebdavStatus.SC_NOT_FOUND);
- } catch (AccessDeniedException e) {
+ } catch (AccessDeniedException e) {
// 403 - Forbidden
System.out.println(e.getMessage());
resp.setStatus(WebdavStatus.SC_FORBIDDEN);
- } catch (ServiceAccessException e) {
- // 500 - Internal server error
+ } catch (ServiceAccessException e) {
+ // 500 - Internal server error
System.out.println(e.getMessage());
resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch (IOException e) {
+ throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ } catch (IOException e) {
e.printStackTrace();
// Unable to write to output stream.
- // 500 - Internal server error
+ // 500 - Internal server error
resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
} catch (RuntimeException e) {
e.printStackTrace();
- // 500 - Internal server error
+ // 500 - Internal server error
resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- }
+ }
}
@@ -342,8 +340,8 @@
/**
* Display a directory browsing page.
*/
- protected void displayDirectoryBrowsing(ObjectNode object,
- Writer servletWriter)
+ protected void displayDirectoryBrowsing(ObjectNode object,
+ Writer servletWriter)
throws IOException {
String contextPath = req.getContextPath();
@@ -383,7 +381,7 @@
// Render the link to our parent (if required)
String parentDirectory = name;
if (parentDirectory.endsWith("/")) {
- parentDirectory =
+ parentDirectory =
parentDirectory.substring(0, parentDirectory.length() - 1);
}
int slash = parentDirectory.lastIndexOf("/");
@@ -407,7 +405,7 @@
try {
- permissionsList =
+ permissionsList =
security.enumeratePermissions(slideToken, object.getUri());
locksList = lock.enumerateLocks(slideToken, object.getUri());
@@ -460,15 +458,15 @@
try {
- NodeRevisionDescriptors revisionDescriptors =
+ NodeRevisionDescriptors revisionDescriptors =
content.retrieve(slideToken, currentResource);
// Retrieve latest revision descriptor
- currentDescriptor =
+ currentDescriptor =
content.retrieve(slideToken, revisionDescriptors);
} catch (SlideException e) {
- // Silent exception : Objects without any revision are
+ // Silent exception : Objects without any revision are
// considered collections, and do not have any attributes
// Any security based exception will be trapped here
@@ -479,7 +477,7 @@
try {
- permissionsList =
+ permissionsList =
security.enumeratePermissions(slideToken, currentResource);
locksList = lock.enumerateLocks(slideToken, currentResource);
@@ -563,7 +561,7 @@
/**
* Display an ACL list.
- *
+ *
* @param permissionsList List of NodePermission objects
* @param boolean Shade
* @param writer The output will be appended to this writer
@@ -621,7 +619,7 @@
if (req.getContextPath() != null) {
writer.print(req.getContextPath());
}
- writer.print(managerServletPath + token.getName()
+ writer.print(managerServletPath + token.getName()
+ "?command=addacl\">");
writer.print(Messages.message
("org.apache.slide.webdav.GetMethod.add"));
@@ -664,7 +662,7 @@
if (req.getContextPath() != null) {
writer.print(req.getContextPath());
}
- writer.print(managerServletPath + token.getName()
+ writer.print(managerServletPath + token.getName()
+ "?command=removeacl"
+ "&object=" + currentPermission.getObjectUri()
+ "&subject=" + currentPermission.getSubjectUri()
@@ -686,7 +684,7 @@
/**
* Display a lock list.
- *
+ *
* @param locksList List of NodeLock objects
* @param boolean Shade
* @param writer The output will be appended to this writer
@@ -796,7 +794,7 @@
private String renderSize(long size) {
long leftSide = size / 1024;
- long rightSide = (size % 1024) / 103; // Makes 1 digit
+ long rightSide = (size % 1024) / 103; // Makes 1 digit
if ((leftSide == 0) && (rightSide == 0) && (size > 0))
rightSide = 1;
@@ -806,9 +804,9 @@
/**
- * Check if the conditions specified in the optional If headers are
+ * Check if the conditions specified in the optional If headers are
* satisfied.
- *
+ *
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param resourceInfo File object
@@ -817,7 +815,7 @@
* request processing is stopped
*/
private boolean checkIfHeaders(HttpServletRequest request,
- HttpServletResponse response,
+ HttpServletResponse response,
ResourceInfo resourceInfo)
throws IOException {
@@ -873,9 +871,9 @@
}
}
- if ((date != null)
+ if ((date != null)
&& (lastModified <= (date.getTime() + 1000)) ) {
- // The entity has not been modified since the date
+ // The entity has not been modified since the date
// specified by the client. This is not an error case.
response.sendError
(HttpServletResponse.SC_NOT_MODIFIED);
@@ -902,7 +900,7 @@
if (conditionSatisfied) {
- // For GET and HEAD, we should respond with
+ // For GET and HEAD, we should respond with
// 304 Not Modified.
// For every other method, 412 Precondition Failed is sent
// back.
@@ -941,7 +939,7 @@
}
if ( (date != null) && (lastModified > date.getTime()) ) {
- // The entity has not been modified since the date
+ // The entity has not been modified since the date
// specified by the client. This is not an error case.
response.sendError
(HttpServletResponse.SC_PRECONDITION_FAILED);
@@ -956,7 +954,7 @@
/**
* Get the ETag value associated with a file.
- *
+ *
* @param resourceInfo File object
* @param strong True if we want a strong ETag, in which case a checksum
* of the file has to be calculated
@@ -970,7 +968,7 @@
/**
* Get the ETag associated with a file.
- *
+ *
* @param resourceInfo File object
* @param strong True if we want a strong ETag, in which case a checksum
* of the file has to be calculated
@@ -993,10 +991,10 @@
*
* @exception IOException if an input/output error occurs
*/
- private void copy(ResourceInfo resourceInfo,
- InputStream resourceInputStream,
+ private void copy(ResourceInfo resourceInfo,
+ InputStream resourceInputStream,
ServletOutputStream ostream)
- throws IOException {
+ throws IOException {
IOException exception = null;
@@ -1013,20 +1011,20 @@
;
}
- try {
- ostream.flush();
- } catch (Throwable t) {
- ;
- }
- try {
- ostream.close();
- } catch (Throwable t) {
- ;
- }
-
- // Rethrow any exception that has occurred
- if (exception != null)
- throw exception;
+ try {
+ ostream.flush();
+ } catch (Throwable t) {
+ ;
+ }
+ try {
+ ostream.close();
+ } catch (Throwable t) {
+ ;
+ }
+
+ // Rethrow any exception that has occurred
+ if (exception != null)
+ throw exception;
}
@@ -1041,11 +1039,11 @@
* @param range Range the client wanted to retrieve
* @exception IOException if an input/output error occurs
*/
- private void copy(ResourceInfo resourceInfo,
- InputStream resourceInputStream,
- ServletOutputStream ostream,
+ private void copy(ResourceInfo resourceInfo,
+ InputStream resourceInputStream,
+ ServletOutputStream ostream,
Range range)
- throws IOException {
+ throws IOException {
IOException exception = null;
@@ -1053,26 +1051,26 @@
new BufferedInputStream(resourceInputStream, input);
exception = copyRange(istream, ostream, range.start, range.end);
- // Clean up the input and output streams
- try {
- istream.close();
- } catch (Throwable t) {
- ;
- }
- try {
- ostream.flush();
- } catch (Throwable t) {
- ;
- }
- try {
- ostream.close();
- } catch (Throwable t) {
- ;
- }
-
- // Rethrow any exception that has occurred
- if (exception != null)
- throw exception;
+ // Clean up the input and output streams
+ try {
+ istream.close();
+ } catch (Throwable t) {
+ ;
+ }
+ try {
+ ostream.flush();
+ } catch (Throwable t) {
+ ;
+ }
+ try {
+ ostream.close();
+ } catch (Throwable t) {
+ ;
+ }
+
+ // Rethrow any exception that has occurred
+ if (exception != null)
+ throw exception;
}
@@ -1088,17 +1086,17 @@
* @param contentType Content type of the resource
* @exception IOException if an input/output error occurs
*/
- private void copy(ResourceInfo resourceInfo,
- InputStream resourceInputStream,
+ private void copy(ResourceInfo resourceInfo,
+ InputStream resourceInputStream,
ServletOutputStream ostream,
Enumeration ranges, String contentType)
- throws IOException {
+ throws IOException {
IOException exception = null;
while ( (exception == null) && (ranges.hasMoreElements()) ) {
- InputStream istream =
+ InputStream istream =
new BufferedInputStream(resourceInputStream, input);
Range currentRange = (Range) ranges.nextElement();
@@ -1108,7 +1106,7 @@
if (contentType != null)
ostream.println("Content-Type: " + contentType);
ostream.println("Content-Range: bytes " + currentRange.start
- + "-" + currentRange.end + "/"
+ + "-" + currentRange.end + "/"
+ currentRange.length);
ostream.println();
@@ -1126,21 +1124,21 @@
ostream.print("--" + mimeSeparation + "--");
- // Clean up the output streams
- try {
- ostream.flush();
- } catch (Throwable t) {
- ;
- }
- try {
- ostream.close();
- } catch (Throwable t) {
- ;
- }
-
- // Rethrow any exception that has occurred
- if (exception != null)
- throw exception;
+ // Clean up the output streams
+ try {
+ ostream.flush();
+ } catch (Throwable t) {
+ ;
+ }
+ try {
+ ostream.close();
+ } catch (Throwable t) {
+ ;
+ }
+
+ // Rethrow any exception that has occurred
+ if (exception != null)
+ throw exception;
}
@@ -1154,25 +1152,25 @@
* @param ostream The output stream to write to
* @return Exception which occured during processing
*/
- private IOException copyRange(InputStream istream,
+ private IOException copyRange(InputStream istream,
ServletOutputStream ostream) {
- // Copy the input stream to the output stream
- IOException exception = null;
- byte buffer[] = new byte[input];
- int len = buffer.length;
- while (true) {
- try {
+ // Copy the input stream to the output stream
+ IOException exception = null;
+ byte buffer[] = new byte[input];
+ int len = buffer.length;
+ while (true) {
+ try {
len = istream.read(buffer);
if (len == -1)
break;
ostream.write(buffer, 0, len);
- } catch (IOException e) {
- exception = e;
- len = -1;
+ } catch (IOException e) {
+ exception = e;
+ len = -1;
break;
- }
- }
+ }
+ }
return exception;
}
@@ -1189,7 +1187,7 @@
* @param end End of the range which will be copied
* @return Exception which occured during processing
*/
- private IOException copyRange(InputStream istream,
+ private IOException copyRange(InputStream istream,
ServletOutputStream ostream,
long start, long end) {
@@ -1199,28 +1197,28 @@
return e;
}
- IOException exception = null;
+ IOException exception = null;
long bytesToRead = end - start + 1;
- byte buffer[] = new byte[input];
- int len = buffer.length;
- while ( (bytesToRead > 0) && (len >= buffer.length)) {
- try {
+ byte buffer[] = new byte[input];
+ int len = buffer.length;
+ while ( (bytesToRead > 0) && (len >= buffer.length)) {
+ try {
len = istream.read(buffer);
if (bytesToRead >= len) {
ostream.write(buffer, 0, len);
- bytesToRead -= len;
+ bytesToRead -= len;
} else {
ostream.write(buffer, 0, (int) bytesToRead);
bytesToRead = 0;
}
- } catch (IOException e) {
- exception = e;
- len = -1;
- }
- if (len < buffer.length)
- break;
- }
+ } catch (IOException e) {
+ exception = e;
+ len = -1;
+ }
+ if (len < buffer.length)
+ break;
+ }
return exception;
@@ -1229,14 +1227,14 @@
/**
* Parse the range header.
- *
+ *
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @return Vector of ranges
*/
- private Vector parseRange(HttpServletRequest request,
- HttpServletResponse response,
- ResourceInfo resourceInfo)
+ private Vector parseRange(HttpServletRequest request,
+ HttpServletResponse response,
+ ResourceInfo resourceInfo)
throws IOException {
// Checking If-Range
@@ -1390,7 +1388,7 @@
/**
* Constructor.
- *
+ *
* @param pathname Path name of the file
*/
public ResourceInfo(String path, NodeRevisionDescriptor properties) {