1 package com.ibm.webdav.protocol.http; 2 3 17 import java.io.*; 18 import java.net.*; 19 20 33 public class WebDAVURLConnection extends sun.net.www.protocol.http.HttpURLConnection { 34 35 private static final String [] methods = {"GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "MKCOL", "COPY", "MOVE", "PROPFIND", "PROPPATCH", "LOCK", "UNLOCK","SEARCH"}; 37 39 private static WebDAVAuthenticator defaultAuth; 40 protected WebDAVURLConnection(URL u, Handler handler) throws IOException { 41 super(u, handler); 42 } 43 public WebDAVURLConnection(URL u, String host, int port) throws IOException { 44 super(u, host, port); 45 } 46 52 53 public synchronized InputStream getInputStream() throws IOException { 54 InputStream is = null; 55 try { 56 is = super.getInputStream(); 57 } catch (IOException exc) { 58 } 61 return is; 62 } 63 67 68 public synchronized OutputStream getOutputStream() throws IOException { 69 OutputStream os = null; 70 String savedMethod = method; 71 if (method.equals("GET") || method.equals("PUT") || method.equals("POST") || 73 method.equals("PROPFIND") || method.equals("PROPPATCH") || 74 method.equals("MKCOL") || method.equals("MOVE") || method.equals("COPY") || 75 method.equals("LOCK")) { 76 method = "PUT"; 78 } else { 79 method = "DELETE"; 82 } 83 os = super.getOutputStream(); 84 method = savedMethod; 85 return os; 86 } 87 108 public void setRequestMethod(String method) throws ProtocolException { 109 if (connected) { 110 throw new ProtocolException("Cannot reset method once connected"); 111 } 112 for (int i = 0; i < methods.length; i++) { 116 if (methods[i].equals(method)) { 117 this.method = method; 118 return; 119 } 120 } 121 throw new ProtocolException("Invalid WebDAV method: " + method); 122 } 123 } 124 | Popular Tags |