|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
wjhk.jupload2.upload.helper.HTTPConnectionHelper
public class HTTPConnectionHelper
This class contains utilities to delegate network manipulation. It hides the
management for the current upload policy connection parameters.
This class goes through the following states, stored in the private
connectionStatus attribute:
initRequest(URL, String, boolean, boolean)
ByteArrayEncoderHTTP. The
connection switches to this status when the
initRequest(URL, String, boolean, boolean) is called.
sendRequest() method changes the connection to this
status.
readHttpResponse() is responsible to put the connectionHelper to
this status.
initRequest(URL, String, boolean, boolean), to start a new
request to the server. Using the same connectionHelper allows to use the same
network connection, when the allowHttpPersistent applet parameter is used.
| Field Summary | |
|---|---|
private boolean |
bChunkEnabled
Is chunk upload on for this request ? |
private boolean |
bLastChunk
Is it the last chunk ? |
private java.lang.String |
boundary
http boundary, for the posting multipart post. |
private ByteArrayEncoder |
byteArrayEncoder
The encoder that will contain the HTTP request. |
private int |
connectionStatus
Indicates where data sent to appendXxx method should be added. |
private HTTPInputStreamReader |
httpInputStreamReader
Contains the HTTP reader. |
private java.io.PushbackInputStream |
inputStream
This stream allows the applet to get the server response. |
private java.lang.String |
method
The HTTP method: POST, GET, HEAD... |
private java.io.DataOutputStream |
outputStream
This stream is open by sendRequest(). |
private java.net.Proxy |
proxy
The current proxy, if any |
private java.net.Socket |
socket
The network socket where the bytes should be written. |
private int |
STATUS_BEFORE_SERVER_CONNECTION
Indicates that the network connection to the server has not been opened. |
private int |
STATUS_CONNECTION_CLOSED
Indicates that the network connection to the server is now closed, that is: we've written the request, read the response, and free the server connection. |
private int |
STATUS_NOT_INITIALIZED
Indicates that the connection has not been initialized. |
private int |
STATUS_READING_RESPONSE
Indicates that the network connection to the server is opened, but the request has not been totally sent to the server. |
private int |
STATUS_WRITING_REQUEST
Indicates that the network connection to the server is opened, but the request has not been totally sent to the server. |
private boolean |
stop
Indicates if the user request to stop the upload. |
private UploadPolicy |
uploadPolicy
The current upload policy |
private java.net.URL |
url
The current URL |
private boolean |
useProxy
Should we use a proxy |
private boolean |
useSSL
Is SSL mode on ? |
| Constructor Summary | |
|---|---|
HTTPConnectionHelper(UploadPolicy uploadPolicy)
The standard constructor for this class. |
|
HTTPConnectionHelper(java.net.URL url,
java.lang.String method,
boolean bChunkEnabled,
boolean bLastChunk,
UploadPolicy uploadPolicy)
The standard constructor for this class. |
|
| Method Summary | |
|---|---|
HTTPConnectionHelper |
append(byte[] bytes)
Append bytes to the current query. |
HTTPConnectionHelper |
append(byte[] bytes,
int off,
int len)
Append bytes to the current query. |
HTTPConnectionHelper |
append(ByteArrayEncoder bae)
Appends a string to the current HTTP request. |
HTTPConnectionHelper |
append(int b)
Append bytes to the current query. |
HTTPConnectionHelper |
append(java.lang.String str)
write a string to the current HTTP request. |
private java.lang.String |
calculateRandomBoundary()
Construction of a random boundary, to separate the uploaded files, in the HTTP upload request. |
void |
close()
This method is the override of OutputStream.close() one. |
void |
dispose()
Releases all reserved resources. |
void |
flush()
Flushes the output stream. |
java.lang.String |
getBoundary()
|
ByteArrayEncoder |
getByteArrayEncoder()
Return the current ByteArrayEncoder. |
java.io.PushbackInputStream |
getInputStream()
get the input stream, where HTTP server response can be read. |
java.lang.String |
getMethod()
Get the HTTP method (HEAD, POST, GET...) |
java.io.OutputStream |
getOutputStream()
get the output stream, where HTTP data can be written. |
java.lang.String |
getResponseBody()
Get the last response body. |
java.lang.String |
getResponseHeaders()
Get the headers of the HTTP response. |
java.lang.String |
getResponseMsg()
Get the last response message. |
(package private) java.net.Socket |
getSocket()
Get the current socket. |
java.lang.String |
getStatusLabel()
Get the label describing the current state of this connection helper. |
boolean |
gotStopped()
Return true is the upload is stopped. |
private void |
initByteArrayEncoder()
creating of a new ByteArrayEncoderHTTP, and initializing of the
following header items: First line (POST currentProtocol URI), Host,
Connection, Keep-Alive, Proxy-Connection. |
void |
initRequest(java.net.URL url,
java.lang.String method,
boolean bChunkEnabled,
boolean bLastChunk)
The standard constructor for this class. |
private boolean |
isKeepAlive()
Indicates whether the current socket should be reused ... if any. |
int |
readHttpResponse()
Read the response of the server. |
void |
sendRequest()
Closes the byteArrayEncoder, create the socket (or not, depending on the current uploadPolicy, and upload history), send the request, and create the InputStream to read the server response. |
void |
stopUpload()
|
void |
write(byte[] b)
|
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final int STATUS_NOT_INITIALIZED
initRequest(URL, String, boolean, boolean).
private final int STATUS_BEFORE_SERVER_CONNECTION
private final int STATUS_WRITING_REQUEST
private final int STATUS_READING_RESPONSE
private final int STATUS_CONNECTION_CLOSED
initRequest(URL, String, boolean, boolean).
private java.lang.String boundary
private boolean bChunkEnabled
private boolean bLastChunk
private ByteArrayEncoder byteArrayEncoder
private int connectionStatus
private HTTPInputStreamReader httpInputStreamReader
private java.io.PushbackInputStream inputStream
outputStream.
private java.lang.String method
private java.io.DataOutputStream outputStream
sendRequest(). It is closed by the
readHttpResponse() method.
sendRequest(),
readHttpResponse(),
getOutputStream()private java.net.Proxy proxy
private java.net.Socket socket
private boolean stop
private UploadPolicy uploadPolicy
private java.net.URL url
private boolean useProxy
private boolean useSSL
| Constructor Detail |
|---|
public HTTPConnectionHelper(UploadPolicy uploadPolicy)
uploadPolicy - The current upload policy.
public HTTPConnectionHelper(java.net.URL url,
java.lang.String method,
boolean bChunkEnabled,
boolean bLastChunk,
UploadPolicy uploadPolicy)
throws JUploadIOException
url - The target URLmethod - The HTTP method (POST, GET, HEAD...)bChunkEnabled - Indicates if chunkUpload is enabled for this query.
Put false, if non chunked request or if it is not relevant.bLastChunk - Indicates whether this chunk is the last one. Put true,
if non chunked request or if it is not relevant.uploadPolicy - The current upload policy.
JUploadIOException| Method Detail |
|---|
public void initRequest(java.net.URL url,
java.lang.String method,
boolean bChunkEnabled,
boolean bLastChunk)
throws JUploadIOException
url - The target URLbChunkEnabled - Indicates if chunkUpload is enabled for this query.
Put false, if non chunked request or if it is not relevant.method - The HTTP method (POST, GET, HEAD...)bLastChunk - Indicates whether this chunk is the last one. Put true,
if non chunked request or if it is not relevant.
JUploadIOException
public ByteArrayEncoder getByteArrayEncoder()
throws JUploadIOException
ByteArrayEncoder. If it was not created, it
is initialized.
ByteArrayEncoder, null if called before the
first initialization.
JUploadIOExceptioninitRequest(URL, String, boolean, boolean)public java.lang.String getBoundary()
public void sendRequest()
throws JUploadIOException
JUploadIOException
public void dispose()
throws JUploadIOException
JUploadIOExceptionpublic java.io.OutputStream getOutputStream()
public java.io.PushbackInputStream getInputStream()
public java.lang.String getMethod()
public java.lang.String getResponseBody()
public java.lang.String getResponseHeaders()
public java.lang.String getResponseMsg()
public java.lang.String getStatusLabel()
java.net.Socket getSocket()
public boolean gotStopped()
public HTTPConnectionHelper append(int b)
throws JUploadIOException
b - The byte to send to the server.
JUploadIOException
public HTTPConnectionHelper append(byte[] bytes)
throws JUploadIOException
bytes - The bytes to send to the server.
JUploadIOException
public HTTPConnectionHelper append(byte[] bytes,
int off,
int len)
throws JUploadIOException
bytes - The bytes to send to the server.off - The first byte to sendlen - Number of bytes to send.
JUploadIOException
public HTTPConnectionHelper append(java.lang.String str)
throws JUploadIOException
str - The string to write
JUploadIOException - If any problem occurs during the writing
operation.append(byte[])
public HTTPConnectionHelper append(ByteArrayEncoder bae)
throws JUploadIOException
bae - The ByteArrayEncoder to write. It is expected to be correctly
encoded. That is: it is up to the caller to check that its
encoding is the same as the current HTTP request encoding.
JUploadIOException - If any problem occurs during the writing
operation.append(byte[])
public int readHttpResponse()
throws JUploadException
JUploadExceptionpublic void stopUpload()
FileUploadThread.stopUpload()
private void initByteArrayEncoder()
throws JUploadIOException
ByteArrayEncoderHTTP, and initializing of the
following header items: First line (POST currentProtocol URI), Host,
Connection, Keep-Alive, Proxy-Connection.
JUploadIOExceptionprivate boolean isKeepAlive()
private final java.lang.String calculateRandomBoundary()
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOException
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOException
public void write(byte[] b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOException
public void close()
throws java.io.IOException
OutputStream.close() one. It may
not been called. You must use the sendRequest() or
readHttpResponse() methods instead.
close in interface java.io.Closeableclose in class java.io.OutputStreamjava.io.IOExceptionOutputStream.close()
public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOExceptionOutputStream.flush()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||