wt.clients.util.http
Class MultiPartPost

java.lang.Object
  extended bywt.clients.util.http.MultiPartPost
All Implemented Interfaces:
MultiPartPostIfc

public final class MultiPartPost
extends Object
implements MultiPartPostIfc

Class MultiPartPost provides the capability to specify a set of files to be uploaded to a url.

Supported API:false

Extendable:false


Nested Class Summary
(package private)  class MultiPartPost.PostThread
           
 
Field Summary
(package private) static String BOUNDARY
           
private static int BUF_SIZ
           
private  BufferedOutputStream bufferedOutput
           
private  URLConnection connection
           
static int FAILURE_FILE_NOT_FOUND
          Returned by getOperationFailureCode().
static int FAILURE_HTTP_ERROR
          Returned by getOperationFailureCode().
static int FAILURE_IO_ERROR
          Returned by getOperationFailureCode().
static int FAILURE_NONE
          Returned by getOperationFailureCode().
private  int fileNum
           
private  int httpResponseCode
           
private  String httpResponseMessage
           
private  Hashtable listeners
           
private  int operationStatus
           
private  boolean postCancelled
           
private  Vector postData
           
private  URL url
           
 
Fields inherited from interface wt.clients.util.MultiPartPostIfc
OPERATION_CANCEL, OPERATION_CANCEL_REQUEST, OPERATION_COMPLETE, OPERATION_FAILURE, OPERATION_INACTIVE, OPERATION_START
 
Constructor Summary
MultiPartPost(URL url)
          Create a MultiPartPost object.
 
Method Summary
 void addUploadListener(MultiPartPostListener l)
           
 void cancelOperation()
           
 void clear()
          If connection is open close it.
private  void closeConnection()
           
private  void closeOutputStream()
           
private  void connect()
           
private  String getContentType(String filename)
           
 int getHTTPResponseCode()
          Return the HTTP response code for the upload operation.
 String getHTTPResponseMessage()
           
 int getOperationStatus()
           
 int getResponseCode()
           
 String getResponseString()
           
 String getURL()
           
static void main(String[] args)
           
private  PostEntry newPostEntry(int type, String name, String value)
           
private  void openConnection()
          Open the connection and set headers.
private  void operationProgress(String contentName, String path, int byteCount)
           
private  void operationStatusChange(int newStatus)
           
private  String parseExtension(String path)
           
private  int parseHTTPResponse()
          Return HTTP reponse code.
 Thread performOperation(boolean separateThread)
          Perform the multi part post operation.
private  void printData(PostEntry postEntry)
           
private  void printFileHeader(PostEntry postEntry)
           
private  void println(String s)
           
 void removeUploadListener(MultiPartPostListener l)
           
 void setData(String contentName, String value)
          Record data to be posted.
private  void setHTTPResponseCode(int code)
           
(package private)  void setHTTPResponseMessage(String message)
           
private  void setOperationStatus(int newValue)
           
 void setPath(String contentName, String path)
          Record file to be posted.
private  void showResponse(InputStream input)
           
private  void streamData()
           
private  void streamFile(PostEntry postEntry)
          Stream the individual file.
(package private)  void validateFiles()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FAILURE_NONE

public static final int FAILURE_NONE
Returned by getOperationFailureCode(). Indicates that no failure has occurred.

See Also:
Constant Field Values

FAILURE_IO_ERROR

public static final int FAILURE_IO_ERROR
Returned by getOperationFailureCode(). Indicates that some IOException was thrown during the operation.

See Also:
Constant Field Values

FAILURE_HTTP_ERROR

public static final int FAILURE_HTTP_ERROR
Returned by getOperationFailureCode(). Indicates that an HTTP error was returned.

See Also:
Constant Field Values

FAILURE_FILE_NOT_FOUND

public static final int FAILURE_FILE_NOT_FOUND
Returned by getOperationFailureCode(). Indicates that the file does not exist.

See Also:
Constant Field Values

url

private URL url

operationStatus

private int operationStatus

httpResponseCode

private int httpResponseCode

httpResponseMessage

private String httpResponseMessage

postCancelled

