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

java.lang.Object
  extended by sun.net.NetworkClient
      extended by sun.net.www.http.HttpClient
          extended by com.sun.faban.driver.transport.sunhttp.HttpClient

public class HttpClient
extends sun.net.www.http.HttpClient

Implementation of the HttpClient for the Faban driver framework. It relies heavily on the sun.net implementation. The only difference is actually the use of SocketFactory instead of plainly creating new sockets. The HttpClient supports both http and https protocols.
Derived from code contributed by Scott Oaks.

Author:
Akara Sucharitakul

Field Summary
protected  boolean inCache
          Superclass' inCache is private.
 
Fields inherited from class sun.net.www.http.HttpClient
cachedHttpClient, cookieHandler, host, kac, port, proxyDisabled, reuse, url, usingProxy
 
Fields inherited from class sun.net.NetworkClient
connectTimeout, defaultConnectTimeout, defaultSoTimeout, encoding, proxy, readTimeout, serverInput, serverOutput, serverSocket
 
Constructor Summary
protected HttpClient(URL url, Proxy proxy, int to)
          Subclass constructor for the client.
 
Method Summary
protected  Socket doConnect(String server, int port)
          Return a socket connected to the server, with any appropriate options pre-established.
static HttpClient New(URL url, Proxy p, int to, boolean useCache)
          Instantiates a HttpClient.
static HttpClient New(URL url, String proxyHost, int proxyPort, boolean useCache, int timeout)
          Instantiates a HttpClient.
protected  void putInKeepAliveCache()
           
protected static void setSocketFactory(SocketFactory sf)
          Sets the socket factory for creating sockets used by this client.
 
Methods inherited from class sun.net.www.http.HttpClient
afterConnect, closeIdleConnection, closeServer, finalize, finished, getDefaultPort, getHttpKeepAliveSet, getInputStream, getOutputStream, getProxyHostUsed, getProxyPortUsed, getURLFile, isCachedConnection, isInKeepAliveCache, isKeepingAlive, needsTunneling, New, New, New, New, newHttpProxy, openServer, openServer, parseHTTP, resetProperties, setCacheRequest, setDoNotRetry, setTimeout, toString, writeRequests, writeRequests
 
Methods inherited from class sun.net.NetworkClient
getConnectTimeout, getLocalAddress, getReadTimeout, serverIsOpen, setConnectTimeout, setReadTimeout
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

inCache

protected boolean inCache
Superclass' inCache is private. Needed to define and check usage.

Constructor Detail

HttpClient

protected HttpClient(URL url,
                     Proxy proxy,
                     int to)
              throws IOException
Subclass constructor for the client.

Parameters:
url - The URL
proxy - Proxies, if any
to - The connect timeout
Throws:
IOException - If an error occurs
Method Detail

New

public static HttpClient New(URL url,
                             String proxyHost,
                             int proxyPort,
                             boolean useCache,
                             int timeout)
                      throws IOException
Instantiates a HttpClient.

Parameters:
url - The URL to connect
proxyHost - The proxy server, null if no proxy
proxyPort - The proxy server port
useCache - Whether to use a client from cache or not
timeout - The connect timeout, -1 if no timeout
Returns:
An instance of HttpClient
Throws:
IOException - An I/O error occurred

New

public static HttpClient New(URL url,
                             Proxy p,
                             int to,
                             boolean useCache)
                      throws IOException
Instantiates a HttpClient.

Parameters:
url - The URL to connect
p - The proxy server, null if no proxy
to - The connect timeout, -1 if no timeout
useCache - Whether to use a client from cache or not
Returns:
An instance of HttpClient
Throws:
IOException - An I/O error occurred

putInKeepAliveCache

protected void putInKeepAliveCache()
Overrides:
putInKeepAliveCache in class sun.net.www.http.HttpClient

doConnect

protected Socket doConnect(String server,
                           int port)
                    throws IOException,
                           UnknownHostException
Return a socket connected to the server, with any appropriate options pre-established. This method overrides NetworClient.doConnect() to use the provided SocketFactory for socket creation.

Overrides:
doConnect in class sun.net.NetworkClient
Parameters:
server - The server to connect to
port - The port to connect to
Returns:
The socket connecting the the server
Throws:
IOException - Communication error
UnknownHostException - The host cannot be found

setSocketFactory

protected static void setSocketFactory(SocketFactory sf)
Sets the socket factory for creating sockets used by this client.

Parameters:
sf - The socket factory