KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** 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.getName());
30
31 /** Construct a PutMethod.
32 * @param request the servlet request
33 * @param response the servlet response
34 * @exception com.ibm.webdav.WebDAVException
35 */

36 public PutMethod(HttpServletRequest request, HttpServletResponse response) throws WebDAVException {
37     super(request, response);
38     methodName = "PUT";
39 }
40 /** Execute the method.
41 * @return the result status code
42 */

43 public WebDAVStatus execute() {
44     try {
45         OutputStream os = resource.getContentsOutputStream(context);
46
47         // attempt to write the request entity body to the resource
48
int length = (int) context.getRequestContext().contentLength();
49         String JavaDoc mimeType = context.getRequestContext().contentType();
50         if (mimeType==null) {
51             // (http 1.1, sec 7.2.1)
52
// the client SHOULD specify this. If they don't
53
// we are allowed to guess. If we can't guess based
54
// on the content or name, we are to assume...
55
mimeType = "application/octet-stream";
56         }
57         copy(request, os, length, mimeType);
58         resource.closeContentsOutputStream(context);
59         setResponseHeaders();
60         setStatusCode(WebDAVStatus.SC_OK);
61     } catch (WebDAVException exc) {
62         m_logger.log(Level.INFO, exc.getMessage() + " - " + request.getQueryString());
63         setStatusCode(exc.getStatusCode());
64     } catch (Exception JavaDoc exc) {
65         m_logger.log(Level.WARNING, exc.getMessage(), exc);
66         setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
67     }
68     return context.getStatusCode();
69 }
70 }
71
Popular Tags