01: package com.ibm.webdav.protocol.http;
02:
03: /*
04: * (C) Copyright IBM Corp. 2000 All rights reserved.
05: *
06: * The program is provided "AS IS" without any warranty express or
07: * implied, including the warranty of non-infringement and the implied
08: * warranties of merchantibility and fitness for a particular purpose.
09: * IBM will not be liable for any damages suffered by you as a result
10: * of using the Program. In no event will IBM be liable for any
11: * special, indirect or consequential damages or lost profits even if
12: * IBM has been advised of the possibility of their occurrence. IBM
13: * will not be liable for any third party claims against you.
14: *
15: * Portions Copyright (C) Simulacra Media Ltd, 2004.
16: */
17: import java.io.*;
18: import java.util.logging.*;
19:
20: import javax.servlet.http.*;
21:
22: import com.ibm.webdav.*;
23:
24: /** Executes the WebDAV GET method.
25: * @author Jim Amsden <jamsden@us.ibm.com>
26: */
27: public class GetMethod extends WebDAVMethod {
28:
29: private static Logger m_logger = Logger.getLogger(GetMethod.class
30: .getName());
31:
32: /** Construct a GetMethod.
33: * @param request the servlet request
34: * @param response the servlet response
35: * @exception com.ibm.webdav.WebDAVException
36: * @exception IOException
37: */
38: public GetMethod(HttpServletRequest request,
39: HttpServletResponse response) throws WebDAVException {
40: super (request, response);
41: methodName = "GET";
42: }
43:
44: /** Execute the method.
45: * @return the result status code
46: */
47: public WebDAVStatus execute() {
48: try {
49: InputStream is = resource.getContentsInputStream(context);
50:
51: // fill in any response headers here
52: // set the response headers and status code. This must
53: // be done before a byte is written to the output stream
54: // or the headers and status code will be lost
55: setStatusCode(WebDAVStatus.SC_OK);
56: setResponseHeaders();
57:
58: // return response entity
59: int length = (int) context.getResponseContext()
60: .contentLength();
61: String mimeType = context.getResponseContext()
62: .contentType();
63: copy(is, response, length, mimeType);
64: is.close();
65: } catch (WebDAVException exc) {
66: m_logger.log(Level.INFO, exc.getLocalizedMessage() + " - "
67: + request.getQueryString());
68: setStatusCode(exc.getStatusCode());
69: } catch (Exception exc) {
70: m_logger.log(Level.WARNING, exc.getMessage(), exc);
71: setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
72: }
73:
74: return context.getStatusCode();
75: }
76: }
|