private boolean postCancelled

listeners

private Hashtable listeners

connection

private URLConnection connection

bufferedOutput

private BufferedOutputStream bufferedOutput

fileNum

private int fileNum

postData

private Vector postData

BOUNDARY

static final String BOUNDARY
See Also:
Constant Field Values

BUF_SIZ

private static int BUF_SIZ
Constructor Detail

MultiPartPost

public MultiPartPost(URL url)
Create a MultiPartPost object.

Throws:
MalformedULRException - indicates that the url is not correctly formatted.
Method Detail

main

public static void main(String[] args)

getURL

public String getURL()

setData

public void setData(String contentName,
                    String value)
Record data to be posted.

Specified by:
setData in interface MultiPartPostIfc
Parameters:
contentName - the content name to be supplied in the post.

setPath

public void setPath(String contentName,
                    String path)
Record file to be posted.

Specified by:
setPath in interface MultiPartPostIfc
Parameters:
contentName - the content name to be supplied in the post.
path - the path to the file.

getHTTPResponseCode

public int getHTTPResponseCode()
Return the HTTP response code for the upload operation. Before the upload is complete the responseCode will be -1. See documentation for class java.net.HttpURLConnection for response code values.


getResponseCode

public int getResponseCode()
Specified by:
getResponseCode in interface MultiPartPostIfc

setHTTPResponseCode

private void setHTTPResponseCode(int code)

getHTTPResponseMessage

public String getHTTPResponseMessage()

getResponseString

public String getResponseString()
Specified by:
getResponseString in interface MultiPartPostIfc

setHTTPResponseMessage

void setHTTPResponseMessage(String message)

getOperationStatus

public int getOperationStatus()
Specified by:
getOperationStatus in interface MultiPartPostIfc

setOperationStatus

private void setOperationStatus(int newValue)

performOperation

public Thread performOperation(boolean separateThread)
Perform the multi part post operation. The url connection is opened the files are streamed up.

Specified by:
performOperation in interface MultiPartPostIfc
Returns:
the status of the operation, see java.net.HttpURLConnection for a list of response values.
Throws:
FileNotFoundException - thrown when file can't be found.
IOException - This is not an expected exception, indicates a critical error.

cancelOperation

public void cancelOperation()
Specified by:
cancelOperation in interface MultiPartPostIfc

clear

public void clear()
           throws IOException
If connection is open close it. Clear the list of files. The url is unchanged.

Throws:
IOException

openConnection

private void openConnection()
                     throws ProtocolException,
                            IOException
Open the connection and set headers.

Throws:
ProtocolException - This is not a normal exception, indicates a critical problem.
IOException

connect

private void connect()

closeOutputStream

private void closeOutputStream()

closeConnection

private void closeConnection()
                      throws IOException
Throws:
IOException

parseHTTPResponse

private int parseHTTPResponse()
                       throws IOException
Return HTTP reponse code. See HttpURLConnection for reponse values.

Throws:
IOException

showResponse

private void showResponse(InputStream input)
                   throws IOException
Throws:
IOException

validateFiles

void validateFiles()
             throws FileNotFoundException
Throws:
FileNotFoundException

streamData

private void streamData()
                 throws IOException
Throws:
IOException

newPostEntry

private PostEntry newPostEntry(int type,
                               String name,
                               String value)

printData

private void printData(PostEntry postEntry)
                throws IOException
Throws:
IOException

printFileHeader

private void printFileHeader(PostEntry postEntry)
                      throws IOException
Throws:
IOException

streamFile

private void streamFile(PostEntry postEntry)
                 throws FileNotFoundException,
                        IOException
Stream the individual file.

Throws:
FileNotFoundException
IOException

getContentType

private String getContentType(String filename)

parseExtension

private String parseExtension(String path)

println

private void println(String s)
              throws IOException
Throws:
IOException

addUploadListener

public void addUploadListener(MultiPartPostListener l)

removeUploadListener

public void removeUploadListener(MultiPartPostListener l)

operationStatusChange

private void operationStatusChange(int newStatus)

operationProgress

private void operationProgress(String contentName,
                               String path,
                               int byteCount)