com.oaklandsw.http
Class HttpURLConnection

java.lang.Object
  extended byjava.net.URLConnection
      extended byjava.net.HttpURLConnection
          extended bycom.oaklandsw.http.HttpURLConnection

public abstract class HttpURLConnection
extends java.net.HttpURLConnection

A URLConnection with support for HTTP-specific features.

The following properties can be used with this class:

http.proxyHost- specifies the host of the proxy server. Note this is identical to the method to specify the proxy host for the java.net.HttpURLConnection. See setProxyHost().

http.proxyPort- specifies the port of the proxy server. Note this is identical to the method to specify the proxy port for the java.net.HttpURLConnection. See setProxyPort().

http.nonProxyHosts- specifies a list of hosts to not direct to the proxy server. Note this is identical to the method to specify such hosts as for the java.net.HttpURLConnection. See setNonProxyHosts().

proxySet- setting this to any value causes all requests to go through the proxy server specified by proxyHost and proxyPort. Note that this method is obsolete and provided only for compatibility with JDK 1.0.2 implementations. The preferred method is to use http.proxyHost/Port. See setProxyHost()/setProxyPort().

proxyHost- specifies the host of the proxy server. Note this is identical to the method to specify the proxy host for the java.net.HttpURLConnection. This only works if proxySet is set to something. Note that this method is obsolete and provided only for compatibility with JDK 1.0.2 implementations. The preferred method is to use http.proxyHost. See setProxyHost().

proxyPort- specifies the port of the proxy server. Note this is identical to the method to specify the proxy port for the java.net.HttpURLConnection. This only works if proxySet is set to something. Note that this method is obsolete and provided only for compatibility with JDK 1.0.2 implementations. The preferred method is to use http.proxyPort. See setProxyPort().

com.oaklandsw.http.timeout- specifies the timeout value in milliseconds. See setDefaultTimeout().

com.oaklandsw.http.idleConnectionTimeout- the number of milliseconds that a connection can be idle before it is removed from the connection pool. See setIdleConnectionTimeout() and setDefaultIdleConnectionTimeout().

com.oaklandsw.http.idleConnectionPing- this is used to ping the connection before sending a POST request. The ping is issued if the connection was idle for at least the number of milliseconds specified. See setIdleConnectionPing() and setDefaultIdleConnectionPing().

com.oaklandsw.http.explicitClose- requires the InputStream to be obtained and closed explicitly. This is enabled if the value of this property is set to anything. See setExplicitClose() for important details about how to use this feature.

com.oaklandsw.http.maxConnectionsPerHost- sets the maximum number of connections allowed to a given host:port. If not specified, a default of 2 is assumed. See setMaxConnectionsPerHost().

com.oaklandsw.http.tries- the number of times to try a sending an idempotent request if there is a problem with getting the response. The default is 3. See setTries().

com.oaklandsw.http.retryInterval- the number of milliseconds to wait before retrying an idempotent request. The default is 50ms. See setRetryInterval().


Field Summary
static boolean _isSSLAvailable
           
static int CONNECT
           
static int DELETE
           
static int GET
           
static int HEAD
           
static java.lang.String HTTP_METHOD_CONNECT
           
static java.lang.String HTTP_METHOD_DELETE
           
static java.lang.String HTTP_METHOD_GET
           
static java.lang.String HTTP_METHOD_HEAD
           
static java.lang.String HTTP_METHOD_OPTIONS
           
static java.lang.String HTTP_METHOD_POST
           
static java.lang.String HTTP_METHOD_PUT
           
static java.lang.String HTTP_METHOD_TRACE
           
static int NTLM_ENCODING_OEM
           
static int NTLM_ENCODING_UNICODE
           
static int OPTIONS
           
static int POST
           
static int PUT
           
static int TRACE
           
 
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
 
Constructor Summary
HttpURLConnection()
           
HttpURLConnection(java.net.URL urlParam)
           
 
Method Summary
 void addRequestProperty(java.lang.String key, java.lang.String value)
           
static void closeAllPooledConnections()
          Close all pooled connections that are not currently in use.
 void connect()
           
 void disconnect()
           
static void dumpConnectionPool()
          Prints all pooled connections to System.out.
 void finalize()
          Releases the associated transport collection when this object is to be collected.
 java.lang.String getCipherSuite()
          Returns the cipher suite associated with this connection.
 java.lang.String getConnectionProxyHost()
          Returns the current value of the proxy server host on this connection.
 int getConnectionProxyPort()
          Returns the current value of the proxy server port number.
 int getConnectionTimeout()
          Return the connection timeout value associated with this connection.
