public class HttpConnectionTask extends Task
Handle.ObjectDiscarder, Handle.WaitOnChange
Modifier and Type | Field and Description |
---|---|
ByteArray |
byteBuffer
An optional ByteArray for use as a byte buffer when reading in the data.
|
int |
bytesReadIn
This keeps track of the number of bytes read in.
|
CharArray |
charBuffer
An optional CharArray for use as a char buffer when reading in the data in
text mode.
|
Socket |
connectedSocket
After reading in the response, if keepConnectionAlive is true, then this
will be the connected socket.
|
HttpConnection |
connection
This is the connection being used.
|
Object |
destination
This is the destination object that will hold the received data.
|
int |
inputBufferSize
The size of the input buffer to use when reading in data.
|
boolean |
keepConnectionAlive
If this is true then the connection will not be closed after the connection
process.
|
boolean |
readInAsText
Set this true to decode the incoming bytes as text instead of bytes.
|
TextCodec |
textCodec
If readInAsText is true then you can specify the TextCodec that will be used here.
|
Aborted, Changed, DEFAULT_CHANGE_ACCEPT_TIME, DEFAULT_PROGRESS_RESOLUTION, doing, error, Failed, Failure, OPTION_STOP_IF_NOT_SET, OPTION_TIMEOUT_IF_NOT_SET, progress, progressResolution, returnCode, returnValue, Running, shouldStop, startTime, state, Stopped, stopReason, subHandle, Succeeded, Success, waitChangeAcceptedTime
Constructor and Description |
---|
HttpConnectionTask() |
HttpConnectionTask(HttpConnection connection)
Create a new HttpConnectionTask using the specified connection.
|
Modifier and Type | Method and Description |
---|---|
int |
connect(TimeOut t)
This calls start(), waits for completion and returns number of bytes read.
|
protected boolean |
connectionMade(PropertyList documentProperties,
int responseCode)
This is called once a successful connection and request is made.
|
protected void |
doRun()
Override this to provide functionality for the Task.
|
protected TextCodec |
getCodec()
Get a copy of the TextCodec being used.
|
protected boolean |
readInData(Handle handle,
InputStream in,
int contentLength)
You do not need to override this - it reads in the data provided by the server
and saves it in the destination.
|
protected void |
setupConnection(HttpConnection connection,
String redirectingTo)
This is called before the initial connection or, in the case of a redirect,
before the redirected connection is made.
|
complete, getDaemon, getThread, interrupt, run, setDaemon, setThreadGroup, sleep, start, start
addParent, changeAccepted, changed, check, check, checkAbortFail, checkAny, checkChangeAccepted, checkFailure, convertError, doChangeTo, fail, getChangeState, getErrorText, getFinalReturnValue, getProperties, getReturnValue, getStoppableWaitOnSuccess, getUnwrappedReturnValue, hasStopped, newWaitOnChange, removeParent, resetProgress, set, setFlags, setProgress, setProgress, setResult, setReturnValue, startDoing, stop, succeed, succeeded, throwErrorIfNotStopped, throwRuntimeError, throwRuntimeError, throwRuntimeError, throwRuntimeError, timeout, timeout, waitChangeAccepted, waitForReturnValue, waitOn, waitOn, waitOn, waitOn, waitOnAny, waitOnAny, waitOnAny, waitOnAny, waitOnChange, waitOnResult, waitOnSuccess, waitOnSuccess, waitReturnValue, waitUntilCompletion, waitUntilCompletion, waitUntilStopped, waitUntilStopped, wasAborted, yield
public HttpConnection connection
public boolean readInAsText
public TextCodec textCodec
public int inputBufferSize
public ByteArray byteBuffer
public CharArray charBuffer
public boolean keepConnectionAlive
public Object destination
eve.util.ByteArray - the read in data is appended to the ByteArray.
If no destination is provided and readInAsText is false, then a ByteArray will be created
and used.
eve.util.CharArray - the read in data is converted to chars and appended to the CharArray.
If no destination is provided and readInAsText is true, then a CharArray will be created
and used.
java.lang.StringBuffer - the read in data is converted to chars and appended to the StringBuffer.
java.io.OutputStream - an output stream to send the incoming bytes to.
java.io.Writer - the read in data is converted to text and written to the Writer.
public int bytesReadIn
public Socket connectedSocket
public HttpConnectionTask(HttpConnection connection)
connection
- the HttpConnection to use. If it is null
then you must create one and set the connection field with it before calling
connect().public HttpConnectionTask()
public int connect(TimeOut t) throws IOException, InterruptedException, TimedOutException
t
- an optional TimeOut.IOException
- if an IOException occured during connection.InterruptedException
- if the Thread was interrupted.TimedOutException
- if the call timed out.protected void setupConnection(HttpConnection connection, String redirectingTo) throws IOException
connection
- the HttpConnection being used. This may be different to the
original one in the case of a redirect.redirectingTo
- if this setup is being done because of a redirect
then this will be non-null and hold the URL of the site the connection
is being redirected to.IOException
- if you don't wish to allow a redirect or if you want to
abort the connection for any reason.protected boolean connectionMade(PropertyList documentProperties, int responseCode) throws IOException
documentProperties
- the properties sent back by the server.responseCode
- the response code sent back by the server.IOException
- if you wish to abort further processing.protected TextCodec getCodec()
protected boolean readInData(Handle handle, InputStream in, int contentLength) throws IOException
handle
- a handle that is used to stop the process. If the stop() method
is called on the handle the method will return false.in
- the InputStream for the Socket.contentLength
- the number of bytes the content should be.IOException
- if an error occurs reading or storing the data.