|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.net.URLConnection
java.net.HttpURLConnection
com.oaklandsw.http.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 |
public static final java.lang.String HTTP_METHOD_GET
public static final java.lang.String HTTP_METHOD_POST
public static final java.lang.String HTTP_METHOD_PUT
public static final java.lang.String HTTP_METHOD_OPTIONS
public static final java.lang.String HTTP_METHOD_DELETE
public static final java.lang.String HTTP_METHOD_HEAD
public static final java.lang.String HTTP_METHOD_TRACE
public static final java.lang.String HTTP_METHOD_CONNECT
public static final int GET
public static final int POST
public static final int PUT
public static final int OPTIONS
public static final int DELETE
public static final int HEAD
public static final int TRACE
public static final int CONNECT
public static final int NTLM_ENCODING_UNICODE
public static final int NTLM_ENCODING_OEM
public static boolean _isSSLAvailable
Constructor Detail |
public HttpURLConnection()
public HttpURLConnection(java.net.URL urlParam)
java.net.HttpURLConnection#HttpURLConnection()
Method Detail |
public static HttpURLConnection openConnection(java.net.URL url)
URL.openConnection()
public void finalize()
public void setRequestMethod(java.lang.String meth) throws java.net.ProtocolException
java.net.ProtocolException
HttpURLConnection.setRequestMethod(String)
public void setRequestProperty(java.lang.String key, java.lang.String value)
URLConnection.setRequestProperty(String,String)
public void addRequestProperty(java.lang.String key, java.lang.String value)
URLConnection.addRequestProperty(String,String)
public java.lang.String getRequestProperty(java.lang.String key)
URLConnection.getRequestProperty(String)
public final void setInstanceFollowRedirects(boolean followRedirects)
followRedirects
- true to follow redirects, false otherwisepublic final boolean getInstanceFollowRedirects()
public java.io.OutputStream getOutputStream() throws java.io.IOException
java.io.IOException
URLConnection.getOutputStream()
public boolean usingProxy()
HttpURLConnection.usingProxy()
public void connect() throws java.io.IOException
java.io.IOException
URLConnection.connect()
public boolean isConnected()
public int getResponseCode() throws java.io.IOException
java.io.IOException
HttpURLConnection.getResponseCode()
public java.lang.String getResponseMessage() throws java.io.IOException
java.io.IOException
HttpURLConnection.getResponseMessage()
public java.lang.String getHeaderField(java.lang.String name)
URLConnection.getHeaderField(String)
public java.lang.String getHeaderFieldKey(int keyPosition)
HttpURLConnection.getHeaderFieldKey(int)
public java.lang.String getHeaderField(int position)
HttpURLConnection.getHeaderField(int)
public java.io.InputStream getInputStream() throws java.io.IOException
java.io.IOException
URLConnection.getInputStream()
public java.io.InputStream getErrorStream()
HttpURLConnection.getErrorStream()
public void disconnect()
HttpURLConnection.disconnect()
public static void setDefaultUserAgent(HttpUserAgent userAgent)
public static HttpUserAgent getDefaultUserAgent()
public void setUserAgent(HttpUserAgent userAgent)
userAgent
- a object that implements the HttpUserAgent interface.HttpUserAgent
public HttpUserAgent getUserAgent()
HttpUserAgent
public boolean getDoAuthentication()
public void setDoAuthentication(boolean doAuthentication)
The default is true.
doAuthentication
- true to process authenticationspublic int getTimeout()
public void setTimeout(int ms)
ms
- milliseconds to wait for a connection or response.public int getConnectionTimeout()
public void setConnectionTimeout(int ms)
ms
- milliseconds to wait for the sockect connection.public int getRequestTimeout()
public void setRequestTimeout(int ms)
ms
- milliseconds to wait for the respone.public static int getDefaultTimeout()
public static void setDefaultTimeout(int ms)
com.oaklandsw.http.timeout
property. This is the same as
calling setDefaultConnectTimeout() and setDefaultRequestTimeout() with
the same value.
ms
- milliseconds to wait for a connection or response.public static int getDefaultConnectionTimeout()
public static void setDefaultConnectionTimeout(int ms)
ms
- milliseconds to wait for a socket connection.public static int getDefaultRequestTimeout()
public static void setDefaultRequestTimeout(int ms)
ms
- milliseconds to wait for a response.public int getIdleConnectionTimeout()
public void setIdleConnectionTimeout(int ms)
ms
- milliseconds to wait before closing an idle connection.public static int getDefaultIdleConnectionTimeout()
public static void setDefaultIdleConnectionTimeout(int ms)
com.oaklandsw.http.idleConnectionTimeout
property.
ms
- milliseconds to wait before closing an idle connection.public static void setDefaultIdleConnectionTimeout()
public int getIdleConnectionPing()
public void setIdleConnectionPing(int ms)
ms
- milliseconds to wait before pinging an idle connection.public static int getDefaultIdleConnectionPing()
public static void setDefaultIdleConnectionPing(int ms)
com.oaklandsw.http.idleConnectionPing
property.
ms
- milliseconds to wait before pinging an idle connection.public static void setDefaultIdleConnectionPing()
public static boolean getExplicitClose()
public static void setExplicitClose(boolean explicitClose)
com.oaklandsw.http.explicitClose
property to anything.
Here are the rules for using this option:
explicitClose
- the value for explicit closing of the connection.public static void setMaxConnectionsPerHost(int maxConnections)
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.
maxConnections
- a number of connections allowed for each host:port, specify -1
for an unlimited number of connections.public static int getMaxConnectionsPerHost()
public static void setUse10KeepAlive(boolean use)
use
- true if HTTP 1.0 Keep-Alive headers are includedpublic static boolean getUse10KeepAlive()
public static void setTries(int tries) throws java.lang.IllegalArgumentException
tries
- the number of times to try the request.
java.lang.IllegalArgumentException
public static int getTries()
public static void setRetryInterval(int ms)
ms
- the interval to wait in milliseconds.public static int getRetryInterval()
public static void setProxyHost(java.lang.String host)
Note that when this is called, all existing connections are closed, since the existing connections are no longer going to the desired destination.
host
- the name of the host to be used as a proxy server.public static java.lang.String getProxyHost()
public void setConnectionProxyHost(java.lang.String host)
This must be called before the connection is connected.
host
- the name of the host to be used as a proxy server.public java.lang.String getConnectionProxyHost()
public static void setProxyPort(int port)
Note that when this is called, all existing connections are closed, since the existing connections are no longer going to the desired destination.
port
- the port number of the proxy server.public static int getProxyPort()
public void setConnectionProxyPort(int port)
This must be called before the connection is connected.
port
- the port number of the proxy server.public int getConnectionProxyPort()
public static void setNonProxyHosts(java.lang.String hosts)
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.public static java.lang.String getNonProxyHosts()
public static void closeAllPooledConnections()
public static void dumpConnectionPool()
public java.lang.String getCipherSuite()
public java.security.cert.Certificate[] getLocalCertificates()
public java.security.cert.Certificate[] getServerCertificates() throws javax.net.ssl.SSLPeerUnverifiedException
javax.net.ssl.SSLPeerUnverifiedException
public static HostnameVerifier getDefaultHostnameVerifier()
public static void setDefaultHostnameVerifier(HostnameVerifier verifier)
public HostnameVerifier getHostnameVerifier()
public void setHostnameVerifier(HostnameVerifier verifier)
public static javax.net.ssl.SSLSocketFactory getDefaultSSLSocketFactory()
public static void setDefaultSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
public javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
public void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
public static void setNtlmPreferredEncoding(int encoding)
public static int getNtlmPreferredEncoding()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |