|
|||||||||
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 |
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. |
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 |
shutdownOutput()
Shutdown my Socket 's output, via
Socket.shutdownOutput() . |
void |
write(byte[] data)
Write the specified bytes 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 topublic 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 topublic 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 toport
- the port I should connect tosecure
- when true, connect via HTTPS (SSL)Method Detail |
public java.lang.String getHost()
public void setHost(java.lang.String host) throws java.lang.IllegalStateException
host
- the host I should connect tojava.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 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 open() throws java.io.IOException
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 occurspublic 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 occurspublic 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.
java.lang.IllegalStateException
- if I am not connectedjava.io.IOException
- if an I/O problem occurspublic void write(byte[] data) throws java.io.IOException, java.lang.IllegalStateException
java.lang.IllegalStateException
- if I am not connectedjava.io.IOException
- if an I/O problem occurspublic void writeLine(byte[] data) throws java.io.IOException, java.lang.IllegalStateException
java.lang.IllegalStateException
- if I am not connectedjava.io.IOException
- if an I/O problem occurspublic void writeLine() throws java.io.IOException, java.lang.IllegalStateException
java.lang.IllegalStateException
- if I am not connectedjava.io.IOException
- if an I/O problem occurspublic void print(java.lang.String data) throws java.io.IOException, java.lang.IllegalStateException
java.lang.IllegalStateException
- if I am not connectedjava.io.IOException
- if an I/O problem occurspublic void printLine(java.lang.String data) throws java.io.IOException, java.lang.IllegalStateException
java.lang.IllegalStateException
- if I am not connectedjava.io.IOException
- if an I/O problem occurspublic void printLine() throws java.io.IOException, java.lang.IllegalStateException
java.lang.IllegalStateException
- if I am not connectedjava.io.IOException
- if an I/O problem occurspublic 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() throws java.io.IOException
Socket
's output, via
Socket.shutdownOutput()
.java.io.IOException
- if an I/O problem occurspublic void close() throws java.io.IOException
java.io.IOException
- if an I/O problem occursprotected void closeSocketAndStreams()
protected void assertNotOpen() throws java.lang.IllegalStateException
IllegalStateException
if I am connected.protected void assertOpen() throws java.lang.IllegalStateException
IllegalStateException
if I am not connected.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |