A connection to an HTTP server.
HTTPS_PORT
public static final int HTTPS_PORT
The default HTTPS port.
- 443
HTTP_PORT
public static final int HTTP_PORT
The default HTTP port.
- 80
connectionTimeout
protected final int connectionTimeout
The connection timeout for connecting the underlying socket.
cookieManager
protected CookieManager cookieManager
The cookie manager for this connection.
hostname
protected final String hostname
The host name of the server to connect to.
in
protected InputStream in
The socket input stream.
majorVersion
protected int majorVersion
The major version of HTTP supported by this client.
minorVersion
protected int minorVersion
The minor version of HTTP supported by this client.
out
protected OutputStream out
The socket output stream.
port
protected final int port
The port to connect to.
proxyHostname
protected String proxyHostname
The host name of the proxy to connect to.
proxyPort
protected int proxyPort
The port on the proxy to connect to.
secure
protected final boolean secure
Whether the connection should use transport level security (HTTPS).
socket
protected Socket socket
The socket this connection communicates on.
timeout
protected final int timeout
The read timeout for reads on the underlying socket.
HTTPConnection
public HTTPConnection(String hostname)
Creates a new HTTP connection.
hostname
- the name of the host to connect to
HTTPConnection
public HTTPConnection(String hostname,
boolean secure)
Creates a new HTTP or HTTPS connection.
hostname
- the name of the host to connect tosecure
- whether to use a secure connection
HTTPConnection
public HTTPConnection(String hostname,
boolean secure,
int connectionTimeout,
int timeout)
Creates a new HTTP or HTTPS connection on the specified port.
hostname
- the name of the host to connect tosecure
- whether to use a secure connectionconnectionTimeout
- the connection timeouttimeout
- the socket read timeout
HTTPConnection
public HTTPConnection(String hostname,
int port)
Creates a new HTTP connection on the specified port.
hostname
- the name of the host to connect toport
- the port on the host to connect to
HTTPConnection
public HTTPConnection(String hostname,
int port,
boolean secure)
Creates a new HTTP or HTTPS connection on the specified port.
hostname
- the name of the host to connect toport
- the port on the host to connect tosecure
- whether to use a secure connection
HTTPConnection
public HTTPConnection(String hostname,
int port,
boolean secure,
int connectionTimeout,
int timeout)
Creates a new HTTP or HTTPS connection on the specified port.
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 timeout
addConnectionListener
public void addConnectionListener(gnu.inet.http.event.ConnectionListener l)
addRequestListener
public void addRequestListener(gnu.inet.http.event.RequestListener l)
close
public void close()
throws IOException
Closes this connection.
closeConnection
protected void closeConnection()
throws IOException
Closes the underlying socket, if any.
fireConnectionEvent
protected void fireConnectionEvent(int type)
fireRequestEvent
protected void fireRequestEvent(int type,
Request request)
getCookieManager
public CookieManager getCookieManager()
Returns the cookie manager in use for this connection.
getHostName
public String getHostName()
Returns the name of the host to connect to.
getInputStream
protected InputStream getInputStream()
throws IOException
getOutputStream
protected OutputStream getOutputStream()
throws IOException
getPort
public int getPort()
Returns the port on the host to connect to.
getSocket
protected Socket getSocket()
throws IOException
Retrieves the socket associated with this connection.
This creates the socket if necessary.
getURI
protected String getURI()
Returns a URI representing the connection.
This does not include any request path component.
getVersion
public String getVersion()
Returns the HTTP version string supported by this connection.
HTTPConnection
isSecure
public boolean isSecure()
Indicates whether to use a secure connection or not.
isUsingProxy
public boolean isUsingProxy()
Indicates whether this connection is using an HTTP proxy.
newRequest
public Request newRequest(String method,
String path)
Creates a new request using this connection.
method
- the HTTP method to invokepath
- the URI-escaped RFC2396 abs_path
with
optional query part
removeConnectionListener
public void removeConnectionListener(gnu.inet.http.event.ConnectionListener l)
removeRequestListener
public void removeRequestListener(gnu.inet.http.event.RequestListener l)
setCookieManager
public void setCookieManager(CookieManager cookieManager)
Sets the cookie manager to use for this connection.
cookieManager
- the cookie manager
setProxy
public void setProxy(String hostname,
int port)
Directs this connection to use the specified proxy.
hostname
- the proxy host nameport
- the port on the proxy to connect to
setVersion
public void setVersion(int majorVersion,
int minorVersion)
Sets the HTTP version supported by this connection.
majorVersion
- the major versionminorVersion
- the minor version