|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.net.HttpConnection
Use this class to create an HttpConnection with a Web Server and to read in the data for the connection.
To use this do the following:
| Field Summary | |
String |
command
This is the command to be sent to the server. |
protected Socket |
connectedSocket
|
int |
contentLength
This is the length of the document read in, valid after a connection call. |
static int |
DataReady
|
String |
document
The document to fetch/submit. |
boolean |
documentIsEncoded
If the document you supplied is already URL encoded, set this to true. |
PropertyList |
documentProperties
This is the list of properties for the server and document. |
String |
host
The host to connect to. |
boolean |
keepAliveMode
Set this to true for keep alive mode requests. |
protected Socket |
openSocket
|
int |
port
The port to connect to. |
PropertyList |
requestorProperties
These are the properties that will be sent to the WebServer. |
String |
requestVersion
This is the version sent to the server. |
int |
responseCode
This is the response code from the server. |
static int |
SocketConnected
|
| Constructor Summary | |
HttpConnection(String url)
Create an HttpConnection with an http:// URL. |
|
HttpConnection(String host,
int port,
String document)
Create a new HttpConnection to the specified host and port to fetch the specified document. |
|
HttpConnection(URL url)
|
|
| Method Summary | |
void |
addRequestorProperty(String name,
String property)
Add a non-exclusive requestor property. |
Socket |
connect()
This makes the connection, blocking the current thread. |
Handle |
connectAsync()
Connect asynchronously. |
Handle |
connectAsync(TextCodec serverTextDecoder)
Connect asynchronously. |
Socket |
connectSocketOnly()
Connect to the server and save the socket for later use as the "connectedSocket" field. |
String |
getEncodedDocument()
|
InputStream |
getInputStream()
Get an InputStream to read in the data. |
PropertyList |
getRequestorProperties()
Returns the requestor properties. |
ByteArray |
readData(Socket connection)
Read in the document body from the Socket. |
Handle |
readInData()
Read in all the data from the Socket. |
Handle |
readInData(Socket connection)
Read in all the data from the Socket. |
Handle |
readInText(Socket connection,
TextCodec documentTextDecoder)
Read in all the data from the Socket, converting it to text using the specified codec. |
CharArray |
readText(Socket connection,
TextCodec documentTextDecoder)
Read in the document body from the Socket. |
HttpConnection |
redirectTo()
Call this after a successful connection. |
void |
setAlreadyOpenSocket(Socket sock)
If a connection has already been made to the server, then you can call this method and the HttpConnection protocol will be done over this Socket. |
void |
setPostData(Object data)
Set the data to post out as either a Stream, InputStream or byte[] or ByteArray. |
void |
setPostDataLength(int length)
This sets the "Content-Length" requestor property to be the specified length. |
void |
setRequestorProperty(String name,
String property)
Set an exclusive requestor property. |
String |
toURLString()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
public String host
public int port
public String document
public String command
public String requestVersion
public PropertyList requestorProperties
public PropertyList documentProperties
public int responseCode
public boolean documentIsEncoded
public boolean keepAliveMode
public int contentLength
protected Socket openSocket
protected Socket connectedSocket
public static final int SocketConnected
public static final int DataReady
| Constructor Detail |
public HttpConnection(String host,
int port,
String document)
host - The host to connect to.port - The port to connect on.document - the document to get.public HttpConnection(String url)
url - The full url, starting with http://public HttpConnection(URL url)
| Method Detail |
public PropertyList getRequestorProperties()
public void setPostData(Object data)
data - the data to post either as a Stream, InputStream, byte[] or ByteArraypublic void setPostDataLength(int length)
length - the number of bytes to be posted.
public void setRequestorProperty(String name,
String property)
name - The name of the property.property - The value of the property.
public void addRequestorProperty(String name,
String property)
name - The name of the property.property - The value of the property.public void setAlreadyOpenSocket(Socket sock)
sock - The already connected socket.public String toURLString()
public String getEncodedDocument()
public HttpConnection redirectTo()
public Handle readInData(Socket connection)
connection - The socket returned by a connect() call.
public Handle readInData()
public InputStream getInputStream()
throws IOException
IOException
public ByteArray readData(Socket connection)
throws IOException
connection - The socket returned by a connect() call.
IOException
public Handle readInText(Socket connection,
TextCodec documentTextDecoder)
connection - The socket returned by a connect() call.documentTextDecoder - The text codec to use to convert the bytes read in into text. If
this is null then a simple Ascii codec will be used.
public CharArray readText(Socket connection,
TextCodec documentTextDecoder)
throws IOException
connection - The socket returned by a connect() call.documentTextDecoder - The text codec to use to convert the bytes read in into text. If
this is null then a simple Ascii codec will be used.
IOExceptionpublic Handle connectAsync()
public Handle connectAsync(TextCodec serverTextDecoder)
serverTextDecoder - The text decoder to convert the server and requestor properties data into text.
public Socket connect()
throws IOException
IOException - if there was an error connecting or getting the data.
public Socket connectSocketOnly()
throws IOException
IOException - if a connection could not be made.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||