KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > webdav > protocol > http > GetMethod


1 package com.ibm.webdav.protocol.http;
2
3 /*
4  * (C) Copyright IBM Corp. 2000 All rights reserved.
5  *
6  * The program is provided "AS IS" without any warranty express or
7  * implied, including the warranty of non-infringement and the implied
8  * warranties of merchantibility and fitness for a particular purpose.
9  * 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
25 /** Executes the WebDAV GET method.
26  * @author Jim Amsden <jamsden@us.ibm.com>
27  */

28 public class GetMethod extends WebDAVMethod {
29     
30     private static Logger m_logger = Logger.getLogger(GetMethod.class.getName());
31
32     
33     /** Construct a GetMethod.
34     * @param request the servlet request
35     * @param response the servlet response
36     * @exception com.ibm.webdav.WebDAVException
37     * @exception IOException
38     */

39     public GetMethod(HttpServletRequest request, HttpServletResponse response)
40               throws WebDAVException {
41         super(request, response);
42         methodName = "GET";
43     }
44
45     /** Execute the method.
46     * @return the result status code
47     */

48     public WebDAVStatus execute() {
49         try {
50             InputStream is = resource.getContentsInputStream(context);
51
52
53             // fill in any response headers here
54
// set the response headers and status code. This must
55
// be done before a byte is written to the output stream
56
// or the headers and status code will be lost
57
setStatusCode(WebDAVStatus.SC_OK);
58             setResponseHeaders();
59
60             // return response entity
61
int length = (int) context.getResponseContext().contentLength();
62             String JavaDoc mimeType = context.getResponseContext().contentType();
63             copy(is, response, length, mimeType);
64             is.close();
65         } catch (WebDAVException exc) {
66             m_logger.log(Level.INFO, exc.getLocalizedMessage() + " - " + request.getQueryString());
67             setStatusCode(exc.getStatusCode());
68         } catch (Exception JavaDoc exc) {
69             m_logger.log(Level.WARNING, exc.getMessage(), exc);
70             setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
71         }
72
73         return context.getStatusCode();
74     }
75 }
Popular Tags