1 17 package org.columba.core.url.http; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.OutputStream ; 22 import java.net.ProtocolException ; 23 import java.net.URL ; 24 import java.security.Permission ; 25 import java.util.Map ; 26 import java.util.logging.Logger ; 27 28 import org.columba.core.connectionstate.ConnectionStateImpl; 29 30 36 public class HttpURLConnection extends java.net.HttpURLConnection { 37 private static final Logger LOG = Logger 38 .getLogger("org.columba.core.url.http"); 39 40 protected java.net.HttpURLConnection connection; 41 42 public HttpURLConnection(URL u, java.net.HttpURLConnection connection) { 43 super(u); 44 this.connection = connection; 45 connection.setUseCaches(false); 46 connection.setDefaultUseCaches(false); 47 } 48 49 52 protected void ensureConnectionAllowed() throws IOException { 53 if (!ConnectionStateImpl.getInstance().isOnline()) { 54 LOG.fine("Blocking HTTP connection to " + getURL().toString()); 55 throw new IOException ("Error while connecting."); 56 } 57 } 58 59 public OutputStream getOutputStream() throws IOException { 60 ensureConnectionAllowed(); 61 return connection.getOutputStream(); 62 } 63 64 public void setDefaultUseCaches(boolean param) {} 65 66 public long getIfModifiedSince() { 67 return connection.getIfModifiedSince(); 68 } 69 70 public String getResponseMessage() throws IOException { 71 if (!ConnectionStateImpl.getInstance().isOnline()) { 72 return "Not Found"; 73 } else { 74 return connection.getResponseMessage(); 75 } 76 } 77 78 public Permission getPermission() throws IOException { 79 return connection.getPermission(); 80 } 81 82 public void setUseCaches(boolean param) {} 83 84 public void addRequestProperty(String str, String str1) { 85 connection.addRequestProperty(str, str1); 86 } 87 88 public boolean getInstanceFollowRedirects() { 89 return connection.getInstanceFollowRedirects(); 90 } 91 92 public Map getRequestProperties() { 93 return connection.getRequestProperties(); 94 } 95 96 public void setRequestMethod(String str) throws ProtocolException { 97 super.setRequestMethod(str); 98 } 99 100 public boolean getDefaultUseCaches() { 101 return connection.getDefaultUseCaches(); 102 } 103 104 public String getRequestMethod() { 105 return connection.getRequestMethod(); 106 } 107 108 public boolean getDoOutput() { 109 return connection.getDoOutput(); 110 } 111 112 public long getDate() { 113 return connection.getDate(); 114 } 115 116 public int getResponseCode() throws IOException { 117 if (!ConnectionStateImpl.getInstance().isOnline()) { 118 return HTTP_NOT_FOUND; 119 } else { 120 return connection.getResponseCode(); 121 } 122 } 123 124 public long getHeaderFieldDate(String str, long param) { 125 return connection.getHeaderFieldDate(str, param); 126 } 127 128 public boolean usingProxy() { 129 return connection.usingProxy(); 130 } 131 132 public void setRequestProperty(String str, String str1) { 133 connection.setRequestProperty(str, str1); 134 } 135 136 public String getHeaderField(int param) { 137 return connection.getHeaderField(param); 138 } 139 140 public void setAllowUserInteraction(boolean param) { 141 super.setAllowUserInteraction(param); 142 } 143 144 public String getHeaderField(String str) { 145 return connection.getHeaderField(str); 146 } 147 148 public InputStream getErrorStream() { 149 return connection.getErrorStream(); 150 } 151 152 public Object getContent(Class [] clazz) throws IOException { 153 ensureConnectionAllowed(); 154 return connection.getContent(clazz); 155 } 156 157 public void disconnect() { 158 connection.disconnect(); 159 } 160 161 public String getHeaderFieldKey(int param) { 162 return connection.getHeaderFieldKey(param); 163 } 164 165 public long getExpiration() { 166 return connection.getExpiration(); 167 } 168 169 public void setDoInput(boolean param) { 170 connection.setDoInput(param); 171 } 172 173 public Object getContent() throws IOException { 174 ensureConnectionAllowed(); 175 return connection.getContent(); 176 } 177 178 public boolean getUseCaches() { 179 return connection.getUseCaches(); 180 } 181 182 public long getLastModified() { 183 return connection.getLastModified(); 184 } 185 186 public boolean getDoInput() { 187 return connection.getDoInput(); 188 } 189 190 public String getContentType() { 191 return connection.getContentType(); 192 } 193 194 public Map getHeaderFields() { 195 return connection.getHeaderFields(); 196 } 197 198 public void setDoOutput(boolean param) { 199 connection.setDoOutput(param); 200 } 201 202 public InputStream getInputStream() throws IOException { 203 ensureConnectionAllowed(); 204 return connection.getInputStream(); 205 } 206 207 public String getRequestProperty(String str) { 208 return connection.getRequestProperty(str); 209 } 210 211 public int getHeaderFieldInt(String str, int param) { 212 return connection.getHeaderFieldInt(str, param); 213 } 214 215 public void setInstanceFollowRedirects(boolean param) { 216 connection.setInstanceFollowRedirects(param); 217 } 218 219 public void setIfModifiedSince(long param) { 220 connection.setIfModifiedSince(param); 221 } 222 223 public String getContentEncoding() { 224 return connection.getContentEncoding(); 225 } 226 227 public void connect() throws IOException { 228 ensureConnectionAllowed(); 229 connection.connect(); 230 } 231 232 public int getContentLength() { 233 return connection.getContentLength(); 234 } 235 236 public boolean getAllowUserInteraction() { 237 return connection.getAllowUserInteraction(); 238 } 239 } 240 | Popular Tags |