com.sun.faban.driver.transport.sunhttp
Class HttpURLConnection

java.lang.Object
  extended by java.net.URLConnection
      extended by java.net.HttpURLConnection
          extended by sun.net.www.protocol.http.HttpURLConnection
              extended by com.sun.faban.driver.transport.sunhttp.HttpURLConnection

public class HttpURLConnection
extends sun.net.www.protocol.http.HttpURLConnection

Faban's implementation of HttpURLConnection relies heavily on the sun.net implementation. It is actually a subclass that creates instances of faban's HttpClient instead of the sun.net version. It also opens up the interface for clients to use a custom SocketFactory. This HttpURLConnection serves both http and https connections.

Author:
Akara Sucharitakul

Field Summary
 
Fields inherited from class sun.net.www.protocol.http.HttpURLConnection
cachedResponse, handler, http, instProxy, pi, ps, userAgent
 
Fields inherited from class java.net.HttpURLConnection
chunkLength, fixedContentLength, 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, method, responseCode, responseMessage
 
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
 
Constructor Summary
protected HttpURLConnection(URL url, Proxy proxy, Handler handler)
          Creates a connection.
 
Method Summary
static SocketFactory getDefaultSocketFactory()
          Gets the default static SocketFactory that is inherited by new instances of this class.
protected  HttpClient getNewHttpClient(URL url, Proxy p, int connectTimeout)
           
 SocketFactory getSocketFactory()
          Gets the socket factory to be used when creating sockets for secure https URL connections.
protected  void proxiedConnect(URL url, String proxyHost, int proxyPort, boolean useCache)
          Connects via proxy.
static void setDefaultSocketFactory(SocketFactory sf)
          Sets the default SocketFactory inherited by new instances of this class.
protected  void setNewClient(URL url, boolean useCache)
          Obtain a HttpClient object.
 void setSocketFactory(SocketFactory sf)
          Sets the SocketFactory to be used when this instance creates sockets for secure https URL connections.
 
Methods inherited from class sun.net.www.protocol.http.HttpURLConnection
addRequestProperty, connect, disconnect, doTunneling, finalize, getConnectTimeout, getErrorStream, getHeaderField, getHeaderField, getHeaderFieldKey, getHeaderFields, getInputStream, getNewHttpClient, getOutputStream, getReadTimeout, getRequestProperties, getRequestProperty, openConnectionCheckRedirects, plainConnect, setConnectTimeout, setDefaultAuthenticator, setNewClient, setProxiedClient, setProxiedClient, setReadTimeout, setRequestProperty, usingProxy
 
Methods inherited from class java.net.HttpURLConnection
getFollowRedirects, getHeaderFieldDate, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseCode, getResponseMessage, setChunkedStreamingMode, setFixedLengthStreamingMode, setFollowRedirects, setInstanceFollowRedirects, setRequestMethod
 
Methods inherited from class java.net.URLConnection
getAllowUserInteraction, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderFieldInt, getIfModifiedSince, getLastModified, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setUseCaches, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HttpURLConnection

protected HttpURLConnection(URL url,
                            Proxy proxy,
                            Handler handler)
Creates a connection.

Parameters:
url - The target URL
proxy - Proxy, if any
handler - The protocol handler
Method Detail

setNewClient

protected void setNewClient(URL url,
                            boolean useCache)
                     throws IOException
Obtain a HttpClient object. Use the cached copy if specified.

Overrides:
setNewClient in class sun.net.www.protocol.http.HttpURLConnection
Parameters:
url - the URL being accessed
useCache - whether the cached connection should be used if present
Throws:
IOException - Communication error

proxiedConnect

protected void proxiedConnect(URL url,
                              String proxyHost,
                              int proxyPort,
                              boolean useCache)
                       throws IOException
Connects via proxy.

Overrides:
proxiedConnect in class sun.net.www.protocol.http.HttpURLConnection
Parameters:
url - The URL to connect
proxyHost - The proxy host
proxyPort - The proxy port
useCache - Whether to use cached connections
Throws:
IOException - Communication error

getNewHttpClient

protected HttpClient getNewHttpClient(URL url,
                                      Proxy p,
                                      int connectTimeout)
                               throws IOException
Overrides:
getNewHttpClient in class sun.net.www.protocol.http.HttpURLConnection
Throws:
IOException

setDefaultSocketFactory

public static void setDefaultSocketFactory(SocketFactory sf)
Sets the default SocketFactory inherited by new instances of this class.

The socket factories are used when creating sockets for secure https URL connections.

Parameters:
sf - the default socket factory
Throws:
IllegalArgumentException - if the SocketFactory parameter is null.
See Also:
getDefaultSocketFactory()

getDefaultSocketFactory

public static SocketFactory getDefaultSocketFactory()
Gets the default static SocketFactory that is inherited by new instances of this class.

The socket factories are used when creating sockets for secure https URL connections.

Returns:
the default SocketFactory
See Also:
setDefaultSocketFactory(SocketFactory)

setSocketFactory

public void setSocketFactory(SocketFactory sf)
Sets the SocketFactory to be used when this instance creates sockets for secure https URL connections.

New instances of this class inherit the default static SocketFactory set by setDefaultSocketFactory. Calls to this method replace this object's SocketFactory.

Parameters:
sf - the socket factory
Throws:
IllegalArgumentException - if the SocketFactory parameter is null.
See Also:
getSocketFactory()

getSocketFactory

public SocketFactory getSocketFactory()
Gets the socket factory to be used when creating sockets for secure https URL connections.

Returns:
the SocketFactory
See Also:
setSocketFactory(SocketFactory)