|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--org.apache.commons.httpclient.HttpConnection
An abstraction of an HTTP InputStream and OutputStream
pair, together with the relevant attributes.
| Constructor Summary | |
HttpConnection(java.lang.String host,
int port)
Constructor. |
|
HttpConnection(java.lang.String host,
int port,
boolean secure)
Constructor. |
|
HttpConnection(java.lang.String proxyHost,
int proxyPort,
java.lang.String host,
int port)
Constructor. |
|
HttpConnection(java.lang.String proxyHost,
int proxyPort,
java.lang.String host,
int port,
boolean secure)
Fully-specified constructor. |
|
| Method Summary | |
protected void |
assertNotOpen()
Throw an IllegalStateException if I am connected. |
protected void |
assertOpen()
Throw an IllegalStateException if I am not connected. |
void |
close()
Close my socket and streams. |
protected void |
closeSocketAndStreams()
Close everything out. |
java.lang.String |
getHost()
Return my host. |
int |
getPort()
Return my port. |
java.lang.String |
getProtocol()
Get the protocol. |
java.lang.String |
getProxyHost()
Return my proxy host. |
int |
getProxyPort()
Return my proxy port. |
java.io.OutputStream |
getRequestOutputStream()
Return a RequestOutputStream suitable for writing (possibly
chunked) bytes to my OutputStream. |
java.io.OutputStream |
getRequestOutputStream(boolean useChunking)
Return a RequestOutputStream suitable for writing (possibly
chunked) bytes to my OutputStream. |
java.io.InputStream |
getResponseInputStream(HttpMethod method)
Return a ResponseInputStream suitable for reading (possibly
chunked) bytes from my InputStream. |
boolean |
isOpen()
Return true if I am connected, false otherwise. |
boolean |
isProxied()
Return true if I am (or I will be) connected via a proxy, false otherwise. |
boolean |
isSecure()
Return true if I will (or I am) connected over a secure (HTTPS/SSL) protocol. |
boolean |
isTransparent()
Indicates if the connection is completely transparent from end to end. |
void |
open()
Open this connection to the current host and port (via a proxy if so configured). |
void |
print(java.lang.String data)
Write the specified String (as bytes) to my output stream. |
void |
printLine()
Write "\r\n".getBytes() to my output stream. |
void |
printLine(java.lang.String data)
Write the specified String (as bytes), followed by "\r\n".getBytes() to my output stream. |
java.lang.String |
readLine()
Read up to "\r\n" from my (unchunked) input stream. |
void |
setHost(java.lang.String host)
Set my host. |
void |
setPort(int port)
Set my port. |
void |
setProxyHost(java.lang.String host)
Set the host I should proxy through. |
void |
setProxyPort(int port)
Set the port I should proxy through. |
void |
setSecure(boolean secure)
Set whether or not I should connect over HTTPS (SSL). |
void |
setSoTimeout(int timeout)
Set my Socket's timeout, via Socket.setSoTimeout(int). |
void |
setSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
Specifies an alternative factory for SSL sockets. |
void |
shutdownOutput()
Shutdown my Socket's output, via Socket.shutdownOutput(). |
void |
tunnelCreated()
Calling this method indicates that the proxy has successfully created the tunnel to the host. |
void |
write(byte[] data)
Write the specified bytes to my output stream. |
void |
write(byte[] data,
int offset,
int length)
Write length bytes in data starting at offset to my output stream. |
void |
writeLine()
Write "\r\n".getBytes() to my output stream. |
void |
writeLine(byte[] data)
Write the specified bytes, followed by "\r\n".getBytes() to my output stream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public HttpConnection(java.lang.String host,
int port)
host - the host I should connect toport - the port I should connect to
public HttpConnection(java.lang.String host,
int port,
boolean secure)
host - the host I should connect toport - the port I should connect tosecure - when true, connect via HTTPS (SSL)
public HttpConnection(java.lang.String proxyHost,
int proxyPort,
java.lang.String host,
int port)
proxyHost - the host I should proxy viaproxyPort - the port I should proxy viahost - the host I should connect toport - the port I should connect to
public HttpConnection(java.lang.String proxyHost,
int proxyPort,
java.lang.String host,
int port,
boolean secure)
proxyHost - the host I should proxy viaproxyPort - the port I should proxy viahost - the host I should connect to. Parameter value must be non-null.port - the port I should connect tosecure - when true, connect via HTTPS (SSL)| Method Detail |
public void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
factory
is null the default implementation is used.factory - An instance of a SSLSocketFactory or null.java.lang.IllegalStateException - If called after the connection was openedpublic java.lang.String getHost()
public void setHost(java.lang.String host)
throws java.lang.IllegalStateException
host - the host I should connect to. Parameter value must be non-null.java.lang.IllegalStateException - if I am already connectedpublic int getPort()
public void setPort(int port)
throws java.lang.IllegalStateException
port - the port I should connect tojava.lang.IllegalStateException - if I am already connectedpublic java.lang.String getProxyHost()
public void setProxyHost(java.lang.String host)
throws java.lang.IllegalStateException
host - the host I should proxy through.java.lang.IllegalStateException - if I am already connectedpublic int getProxyPort()
public void setProxyPort(int port)
throws java.lang.IllegalStateException
port - the host I should proxy through.java.lang.IllegalStateException - if I am already connectedpublic boolean isSecure()
public java.lang.String getProtocol()
public void setSecure(boolean secure)
throws java.lang.IllegalStateException
secure - whether or not I should connect over HTTPS (SSL).java.lang.IllegalStateException - if I am already connectedpublic boolean isOpen()
public boolean isProxied()
public void setSoTimeout(int timeout)
throws java.net.SocketException,
java.lang.IllegalStateException
Socket's timeout, via Socket.setSoTimeout(int). If the
connection is already open, the SO_TIMEOUT is changed. If no connection
is open, then subsequent connections will use the timeout value.timeout - the timeout valuejava.net.SocketException - - if there is an error in the underlying
protocol, such as a TCP error.java.lang.IllegalStateException - if I am not connected
public void open()
throws java.io.IOException
java.io.IOException - when there are errors opening the connection
public void tunnelCreated()
throws java.lang.IllegalStateException,
java.io.IOException
java.lang.IllegalStateException - if connection is not secure and proxied or
if the socket is already secure.java.io.IOException - if an error occured creating the secure socketpublic boolean isTransparent()
public java.io.OutputStream getRequestOutputStream()
throws java.io.IOException,
java.lang.IllegalStateException
RequestOutputStream suitable for writing (possibly
chunked) bytes to my OutputStream.java.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurs
public java.io.OutputStream getRequestOutputStream(boolean useChunking)
throws java.io.IOException,
java.lang.IllegalStateException
RequestOutputStream suitable for writing (possibly
chunked) bytes to my OutputStream.useChunking - when true the chunked transfer-encoding will
be usedjava.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurs
public java.io.InputStream getResponseInputStream(HttpMethod method)
throws java.io.IOException,
java.lang.IllegalStateException
ResponseInputStream suitable for reading (possibly
chunked) bytes from my InputStream.
If the given HttpMethod contains
a Transfer-Encoding: chunked header,
the returned stream will be configured
to read chunked bytes.
method - the http method to get the input stream fromjava.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurs
public void write(byte[] data)
throws java.io.IOException,
java.lang.IllegalStateException,
HttpRecoverableException
data - the data to be writtenHttpRecoverableException - if a SocketException occursjava.lang.IllegalStateException - if not connectedjava.io.IOException - if an I/O problem occurswrite(byte[],int,int)
public void write(byte[] data,
int offset,
int length)
throws java.io.IOException,
java.lang.IllegalStateException,
HttpRecoverableException
data - array containing the data to be written.offset - the start offset in the data.length - the number of bytes to write.HttpRecoverableException - if a SocketException occursjava.lang.IllegalStateException - if not connectedjava.io.IOException - if an I/O problem occurs
public void writeLine(byte[] data)
throws java.io.IOException,
java.lang.IllegalStateException,
HttpRecoverableException
data - the bytes to be writtenHttpRecoverableException - when socket exceptions occur writing datajava.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurs
public void writeLine()
throws java.io.IOException,
java.lang.IllegalStateException,
HttpRecoverableException
HttpRecoverableException - when socket exceptions occur writing
datajava.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurs
public void print(java.lang.String data)
throws java.io.IOException,
java.lang.IllegalStateException,
HttpRecoverableException
data - the string to be writtenHttpRecoverableException - when socket exceptions occur writing
datajava.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurs
public void printLine(java.lang.String data)
throws java.io.IOException,
java.lang.IllegalStateException,
HttpRecoverableException
data - the data to be writtenHttpRecoverableException - when socket exceptions occur writing
datajava.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurs
public void printLine()
throws java.io.IOException,
java.lang.IllegalStateException,
HttpRecoverableException
HttpRecoverableException - when socket exceptions occur writing
datajava.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurs
public java.lang.String readLine()
throws java.io.IOException,
java.lang.IllegalStateException
java.lang.IllegalStateException - if I am not connectedjava.io.IOException - if an I/O problem occurspublic void shutdownOutput()
Socket's output, via Socket.shutdownOutput().public void close()
protected void closeSocketAndStreams()
protected void assertNotOpen()
throws java.lang.IllegalStateException
IllegalStateException if I am connected.java.lang.IllegalStateException - if connected
protected void assertOpen()
throws java.lang.IllegalStateException
IllegalStateException if I am not connected.java.lang.IllegalStateException - if not connected
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||