static int getDefaultConnectionTimeout()
          Return the default connection timeout value.
static HostnameVerifier getDefaultHostnameVerifier()
          Returns the default hostname verifier used for SSL connections.
static int getDefaultIdleConnectionPing()
          Return the default idle connection ping value.
static int getDefaultIdleConnectionTimeout()
          Return the default idle connection timeout value.
static int getDefaultRequestTimeout()
          Return the default request timeout value.
static javax.net.ssl.SSLSocketFactory getDefaultSSLSocketFactory()
          Returns the default SSL socket factory used for SSL connections.
static int getDefaultTimeout()
          Deprecated. please use getDefaultConnectionTimeout() or getDefaultRequestTimeout()
static HttpUserAgent getDefaultUserAgent()
          Gets the default user agent.
 boolean getDoAuthentication()
          Automatic processing of responses where authentication is required (status codes 401 and 407).
 java.io.InputStream getErrorStream()
          Returns the data associated with the connection in the event of an error.
static boolean getExplicitClose()
          Returns true if an explicit close is required, false otherwise.
 java.lang.String getHeaderField(int position)
           
 java.lang.String getHeaderField(java.lang.String name)
           
 java.lang.String getHeaderFieldKey(int keyPosition)
           
 HostnameVerifier getHostnameVerifier()
          Returns the hostname verifier used for this SSL connection.
 int getIdleConnectionPing()
          Return the idle connection ping value associated with this connection.
 int getIdleConnectionTimeout()
          Return the idle connection timeout value associated with this connection.
 java.io.InputStream getInputStream()
          Gets an InputStream for the data returned in the response.
 boolean getInstanceFollowRedirects()
          Whether or not I should automatically follow HTTP redirects (status code 302, etc.)
 java.security.cert.Certificate[] getLocalCertificates()
          Returns the certificates(s) that were sent to the server when the connection was established.
static int getMaxConnectionsPerHost()
          Get the maximum number of connections allowed for a given host:port.
static java.lang.String getNonProxyHosts()
          Returns the current value of the hosts to not be accessed through the proxy server.
static int getNtlmPreferredEncoding()
          Gets the preferred encoding for NTLM messages.
 java.io.OutputStream getOutputStream()
           
static java.lang.String getProxyHost()
          Returns the current value of the proxy server host.
static int getProxyPort()
          Returns the current value of the proxy server port number.
 java.lang.String getRequestProperty(java.lang.String key)
           
 int getRequestTimeout()
          Return the request timeout value associated with this connection.
 int getResponseCode()
           
 java.lang.String getResponseMessage()
           
static int getRetryInterval()
          Get the interval to wait before each retry of a failed request.
 java.security.cert.Certificate[] getServerCertificates()
          Returns the server's certificate chain that was established when the session was setup.
 javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
          Returns the SSL socket factory used this SSL connection.
 int getTimeout()
          Deprecated. please use either getConnectionTimeout() or getRequestTimeout()
static int getTries()
          Get the number of times an idempotent request is tried.
static boolean getUse10KeepAlive()
          Get the option to include the HTTP 1.0 Keep-Alive headers in HTTP requests.
 HttpUserAgent getUserAgent()
          Sets the user agent for this connection.
 boolean isConnected()
          Returns true if this connection is currently connected.
static HttpURLConnection openConnection(java.net.URL url)
          Creates an HTTP connection directly, without using the URLStreamHandler.
 void setConnectionProxyHost(java.lang.String host)
          Sets the host to be used as a proxy server for this connection.
 void setConnectionProxyPort(int port)
          Sets the port on the proxy server host.
 void setConnectionTimeout(int ms)
          Set the connection timeout value associated with this connection.
static void setDefaultConnectionTimeout(int ms)
          Set the default connection timeout value.
static void setDefaultHostnameVerifier(HostnameVerifier verifier)
          Sets the default hostname verifier used for SSL connections
static void setDefaultIdleConnectionPing()
          Set the default idle connection ping value to its default value (0 seconds).
static void setDefaultIdleConnectionPing(int ms)
          Set the default idle connection ping value.
static void setDefaultIdleConnectionTimeout()
          Set the default idle connection timeout value to its default value (14 seconds).
