public class HTTPConnection
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected int |
connectionTimeout
The connection timeout for connecting the underlying socket.
|
protected CookieManager |
cookieManager
The cookie manager for this connection.
|
protected java.lang.String |
hostname
The host name of the server to connect to.
|
static int |
HTTP_PORT
The default HTTP port.
|
static int |
HTTPS_PORT
The default HTTPS port.
|
protected java.io.InputStream |
in
The socket input stream.
|
protected int |
majorVersion
The major version of HTTP supported by this client.
|
protected int |
minorVersion
The minor version of HTTP supported by this client.
|
protected java.io.OutputStream |
out
The socket output stream.
|
protected int |
port
The port to connect to.
|
protected java.lang.String |
proxyHostname
The host name of the proxy to connect to.
|
protected int |
proxyPort
The port on the proxy to connect to.
|
protected boolean |
secure
Whether the connection should use transport level security (HTTPS).
|
protected java.net.Socket |
socket
The socket this connection communicates on.
|
protected int |
timeout
The read timeout for reads on the underlying socket.
|
Constructor and Description |
---|
HTTPConnection(java.lang.String hostname)
Creates a new HTTP connection.
|
HTTPConnection(java.lang.String hostname,
boolean secure)
Creates a new HTTP or HTTPS connection.
|
HTTPConnection(java.lang.String hostname,
boolean secure,
int connectionTimeout,
int timeout)
Creates a new HTTP or HTTPS connection on the specified port.
|
HTTPConnection(java.lang.String hostname,
int port)
Creates a new HTTP connection on the specified port.
|
HTTPConnection(java.lang.String hostname,
int port,
boolean secure)
Creates a new HTTP or HTTPS connection on the specified port.
|
HTTPConnection(java.lang.String hostname,
int port,
boolean secure,
int connectionTimeout,
int timeout)
Creates a new HTTP or HTTPS connection on the specified port.
|
Modifier and Type | Method and Description |
---|---|
void |
addConnectionListener(ConnectionListener l) |
void |
addRequestListener(RequestListener l) |
void |
close()
Closes this connection.
|
protected void |
closeConnection()
Closes the underlying socket, if any.
|
protected void |
fireConnectionEvent(int type) |
protected void |
fireRequestEvent(int type,
Request request) |
CookieManager |
getCookieManager()
Returns the cookie manager in use for this connection.
|
java.lang.String |
getHostName()
Returns the name of the host to connect to.
|
protected java.io.InputStream |
getInputStream() |
protected java.io.OutputStream |
getOutputStream() |
int |
getPort()
Returns the port on the host to connect to.
|
protected java.net.Socket |
getSocket()
Retrieves the socket associated with this connection.
|
protected java.lang.String |
getURI()
Returns a URI representing the connection.
|
java.lang.String |
getVersion()
Returns the HTTP version string supported by this connection.
|
boolean |
isSecure()
Indicates whether to use a secure connection or not.
|
boolean |
isUsingProxy()
Indicates whether this connection is using an HTTP proxy.
|
Request |
newRequest(java.lang.String method,
java.lang.String path)
Creates a new request using this connection.
|
void |
removeConnectionListener(ConnectionListener l) |
void |
removeRequestListener(RequestListener l) |
void |
setCookieManager(CookieManager cookieManager)
Sets the cookie manager to use for this connection.
|
void |
setProxy(java.lang.String hostname,
int port)
Directs this connection to use the specified proxy.
|
void |
setVersion(int majorVersion,
int minorVersion)
Sets the HTTP version supported by this connection.
|
public static final int HTTP_PORT
public static final int HTTPS_PORT
protected final java.lang.String hostname
protected final int port
protected final boolean secure
protected final int connectionTimeout
protected final int timeout
protected java.lang.String proxyHostname
protected int proxyPort
protected int majorVersion
protected int minorVersion
protected java.net.Socket socket
protected java.io.InputStream in
protected java.io.OutputStream out
protected CookieManager cookieManager
public HTTPConnection(java.lang.String hostname)
hostname
- the name of the host to connect topublic HTTPConnection(java.lang.String hostname, boolean secure)
hostname
- the name of the host to connect tosecure
- whether to use a secure connectionpublic HTTPConnection(java.lang.String hostname, boolean secure, int connectionTimeout, int timeout)
hostname
- the name of the host to connect tosecure
- whether to use a secure connectionconnectionTimeout
- the connection timeouttimeout
- the socket read timeoutpublic HTTPConnection(java.lang.String hostname, int port)
hostname
- the name of the host to connect toport
- the port on the host to connect topublic HTTPConnection(java.lang.String hostname, int port, boolean secure)
hostname
- the name of the host to connect toport
- the port on the host to connect tosecure
- whether to use a secure connectionpublic HTTPConnection(java.lang.String hostname, int port, boolean secure, int connectionTimeout, int timeout)
hostname
- the name of the host to connect toport
- the port on the host to connect tosecure
- whether to use a secure connectionconnectionTimeout
- the connection timeouttimeout
- the socket read timeoutpublic java.lang.String getHostName()
public int getPort()
public boolean isSecure()
public java.lang.String getVersion()
#version
public void setVersion(int majorVersion, int minorVersion)
majorVersion
- the major versionminorVersion
- the minor versionpublic void setProxy(java.lang.String hostname, int port)
hostname
- the proxy host nameport
- the port on the proxy to connect topublic boolean isUsingProxy()
public void setCookieManager(CookieManager cookieManager)
cookieManager
- the cookie managerpublic CookieManager getCookieManager()
public Request newRequest(java.lang.String method, java.lang.String path)
method
- the HTTP method to invokepath
- the URI-escaped RFC2396 abs_path
with
optional query partpublic void close() throws java.io.IOException
java.io.IOException
protected java.net.Socket getSocket() throws java.io.IOException
java.io.IOException
protected java.io.InputStream getInputStream() throws java.io.IOException
java.io.IOException
protected java.io.OutputStream getOutputStream() throws java.io.IOException
java.io.IOException
protected void closeConnection() throws java.io.IOException
java.io.IOException
protected java.lang.String getURI()
public void addConnectionListener(ConnectionListener l)
public void removeConnectionListener(ConnectionListener l)
protected void fireConnectionEvent(int type)
public void addRequestListener(RequestListener l)
public void removeRequestListener(RequestListener l)
protected void fireRequestEvent(int type, Request request)