1 31 32 package org.apache.commons.httpclient.util; 33 34 import org.apache.commons.httpclient.HttpMethod; 35 import org.apache.commons.httpclient.Header; 36 37 import org.apache.commons.logging.LogFactory; 38 import org.apache.commons.logging.Log; 39 import java.io.IOException ; 40 import java.io.InputStream ; 41 import java.io.OutputStream ; 42 import java.net.URL ; 43 import java.net.ProtocolException ; 44 import java.security.Permission ; 45 46 68 public class HttpURLConnection extends java.net.HttpURLConnection { 69 70 72 73 private static final Log LOG = LogFactory.getLog(HttpURLConnection.class); 74 75 76 78 82 private HttpMethod method; 83 84 87 private URL url; 88 89 90 91 93 100 public HttpURLConnection(HttpMethod method, URL url) { 101 super(url); 102 this.method = method; 103 this.url = url; 104 } 105 106 111 protected HttpURLConnection(URL url) { 112 super(url); 113 throw new RuntimeException ("An HTTP URL connection can only be " 114 + "constructed from a HttpMethod class"); 115 } 116 117 118 120 127 public InputStream getInputStream() throws IOException { 128 LOG.trace("enter HttpURLConnection.getInputStream()"); 129 return this.method.getResponseBodyAsStream(); 130 } 131 132 137 public InputStream getErrorStream() { 138 LOG.trace("enter HttpURLConnection.getErrorStream()"); 139 throw new RuntimeException ("Not implemented yet"); 140 } 141 142 146 public void disconnect() { 147 LOG.trace("enter HttpURLConnection.disconnect()"); 148 throw new RuntimeException ("Not implemented yet"); 149 } 150 151 156 public void connect() throws IOException { 157 LOG.trace("enter HttpURLConnection.connect()"); 158 throw new RuntimeException ("This class can only be used with already" 159 + "retrieved data"); 160 } 161 162 167 public boolean usingProxy() { 168 LOG.trace("enter HttpURLConnection.usingProxy()"); 169 throw new RuntimeException ("Not implemented yet"); 170 } 171 172 178 public String getRequestMethod() { 179 LOG.trace("enter HttpURLConnection.getRequestMethod()"); 180 return this.method.getName(); 181 } 182 183 190 public int getResponseCode() throws IOException { 191 LOG.trace("enter HttpURLConnection.getResponseCode()"); 192 return this.method.getStatusCode(); 193 } 194 195 202 public String getResponseMessage() throws IOException { 203 LOG.trace("enter HttpURLConnection.getResponseMessage()"); 204 return this.method.getStatusText(); 205 } 206 207 214 public String getHeaderField(String name) { 215 LOG.trace("enter HttpURLConnection.getHeaderField(String)"); 216 Header[] headers = this.method.getResponseHeaders(); 219 for (int i = headers.length - 1; i >= 0; i--) { 220 if (headers[i].getName().equalsIgnoreCase(name)) { 221 return headers[i].getValue(); 222 } 223 } 224 225 return null; 226 } 227 228 235 public String getHeaderFieldKey(int keyPosition) { 236 LOG.trace("enter HttpURLConnection.getHeaderFieldKey(int)"); 237 238 242 if (keyPosition == 0) { 243 return null; 244 } 245 246 249 Header[] headers = this.method.getResponseHeaders(); 250 if (keyPosition < 0 || keyPosition > headers.length) { 251 return null; 252 } 253 254 return headers[keyPosition - 1].getName(); 255 } 256 257 264 public String getHeaderField(int position) { 265 LOG.trace("enter HttpURLConnection.getHeaderField(int)"); 266 267 271 if (position == 0) { 272 return this.method.getStatusLine().toString(); 273 } 274 275 278 Header[] headers = this.method.getResponseHeaders(); 279 if (position < 0 || position > headers.length) { 280 return null; 281 } 282 283 return headers[position - 1].getValue(); 284 } 285 286 291 public URL getURL() { 292 LOG.trace("enter HttpURLConnection.getURL()"); 293 return this.url; 294 } 295 296 300 309 312 public void setInstanceFollowRedirects(boolean isFollowingRedirects) { 313 LOG.trace("enter HttpURLConnection.setInstanceFollowRedirects(boolean)"); 314 throw new RuntimeException ("This class can only be used with already" 315 + "retrieved data"); 316 } 317 318 321 public boolean getInstanceFollowRedirects() { 322 LOG.trace("enter HttpURLConnection.getInstanceFollowRedirects()"); 323 throw new RuntimeException ("Not implemented yet"); 324 } 325 326 330 public void setRequestMethod(String method) throws ProtocolException { 331 LOG.trace("enter HttpURLConnection.setRequestMethod(String)"); 332 throw new RuntimeException ("This class can only be used with already" 333 + "retrieved data"); 334 } 335 336 340 public Permission getPermission() throws IOException { 341 LOG.trace("enter HttpURLConnection.getPermission()"); 342 throw new RuntimeException ("Not implemented yet"); 343 } 344 345 349 public Object getContent() throws IOException { 350 LOG.trace("enter HttpURLConnection.getContent()"); 351 throw new RuntimeException ("Not implemented yet"); 352 } 353 354 357 public Object getContent(Class [] classes) throws IOException { 358 LOG.trace("enter HttpURLConnection.getContent(Class[])"); 359 throw new RuntimeException ("Not implemented yet"); 360 } 361 362 365 public OutputStream getOutputStream() throws IOException { 366 LOG.trace("enter HttpURLConnection.getOutputStream()"); 367 throw new RuntimeException ("This class can only be used with already" 368 + "retrieved data"); 369 } 370 371 375 public void setDoInput(boolean isInput) { 376 LOG.trace("enter HttpURLConnection.setDoInput()"); 377 throw new RuntimeException ("This class can only be used with already" 378 + "retrieved data"); 379 } 380 381 385 public boolean getDoInput() { 386 LOG.trace("enter HttpURLConnection.getDoInput()"); 387 throw new RuntimeException ("Not implemented yet"); 388 } 389 390 394 public void setDoOutput(boolean isOutput) { 395 LOG.trace("enter HttpURLConnection.setDoOutput()"); 396 throw new RuntimeException ("This class can only be used with already" 397 + "retrieved data"); 398 } 399 400 404 public boolean getDoOutput() { 405 LOG.trace("enter HttpURLConnection.getDoOutput()"); 406 throw new RuntimeException ("Not implemented yet"); 407 } 408 409 413 public void setAllowUserInteraction(boolean isAllowInteraction) { 414 LOG.trace("enter HttpURLConnection.setAllowUserInteraction(boolean)"); 415 throw new RuntimeException ("This class can only be used with already" 416 + "retrieved data"); 417 } 418 419 423 public boolean getAllowUserInteraction() { 424 LOG.trace("enter HttpURLConnection.getAllowUserInteraction()"); 425 throw new RuntimeException ("Not implemented yet"); 426 } 427 428 432 public void setUseCaches(boolean isUsingCaches) { 433 LOG.trace("enter HttpURLConnection.setUseCaches(boolean)"); 434 throw new RuntimeException ("This class can only be used with already" 435 + "retrieved data"); 436 } 437 438 442 public boolean getUseCaches() { 443 LOG.trace("enter HttpURLConnection.getUseCaches()"); 444 throw new RuntimeException ("Not implemented yet"); 445 } 446 447 451 public void setIfModifiedSince(long modificationDate) { 452 LOG.trace("enter HttpURLConnection.setIfModifiedSince(long)"); 453 throw new RuntimeException ("This class can only be used with already" 454 + "retrieved data"); 455 } 456 457 461 public long getIfModifiedSince() { 462 LOG.trace("enter HttpURLConnection.getIfmodifiedSince()"); 463 throw new RuntimeException ("Not implemented yet"); 464 } 465 466 470 public boolean getDefaultUseCaches() { 471 LOG.trace("enter HttpURLConnection.getDefaultUseCaches()"); 472 throw new RuntimeException ("Not implemented yet"); 473 } 474 475 479 public void setDefaultUseCaches(boolean isUsingCaches) { 480 LOG.trace("enter HttpURLConnection.setDefaultUseCaches(boolean)"); 481 throw new RuntimeException ("This class can only be used with already" 482 + "retrieved data"); 483 } 484 485 489 public void setRequestProperty(String key, String value) { 490 LOG.trace("enter HttpURLConnection.setRequestProperty()"); 491 throw new RuntimeException ("This class can only be used with already" 492 + "retrieved data"); 493 } 494 495 499 public String getRequestProperty(String key) { 500 LOG.trace("enter HttpURLConnection.getRequestProperty()"); 501 throw new RuntimeException ("Not implemented yet"); 502 } 503 504 } 505 506 | Popular Tags |