static void setDefaultIdleConnectionTimeout(int ms)
          Set the default idle connection timeout value.
static void setDefaultRequestTimeout(int ms)
          Set the default request timeout value.
static void setDefaultSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
          Sets the default SSL socket factory used for SSL connections.
static void setDefaultTimeout(int ms)
          Set the default timeout value.
static void setDefaultUserAgent(HttpUserAgent userAgent)
          Sets the default user agent.
 void setDoAuthentication(boolean doAuthentication)
          Automatic processing of responses where authentication is required (status codes 401 and 407).
static void setExplicitClose(boolean explicitClose)
          Sets all connections to require the InputStream to be obtained using a call to getInputStream(), and for that stream to be closed.
 void setHostnameVerifier(HostnameVerifier verifier)
          Sets the hostname verifier used for this SSL connection
 void setIdleConnectionPing(int ms)
          Set the idle connection ping value associated with this connection.
 void setIdleConnectionTimeout(int ms)
          Set the idle connection timeout value associated with this connection.
 void setInstanceFollowRedirects(boolean followRedirects)
          Set whether or not I should automatically follow HTTP redirects (status code 302, etc.)
static void setMaxConnectionsPerHost(int maxConnections)
          Set the maximum number of connections allowed for a given host:port.
static void setNonProxyHosts(java.lang.String hosts)
          Sets the hosts to be excluded from the proxy mechanism.
static void setNtlmPreferredEncoding(int encoding)
          Sets the preferred encoding for NTLM authenticate messages.
static void setProxyHost(java.lang.String host)
          Sets the host to be used as a proxy server.
static void setProxyPort(int port)
          Sets the port on the proxy server host.
 void setRequestMethod(java.lang.String meth)
           
 void setRequestProperty(java.lang.String key, java.lang.String value)
           
 void setRequestTimeout(int ms)
          Set the request timeout value associated with this connection.
static void setRetryInterval(int ms)
          Set the interval to wait before each retry of a failed request.
 void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
          Sets the SSL socket factory used for this SSL connection.
 void setTimeout(int ms)
          Set the timeout value associated with this connection.
static void setTries(int tries)
          Set the number of times an idempotent request is to be tried before considering it a failure.
static void setUse10KeepAlive(boolean use)
          Set the option to include the HTTP 1.0 Keep-Alive headers in HTTP requests.
 void setUserAgent(HttpUserAgent userAgent)
          Sets the user agent for this connection.
 boolean usingProxy()
           
 
Methods inherited from class java.net.HttpURLConnection
getFollowRedirects, getHeaderFieldDate, getPermission, getRequestMethod, setFollowRedirects
 
Methods inherited from class java.net.URLConnection
getAllowUserInteraction, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderFieldInt, getHeaderFields, getIfModifiedSince, getLastModified, getRequestProperties, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setUseCaches, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HTTP_METHOD_GET

public static final java.lang.String HTTP_METHOD_GET
See Also:
Constant Field Values

HTTP_METHOD_POST

public static final java.lang.String HTTP_METHOD_POST
See Also:
Constant Field Values

HTTP_METHOD_PUT

public static final java.lang.String HTTP_METHOD_PUT
See Also:
Constant Field Values

HTTP_METHOD_OPTIONS

public static final java.lang.String HTTP_METHOD_OPTIONS
See Also:
Constant Field Values

HTTP_METHOD_DELETE

public static final java.lang.String HTTP_METHOD_DELETE
See Also:
Constant Field Values

HTTP_METHOD_HEAD

public static final java.lang.String HTTP_METHOD_HEAD
See Also:
Constant Field Values

HTTP_METHOD_TRACE

public static final java.lang.String HTTP_METHOD_TRACE
See Also:
Constant Field Values

HTTP_METHOD_CONNECT

public static final java.lang.String HTTP_METHOD_CONNECT
See Also:
Constant Field Values

GET

public static final int GET
See Also:
Constant Field Values

POST

public static final int POST
See Also:
Constant Field Values

PUT

public static final int PUT
See Also:
Constant Field Values

OPTIONS

public static final int OPTIONS
See Also:
Constant Field Values

DELETE

public static final int DELETE
See Also:
Constant Field Values

HEAD

public static final int HEAD
See Also:
Constant Field Values

TRACE

public static final int TRACE
See Also:
Constant Field Values

CONNECT

public static final int CONNECT
See Also:
Constant Field Values

NTLM_ENCODING_UNICODE

