org.apache.commons.httpclient.util
Class HttpURLConnection

java.lang.Object
  extended byjava.net.URLConnection
      extended byjava.net.HttpURLConnection
          extended byorg.apache.commons.httpclient.util.HttpURLConnection

public class HttpURLConnection
extends HttpURLConnection

Provides a HttpURLConnection wrapper around HttpClient's HttpMethod. This allows existing code to easily switch to HttpClieht without breaking existing interfaces using the JDK HttpURLConnection. Note 1: The current implementations wraps only a connected HttpMethod, ie a method that has alreayd been used to connect to an HTTP server. Note 2: It is a best try effort as different version of the JDK have different behaviours for HttpURLConnection (And I'm not even including the numerous HttpURLConnection bugs!).

Since:
2.0
Version:
$Id: HttpURLConnection.java,v 1.12.2.2 2004/02/22 18:21:16 olegk Exp $
Author:
Vincent Massol, Jeff Dever, Mike Bowler

Field Summary
 
Fields inherited from class java.net.HttpURLConnection
HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, responseCode, responseMessage
 
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, useCaches
 
Constructor Summary
  HttpURLConnection(HttpMethod method, URL url)
          Creates an HttpURLConnection from a HttpMethod.
protected HttpURLConnection(URL url)
          Create an instance.
 
Method Summary
 void connect()
          Not available: the data must have already been retrieved.
 void disconnect()
          Not yet implemented.
 boolean getAllowUserInteraction()
          Not yet implemented.
 Object getContent()
          Not yet implemented.
 Object getContent(Class[] classes)
          Not yet implemented.
 boolean getDefaultUseCaches()
          Not available: the data must have already been retrieved.
 boolean getDoInput()
          Not yet implemented.
 boolean getDoOutput()
          Not yet implemented.
 InputStream getErrorStream()
          Not yet implemented.
 String getHeaderField(int position)
          Return the header field at the specified position
 String getHeaderField(String name)
          Return the header field
 String getHeaderFieldKey(int keyPosition)
          Return the header field key
 long getIfModifiedSince()
          Not yet implemented.
 InputStream getInputStream()
          Gets an input stream for the HttpMethod response body.
 boolean getInstanceFollowRedirects()
          Not yet implemented.
 OutputStream getOutputStream()
           
 Permission getPermission()
          Not yet implemented.
 String getRequestMethod()
          Return the request method.
 String getRequestProperty(String key)
          Not yet implemented.
 int getResponseCode()
          Return the response code.
 String getResponseMessage()
          Return the response message
 URL getURL()
          Return the URL
 boolean getUseCaches()
          Not yet implemented.
 void setAllowUserInteraction(boolean isAllowInteraction)
          Not available: the data must have already been retrieved.
 void setDefaultUseCaches(boolean isUsingCaches)
          Not available: the data must have already been retrieved.
 void setDoInput(boolean isInput)
          Not available: the data must have already been retrieved.
 void setDoOutput(boolean isOutput)
          Not available: the data must have already been retrieved.
 void setIfModifiedSince(long modificationDate)
          Not available: the data must have already been retrieved.
 void setInstanceFollowRedirects(boolean isFollowingRedirects)
          Not available: the data must have already been retrieved.
 void setRequestMethod(String method)
          Not available: the data must have already been retrieved.
 void setRequestProperty(String key, String value)
          Not available: the data must have already been retrieved.
 void setUseCaches(boolean isUsingCaches)
          Not available: the data must have already been retrieved.
 boolean usingProxy()
          Not yet implemented.
 
Methods inherited from class java.net.HttpURLConnection
getFollowRedirects, getHeaderFieldDate, setFollowRedirects
 
Methods inherited from class java.net.URLConnection
addRequestProperty, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getExpiration, getFileNameMap, getHeaderFieldInt, getHeaderFields, getLastModified, getRequestProperties, guessContentTypeFromName, guessContentTypeFromStream, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setFileNameMap, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpURLConnection

public HttpURLConnection(HttpMethod method,
                         URL url)
Creates an HttpURLConnection from a HttpMethod.

Parameters:
method - the theMethod that was used to connect to the HTTP server and which contains the returned data.
url - the URL to which we are connected (includes query string)

HttpURLConnection

protected HttpURLConnection(URL url)
Create an instance.

Parameters:
url - The URL.
See Also:
HttpURLConnection.HttpURLConnection(URL)
Method Detail

getInputStream

public InputStream getInputStream()
                           throws IOException
Gets an input stream for the HttpMethod response body.

Returns:
The input stream.
Throws:
IOException - If an IO problem occurs.
See Also:
URLConnection.getInputStream(), HttpMethod.getResponseBodyAsStream()

getErrorStream

public InputStream getErrorStream()
Not yet implemented. Return the error stream.

See Also:
HttpURLConnection.getErrorStream()

disconnect

public void disconnect()
Not yet implemented.

See Also:
HttpURLConnection.disconnect()

connect

public void connect()
             throws IOException
