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 PUT method.
25: * @author Jim Amsden <jamsden@us.ibm.com>
26: */
27: public class PutMethod extends WebDAVMethod {
28:
29: private static Logger m_logger = Logger.getLogger(PutMethod.class
30: .getName());
31:
32: /** Construct a PutMethod.
33: * @param request the servlet request
34: * @param response the servlet response
35: * @exception com.ibm.webdav.WebDAVException
36: */
37: public PutMethod(HttpServletRequest request,
38: HttpServletResponse response) throws WebDAVException {
39: super (request, response);
40: methodName = "PUT";
41: }
42:
43: /** Execute the method.
44: * @return the result status code
45: */
46: public WebDAVStatus execute() {
47: try {
48: OutputStream os = resource.getContentsOutputStream(context);
49:
50: // attempt to write the request entity body to the resource
51: int length = (int) context.getRequestContext()
52: .contentLength();
53: String mimeType = context.getRequestContext().contentType();
54: if (mimeType == null) {
55: // (http 1.1, sec 7.2.1)
56: // the client SHOULD specify this. If they don't
57: // we are allowed to guess. If we can't guess based
58: // on the content or name, we are to assume...
59: mimeType = "application/octet-stream";
60: }
61: copy(request, os, length, mimeType);
62: resource.closeContentsOutputStream(context);
63: setResponseHeaders();
64: setStatusCode(WebDAVStatus.SC_OK);
65: } catch (WebDAVException exc) {
66: m_logger.log(Level.INFO, exc.getMessage() + " - "
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: return context.getStatusCode();
74: }
75: }
|