public static final int NTLM_ENCODING_UNICODE
See Also:
Constant Field Values

NTLM_ENCODING_OEM

public static final int NTLM_ENCODING_OEM
See Also:
Constant Field Values

_isSSLAvailable

public static boolean _isSSLAvailable
Constructor Detail

HttpURLConnection

public HttpURLConnection()

HttpURLConnection

public HttpURLConnection(java.net.URL urlParam)
See Also:
java.net.HttpURLConnection#HttpURLConnection()
Method Detail

openConnection

public static HttpURLConnection openConnection(java.net.URL url)
Creates an HTTP connection directly, without using the URLStreamHandler. This is used if the currently selected HTTP implementation is something other than the Oakland Software implementation, and you need a Oakland Software HTTP connection. It is exactly the same as calling java.net.URL.openConnection()

See Also:
URL.openConnection()

finalize

public void finalize()
Releases the associated transport collection when this object is to be collected.


setRequestMethod

public void setRequestMethod(java.lang.String meth)
                      throws java.net.ProtocolException
Throws:
java.net.ProtocolException
See Also:
HttpURLConnection.setRequestMethod(String)

setRequestProperty

public void setRequestProperty(java.lang.String key,
                               java.lang.String value)
See Also:
URLConnection.setRequestProperty(String,String)

addRequestProperty

public void addRequestProperty(java.lang.String key,
                               java.lang.String value)
See Also:
URLConnection.addRequestProperty(String,String)

getRequestProperty

public java.lang.String getRequestProperty(java.lang.String key)
See Also:
URLConnection.getRequestProperty(String)

setInstanceFollowRedirects

public final void setInstanceFollowRedirects(boolean followRedirects)
Set whether or not I should automatically follow HTTP redirects (status code 302, etc.)

Parameters:
followRedirects - true to follow redirects, false otherwise

getInstanceFollowRedirects

public final boolean getInstanceFollowRedirects()
Whether or not I should automatically follow HTTP redirects (status code 302, etc.)

Returns:
true if I will automatically follow HTTP redirects

getOutputStream

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

usingProxy

public boolean usingProxy()
See Also:
HttpURLConnection.usingProxy()

connect

public void connect()
             throws java.io.IOException
Throws:
java.io.IOException
See Also:
URLConnection.connect()

isConnected

public boolean isConnected()
Returns true if this connection is currently connected.

Returns:
a boolean value, true if connected.

getResponseCode

public int getResponseCode()
                    throws java.io.IOException
Throws:
java.io.IOException
See Also:
HttpURLConnection.getResponseCode()

getResponseMessage

public java.lang.String getResponseMessage()
                                    throws java.io.IOException
Throws:
java.io.IOException
See Also:
HttpURLConnection.getResponseMessage()

getHeaderField

public java.lang.String getHeaderField(java.lang.String name)
See Also:
URLConnection.getHeaderField(String)

getHeaderFieldKey

public java.lang.String getHeaderFieldKey(int keyPosition)
See Also:
HttpURLConnection.getHeaderFieldKey(int)

getHeaderField

public java.lang.String getHeaderField(int position)
See Also:
HttpURLConnection.getHeaderField(int)

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Gets an InputStream for the data returned in the response. You should not use getErrorStream() if you have called this, as this function returns the response even in the case of an error.

Throws:
java.io.IOException
See Also:
URLConnection.getInputStream()

getErrorStream

public java.io.InputStream getErrorStream()
Returns the data associated with the connection in the event of an error. This returns data only when the respose code is >= 300. This should not be used if getInputStream() has already been called since that will have read the response.

See Also:
HttpURLConnection.getErrorStream()

disconnect

public void disconnect()
See Also:
HttpURLConnection.disconnect()

setDefaultUserAgent

public static void setDefaultUserAgent(HttpUserAgent userAgent)
Sets the default user agent.


getDefaultUserAgent

public static HttpUserAgent getDefaultUserAgent()
Gets the default user agent.


setUserAgent

public void setUserAgent(HttpUserAgent userAgent)
Sets the user agent for this connection.

Parameters:
userAgent - a object that implements the HttpUserAgent interface.
See Also:
HttpUserAgent

getUserAgent

public HttpUserAgent getUserAgent()
Sets the user agent for this connection.

Returns:
the user agent object.
See Also:
HttpUserAgent

getDoAuthentication

public boolean getDoAuthentication()
Automatic processing of responses where authentication is required (status codes 401 and 407).