Not available: the data must have already been retrieved.

Throws:
IOException - If an IO problem occurs.
See Also:
URLConnection.connect()

usingProxy

public boolean usingProxy()
Not yet implemented.

Returns:
true if we are using a proxy.
See Also:
HttpURLConnection.usingProxy()

getRequestMethod

public String getRequestMethod()
Return the request method.

Returns:
The request method.
See Also:
HttpURLConnection.getRequestMethod(), HttpMethod.getName()

getResponseCode

public int getResponseCode()
                    throws IOException
Return the response code.

Returns:
The response code.
Throws:
IOException - If an IO problem occurs.
See Also:
HttpURLConnection.getResponseCode(), HttpMethod.getStatusCode()

getResponseMessage

public String getResponseMessage()
                          throws IOException
Return the response message

Returns:
The response message
Throws:
IOException - If an IO problem occurs.
See Also:
HttpURLConnection.getResponseMessage(), HttpMethod.getStatusText()

getHeaderField

public String getHeaderField(String name)
Return the header field

Parameters:
name - the name of the header
Returns:
the header field.
See Also:
URLConnection.getHeaderField(String), HttpMethod.getResponseHeaders()

getHeaderFieldKey

public String getHeaderFieldKey(int keyPosition)
Return the header field key

Parameters:
keyPosition - The key position
Returns:
The header field key.
See Also:
HttpURLConnection.getHeaderFieldKey(int), HttpMethod.getResponseHeaders()

getHeaderField

public String getHeaderField(int position)
Return the header field at the specified position

Parameters:
position - The position
Returns:
The header field.
See Also:
HttpURLConnection.getHeaderField(int), HttpMethod.getResponseHeaders()

getURL

public URL getURL()
Return the URL

Returns:
The URL.
See Also:
URLConnection.getURL()

setInstanceFollowRedirects

public void setInstanceFollowRedirects(boolean isFollowingRedirects)
Not available: the data must have already been retrieved.


getInstanceFollowRedirects

public boolean getInstanceFollowRedirects()
Not yet implemented.


setRequestMethod

public void setRequestMethod(String method)
                      throws ProtocolException
Not available: the data must have already been retrieved.

Throws:
ProtocolException
See Also:
HttpURLConnection.setRequestMethod(String)

getPermission

public Permission getPermission()
                         throws IOException
Not yet implemented.

Throws:
IOException
See Also:
HttpURLConnection.getPermission()

getContent

public Object getContent()
                  throws IOException
Not yet implemented.

Throws:
IOException
See Also:
URLConnection.getContent()

getContent

public Object getContent(Class[] classes)
                  throws IOException
Not yet implemented.

Throws:
IOException

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Throws:
IOException
See Also:
URLConnection.getOutputStream()

setDoInput

public void setDoInput(boolean isInput)
Not available: the data must have already been retrieved.

See Also:
URLConnection.setDoInput(boolean)

getDoInput

public boolean getDoInput()
Not yet implemented.

See Also:
URLConnection.getDoInput()

setDoOutput

public void setDoOutput(boolean isOutput)
Not available: the data must have already been retrieved.

See Also:
URLConnection.setDoOutput(boolean)

getDoOutput

public boolean getDoOutput()
Not yet implemented.

See Also:
URLConnection.getDoOutput()

setAllowUserInteraction

public void setAllowUserInteraction(boolean isAllowInteraction)
Not available: the data must have already been retrieved.

See Also:
URLConnection.setAllowUserInteraction(boolean)

getAllowUserInteraction

public boolean getAllowUserInteraction()
Not yet implemented.

See Also:
URLConnection.getAllowUserInteraction()

setUseCaches

public void setUseCaches(boolean isUsingCaches)
Not available: the data must have already been retrieved.

See Also:
URLConnection.setUseCaches(boolean)

getUseCaches

public boolean getUseCaches()
Not yet implemented.

See Also:
URLConnection.getUseCaches()

setIfModifiedSince

public void setIfModifiedSince(long modificationDate)
Not available: the data must have already been retrieved.

See Also:
URLConnection.setIfModifiedSince(long)

getIfModifiedSince

public long getIfModifiedSince()
Not yet implemented.

See Also:
URLConnection.getIfModifiedSince()

getDefaultUseCaches

public boolean getDefaultUseCaches()
Not available: the data must have already been retrieved.

See Also:
URLConnection.getDefaultUseCaches()

setDefaultUseCaches

public void setDefaultUseCaches(boolean isUsingCaches)
Not available: the data must have already been retrieved.

See Also:
URLConnection.setDefaultUseCaches(boolean)

setRequestProperty

public void setRequestProperty(String key,
                               String value)
Not available: the data must have already been retrieved.

See Also:
URLConnection.setRequestProperty(String,String)

getRequestProperty

public String getRequestProperty(String key)
Not yet implemented.

See Also:
URLConnection.getRequestProperty(String)


Copyright (c) 1999-2002 - Apache Software Foundation