Returns:
true if authentications will be processed automatically

setDoAuthentication

public void setDoAuthentication(boolean doAuthentication)
Automatic processing of responses where authentication is required (status codes 401 and 407).

The default is true.

Parameters:
doAuthentication - true to process authentications

getTimeout

public int getTimeout()
Deprecated. please use either getConnectionTimeout() or getRequestTimeout()

Return the timeout value associated with this connection.

Returns:
the timeout value in milliseconds.

setTimeout

public void setTimeout(int ms)
Set the timeout value associated with this connection. This is the number of milliseconds to wait for a connection to be established or a response to be recieved. If this is not specified the default timeout value is used. This is the same as calling setConnectTimeout() and setRequestTimeout() with the same value.

Parameters:
ms - milliseconds to wait for a connection or response.

getConnectionTimeout

public int getConnectionTimeout()
Return the connection timeout value associated with this connection.

Returns:
the timeout value in milliseconds.

setConnectionTimeout

public void setConnectionTimeout(int ms)
Set the connection timeout value associated with this connection. This is the number of milliseconds to wait for the socket connection to be established. If this is not specified the default connection timeout value is used.

Parameters:
ms - milliseconds to wait for the sockect connection.

getRequestTimeout

public int getRequestTimeout()
Return the request timeout value associated with this connection.

Returns:
the timeout value in milliseconds.

setRequestTimeout

public void setRequestTimeout(int ms)
Set the request timeout value associated with this connection. This is the number of milliseconds to wait for a response after the request was sent. If this is not specified the default request timeout value is used.

Parameters:
ms - milliseconds to wait for the respone.

getDefaultTimeout

public static int getDefaultTimeout()
Deprecated. please use getDefaultConnectionTimeout() or getDefaultRequestTimeout()

Return the default connection timeout value.

Returns:
the default timeout value in milliseconds.

setDefaultTimeout

public static void setDefaultTimeout(int ms)
Set the default timeout value. This is the number of milliseconds to wait for a connection to be established or a response to be recieved. Setting the value to 0 means no timeout is used, which is the default value for this property. This is equivalent to setting the com.oaklandsw.http.timeout property. This is the same as calling setDefaultConnectTimeout() and setDefaultRequestTimeout() with the same value.

Parameters:
ms - milliseconds to wait for a connection or response.

getDefaultConnectionTimeout

public static int getDefaultConnectionTimeout()
Return the default connection timeout value.

Returns:
the default timeout value in milliseconds.

setDefaultConnectionTimeout

public static void setDefaultConnectionTimeout(int ms)
Set the default connection timeout value. This is the number of milliseconds to wait for a connection to be established. Setting the value to 0 means no timeout is used, which is the default value for this property.

Parameters:
ms - milliseconds to wait for a socket connection.

getDefaultRequestTimeout

public static int getDefaultRequestTimeout()
Return the default request timeout value.

Returns:
the default timeout value in milliseconds.

setDefaultRequestTimeout

public static void setDefaultRequestTimeout(int ms)
Set the default request timeout value. This is the number of milliseconds to wait for a response to a request. Setting the value to 0 means no timeout is used, which is the default value for this property.

Parameters:
ms - milliseconds to wait for a response.

getIdleConnectionTimeout

public int getIdleConnectionTimeout()
Return the idle connection timeout value associated with this connection.

Returns:
the idle connection timeout value in milliseconds.

setIdleConnectionTimeout

public void setIdleConnectionTimeout(int ms)
Set the idle connection timeout value associated with this connection. This is the number of milliseconds to wait before closing an idle connection. Setting the value to 0 means idle connections are never automatically closed. If this is not specified the default idle connection timeout value is used.

Parameters:
ms - milliseconds to wait before closing an idle connection.

getDefaultIdleConnectionTimeout

public static int getDefaultIdleConnectionTimeout()
Return the default idle connection timeout value.

Returns:
the default idle connection timeout value in milliseconds.

setDefaultIdleConnectionTimeout

public static void setDefaultIdleConnectionTimeout(int ms)
Set the default idle connection timeout value. This is the number of milliseconds to wait before closing an idle connection. Setting the value to 0 means idle connections are never automatically closed. The default value for this is 14000 (14 seconds). This value was chosen to be slightly less than the default KeepAliveTimeout value for the Apache web server. This is equivalent to setting the com.oaklandsw.http.idleConnectionTimeout property.

Parameters:
ms - milliseconds to wait before closing an idle connection.

setDefaultIdleConnectionTimeout

public static void setDefaultIdleConnectionTimeout()
Set the default idle connection timeout value to its default value (14 seconds).


getIdleConnectionPing

public int getIdleConnectionPing()
Return the idle connection ping value associated with this connection.

Returns:
the idle connection ping value in milliseconds.

setIdleConnectionPing

public void setIdleConnectionPing(int ms)
Set the idle connection ping value associated with this connection. This is used to ping the connection before sending a POST request. The ping is issued if the connection was idle for at least the number of milliseconds specified. Setting the value to 0 means idle connections are never pinged before a POST request. If this is not specified the default idle connection ping value is used.

Parameters:
ms - milliseconds to wait before pinging an idle connection.

getDefaultIdleConnectionPing

public static int getDefaultIdleConnectionPing()
Return the default idle connection ping value.

Returns:
the default idle connection ping value in milliseconds.

setDefaultIdleConnectionPing

public static void setDefaultIdleConnectionPing(int ms)
Set the default idle connection ping value. This is used to ping the connection before sending a POST request. The ping is issued if the connection was idle for at least the number of milliseconds specified. an idle connection. Setting the value to 0 means idle connections are never pinged before a POST request. The default value for this is 0 (this feature is disabled). This is equivalent to setting the com.oaklandsw.http.idleConnectionPing property.

Parameters:
ms - milliseconds to wait before pinging an idle connection.

setDefaultIdleConnectionPing

public static void setDefaultIdleConnectionPing()
Set the default idle connection ping value to its default value (0 seconds).


getExplicitClose

public static boolean getExplicitClose()
Returns true if an explicit close is required, false otherwise.

Returns:
the value of the explicit close flag.

setExplicitClose

public static void setExplicitClose(boolean explicitClose)
Sets all connections to require the InputStream to be obtained using a call to getInputStream(), and for that stream to be closed. If this is specified, this can result in better performance as the data associated with the connection is not read unless the stream associated with the connection is read. This is equivalent to setting the com.oaklandsw.http.explicitClose property to anything.

Here are the rules for using this option:

Parameters:
explicitClose - the value for explicit closing of the connection.

setMaxConnectionsPerHost

public static void setMaxConnectionsPerHost(int maxConnections)
Set the maximum number of connections allowed for a given host:port. Per RFC 2616 section 8.1.4, this value defaults to 2.

Note that this refers to the connections to the target host of the request, it does not refer to the maximum number of connections to a proxy server. The maximum number of connections to a proxy server is always unlimited.

Parameters:
maxConnections - a number of connections allowed for each host:port, specify -1 for an unlimited number of connections.

getMaxConnectionsPerHost

public static int getMaxConnectionsPerHost()
Get the maximum number of connections allowed for a given host:port.

Returns:
The maximum number of connections allowed for a given host:port.

setUse10KeepAlive

public static void setUse10KeepAlive(boolean use)
Set the option to include the HTTP 1.0 Keep-Alive headers in HTTP requests. The default is that they are included.

Parameters:
use - true if HTTP 1.0 Keep-Alive headers are included

getUse10KeepAlive

public static boolean getUse10KeepAlive()
Get the option to include the HTTP 1.0 Keep-Alive headers in HTTP requests.

Returns:
true if HTTP 1.0 Keep-Alive headers are included

setTries

public static void setTries(int tries)
                     throws java.lang.IllegalArgumentException
Set the number of times an idempotent request is to be tried before considering it a failure. This value defaults to 3.

Parameters:
tries - the number of times to try the request.
Throws:
java.lang.IllegalArgumentException

getTries

public static int getTries()
Get the number of times an idempotent request is tried.

Returns:
The number of times to try the request.

setRetryInterval

public static void setRetryInterval(int ms)
Set the interval to wait before each retry of a failed request. This value defaults to 50 (milliseconds).

Parameters:
ms - the interval to wait in milliseconds.

getRetryInterval

public static int getRetryInterval()
Get the interval to wait before each retry of a failed request.

Returns:
The number of milliseconds to wait before retrying.

setProxyHost

public static void setProxyHost(java.lang.String host)
Sets the host to be used as a proxy server.

Note that when this is called, all existing connections are closed, since the existing connections are no longer going to the desired destination.

Parameters:
host - the name of the host to be used as a proxy server.

getProxyHost

public static java.lang.String getProxyHost()
Returns the current value of the proxy server host.

Returns:
the proxy host.

setConnectionProxyHost

public void setConnectionProxyHost(java.lang.String host)
Sets the host to be used as a proxy server for this connection.

This must be called before the connection is connected.

Parameters:
host - the name of the host to be used as a proxy server.

getConnectionProxyHost

public java.lang.String getConnectionProxyHost()
Returns the current value of the proxy server host on this connection.

Returns:
the proxy host.

setProxyPort

public static void setProxyPort(int port)
Sets the port on the proxy server host.

Note that when this is called, all existing connections are closed, since the existing connections are no longer going to the desired destination.

Parameters:
port - the port number of the proxy server.

getProxyPort

public static int getProxyPort()
Returns the current value of the proxy server port number.

Returns:
the proxy port.

setConnectionProxyPort

public void setConnectionProxyPort(int port)
Sets the port on the proxy server host.

This must be called before the connection is connected.

Parameters:
port - the port number of the proxy server.

getConnectionProxyPort

public int getConnectionProxyPort()
Returns the current value of the proxy server port number.

Returns:
the proxy port.

setNonProxyHosts

public static void setNonProxyHosts(java.lang.String hosts)
Sets the hosts to be excluded from the proxy mechanism.

Parameters:
hosts - a list of hosts separated by the pipe ("|") character. Each host is a regular expression that is matched against the host being connected to. If the host matches the regular expression, it is not proxied.

getNonProxyHosts

public static java.lang.String getNonProxyHosts()
Returns the current value of the hosts to not be accessed through the proxy server.

Returns:
the non-proxied hosts.

closeAllPooledConnections

public static void closeAllPooledConnections()
Close all pooled connections that are not currently in use.


dumpConnectionPool

public static void dumpConnectionPool()
Prints all pooled connections to System.out.


getCipherSuite

public java.lang.String getCipherSuite()
Returns the cipher suite associated with this connection.

Returns:
the Cipher Suite associated with the SSL connection.

getLocalCertificates

public java.security.cert.Certificate[] getLocalCertificates()
Returns the certificates(s) that were sent to the server when the connection was established. Note: this method does not work on implementations prior to 1.4.

Returns:
the local Certificates associated with the SSL connection
Since:
JDK 1.4

getServerCertificates

public java.security.cert.Certificate[] getServerCertificates()
                                                       throws javax.net.ssl.SSLPeerUnverifiedException
Returns the server's certificate chain that was established when the session was setup. Note: this method does not work on implementations prior to 1.4.

Returns:
the server Certificates associated with the SSL connection
Throws:
javax.net.ssl.SSLPeerUnverifiedException
Since:
JDK 1.4

getDefaultHostnameVerifier

public static HostnameVerifier getDefaultHostnameVerifier()
Returns the default hostname verifier used for SSL connections.

Returns:
the default hostname verifier associated with the SSL connection

setDefaultHostnameVerifier

public static void setDefaultHostnameVerifier(HostnameVerifier verifier)
Sets the default hostname verifier used for SSL connections


getHostnameVerifier

public HostnameVerifier getHostnameVerifier()
Returns the hostname verifier used for this SSL connection.

Returns:
the default hostname verifier associated with the SSL connection

setHostnameVerifier

public void setHostnameVerifier(HostnameVerifier verifier)
Sets the hostname verifier used for this SSL connection


getDefaultSSLSocketFactory

public static javax.net.ssl.SSLSocketFactory getDefaultSSLSocketFactory()
Returns the default SSL socket factory used for SSL connections.


setDefaultSSLSocketFactory

public static void setDefaultSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
Sets the default SSL socket factory used for SSL connections.


getSSLSocketFactory

public javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
Returns the SSL socket factory used this SSL connection.


setSSLSocketFactory

public void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
Sets the SSL socket factory used for this SSL connection.


setNtlmPreferredEncoding

public static void setNtlmPreferredEncoding(int encoding)
Sets the preferred encoding for NTLM authenticate messages. By default the preferred encoding is Unicode, this method can be used to override that. The preferred encoding is sent only if it is an allowed encoding as indicated by the challenge message.


getNtlmPreferredEncoding

public static int getNtlmPreferredEncoding()
Gets the preferred encoding for NTLM messages.

Returns:
an int, the preferred encoding.


Copyright © 2002-2005 Oakland Software Incorporated. All Rights Reserved.