|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.net.URLConnection | +--java.net.HttpURLConnection | +--JavaCGIBridge
The JavaCGIBridge class POSTS and GETS data from URLs using various helper methods. It also provides the capability of timing out if the connection takes too long to transfer data by using threads to monitor whether the data is taking too long to transfer (implements Runnable).
Modifications including adding 401 HTTP security , P. Lemkin (NCI), J. Evans(CIT), C. Santos(CIT), G. Thornwall (SAIC), NCI-Frederick, Frederick, MD
JavaCGIBridgeTimeOutException
Field Summary | |
private java.lang.String |
bottomSeparator
The bottom of data separator. |
private static int |
defaultThreadJavaCGIBridgeTimeOut
This is the default CGI Timeout in milliseconds. |
private java.lang.String |
fieldSeparator
The field separator. |
private boolean |
gotHdrFlag
|
private java.util.Vector |
headers
|
private java.util.Hashtable |
keys
|
private static char |
keySeparator
|
private java.lang.String |
passwd
possibly used for Authentication |
private static boolean |
PFL_NEW_READ_BUF_CODE
|
private int |
responseCode
set when return from server |
private java.lang.String |
responseMsg
|
private java.lang.String |
rowSeparator
The row separator. |
private java.net.Socket |
sock
socket for fine-grain control |
private boolean |
threadCanRunMethodExecute
This is a flag that makes it so that the run() method is at least semi-private for Threading. |
private java.lang.String |
threadCGIData
This is the returned URL data. |
private boolean |
threadCompleted
This is a flag indicating whether the URL data was retrieved inside the thread or not. |
private java.util.Hashtable |
threadFormVar
The HTML form data for the URL that data is retrieved from. |
private int |
threadJavaCGIBridgeTimeOut
This is the actual CGI Timeout value in milliseconds for the instantiated object. |
private java.net.URL |
threadURL
The URL That data is retrieved from. |
private java.lang.String |
topSeparator
The top of data separator. |
private java.net.URL |
urlArg
may need because of HttpURLConnection |
private java.lang.String |
userName
possibly used for Authentication |
Fields inherited from class java.net.HttpURLConnection |
followRedirects, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, methods, responseMessage |
Fields inherited from class java.net.URLConnection |
allowUserInteraction, connected, contentClassPrefix, contentPathProp, defaultAllowUserInteraction, defaultUseCaches, doInput, doOutput, factory, fileNameMap, fileNameMapLoaded, handlers, ifModifiedSince, UnknownContentHandlerP, url, useCaches |
Constructor Summary | |
JavaCGIBridge()
JavaCGIBridge() - Constructs the object with no initialization. |
|
JavaCGIBridge(java.net.URL url)
JavaCGIBridge() - Constructs the object with no initialization. |
|
JavaCGIBridge(java.net.URL url,
java.lang.String userName,
java.lang.String passwd)
JavaCGIBridge() - Constructs the object with userName, password. |
Method Summary | |
void |
addFormValue(java.util.Hashtable ht,
java.lang.String formKey,
java.lang.String formValue)
addFormValue() - adds a form variable, value pair to the passed Hashtable. |
private java.lang.String |
base64encode(java.lang.String str)
base64encode() - return str encoded to base64 format. |
private int |
base64Length(int strLength)
base64Length() - compute# bytes it takes to store LEN bytes in base64. |
java.lang.String |
basicAuthenticationEncode(java.lang.String user,
java.lang.String passwd)
basicAuthenticationEncode() - create authentication header contents for the `Basic' scheme. |
void |
connect()
connect() - implements abstract method for HttpURLconnection. |
void |
disconnect()
disconnect() - implements abstract method for HttpURLconnection. |
java.lang.String |
getBottomSeparator()
getBottomSeparator() - Returns the bottom separator for the object When getParsedData method is called, the object uses the bottom separator to determine where the rows of data inside the raw HTML output actually end. |
static int |
getDefaultThreadJavaCGIBridgeTimeOut()
getDefaultThreadJavaCGIBridgeTimeOut() - default communication time out Return default static value in milliseconds for the class. |
java.lang.String |
getField(java.lang.String str)
getField() - helper routine for parsing header key PFL - 8-7-00 See pg931, Patrick Chan etal, Java Class Libraries 2nd Ed, Vol 1. |
java.lang.String |
getFieldSeparator()
getFieldSeparator() - Returns the field separator for the object. |
java.lang.String |
getHeaderField(int n)
getHeaderField() - implements getHeaderField for HttpURLconnection. |
java.lang.String |
getHeaderField(java.lang.String key)
getHeaderField() - implements HeaderField for HttpURLconnection. |
(package private) void |
getHeaders()
getHeaders() - help routine read header from HTTP connection. |
private java.lang.String |
getHttpRequestInThread(java.net.URL u,
java.util.Hashtable ht)
getHttpRequestInThread() - Returns HTTP Request data to the thread that was launched to GET/POST data for a URL. |
java.io.InputStream |
getInputStream()
getInputStream() - implements getInputStream for HttpURLconnection. |
(package private) static java.lang.String |
getKey(java.lang.String str)
getKey() - helper routine for parsing header field PFL - 8-7-00 See pg931, Patrick Chan etal, Java Class Libraries 2nd Ed, Vol 1. |
java.util.Hashtable |
getKeyValuePairs(java.util.Vector vectorOfVectors)
getKeyValuePairs() - cvt getParsedData to hashtable. |
java.io.OutputStream |
getOutputStream()
getOutputStream() - implements getOutputStream for HttpURLconnection. |
java.util.Vector |
getParsedData(java.net.URL u)
getParsedData() - returns parsed data in form of Vector of Vectors containing the returned fields inside of a Vector of returned rows. |
java.util.Vector |
getParsedData(java.net.URL u,
java.util.Hashtable ht)
getParsedData() - returns parsed data in form of Vector of Vectors Returns parsed data in the form of a Vector of Vectors containing the returned fields inside of a Vector of returned rows. |
java.lang.String |
getRawCGIData(java.net.URL u)
getRawCGIData() - returns raw HTML data as a String from the passed URL. |
java.lang.String |
getRawCGIData(java.net.URL u,
java.util.Hashtable ht)
getRawCGIData() - returns raw HTML data as a String from URL & hashtable. |
byte[] |
getRawCGIDataByte(java.net.URL u,
java.util.Hashtable ht)
getRawCGIDataByte() - returns raw HTML data as byte[] from URL&hashtable. |
java.lang.String |
getRowSeparator()
getRowSeparator() - Returns the row separator for the object. |
int |
getThreadJavaCGIBridgeTimeOut()
getThreadJavaCGIBridgeTimeOut() - actual communication time out in msec. |
java.lang.String |
getTopSeparator()
getTopSeparator() - Returns the top separator for the object. |
private java.lang.String |
getURLEncodedHashTable(java.util.Hashtable ht)
getURLEncodedHashTable() - form variables inside hashtable as URLencoded string of parameters for a CGI based program to process. |
java.lang.String |
HeaderFieldKey(int n)
HeaderFieldKey() - implements HeaderFieldKey for HttpURLconnection. |
void |
JavaCGIBridgeSep(java.lang.String field,
java.lang.String row,
java.lang.String top,
java.lang.String bottom)
JavaCGIBridgeSep() - constructs the object with new separator values |
(package private) static java.lang.String |
recv(java.io.InputStream in)
recv() - helper routine to read a \n-terminated string from input stream. |
void |
run()
run() - This run thread asynchronously POSTs and GETs data from URL and places the contents into the threadCGIData variable. |
(package private) static void |
send(java.io.OutputStream out,
java.lang.String s)
send() - helper routine to send a string to output stream. |
void |
setBottomSeparator(java.lang.String s)
setBottomSeparator() - Sets the bottom separator for the object. |
static void |
setDefaultThreadJavaCGIBridgeTimeOut(int t)
setDefaultThreadJavaCGIBridgeTimeOut() - set communication time out Static method sets the default communication time out in milliseconds for the class. |
void |
setFieldSeparator(java.lang.String s)
setFieldSeparator() - Sets the field separator for the object. |
void |
setRowSeparator(java.lang.String s)
setRowSeparator() - Sets the row separator for the object. |
void |
setThreadJavaCGIBridgeTimeOut(int t)
setThreadJavaCGIBridgeTimeOut() - actual communication time out in msec. |
void |
setTopSeparator(java.lang.String s)
setTopSeparator() - Sets the top separator for the object. |
boolean |
usingProxy()
usingProxy() - impimplements abstract method for HttpURLconnection. |
Methods inherited from class java.net.HttpURLConnection |
|
Methods inherited from class java.net.URLConnection |
checkfpx, getAllowUserInteraction, getContent, getContent, getContentEncoding, getContentHandler, getContentHandlerPkgPrefixes, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderFieldInt, getHeaderFieldKey, getIfModifiedSince, getLastModified, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, lookupContentHandlerClassFor, setAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setRequestProperty, setUseCaches, stripOffParameters, toString, typeToPackageName |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait |
Field Detail |
private static final boolean PFL_NEW_READ_BUF_CODE
private java.lang.String fieldSeparator
private java.lang.String rowSeparator
private java.lang.String topSeparator
private java.lang.String bottomSeparator
private java.net.URL threadURL
private java.util.Hashtable threadFormVar
private boolean threadCompleted
private java.lang.String threadCGIData
private static int defaultThreadJavaCGIBridgeTimeOut
private int threadJavaCGIBridgeTimeOut
private boolean threadCanRunMethodExecute
private java.net.URL urlArg
private java.lang.String userName
private java.lang.String passwd
private java.net.Socket sock
private java.util.Hashtable keys
private java.util.Vector headers
private boolean gotHdrFlag
private static final char keySeparator
private int responseCode
private java.lang.String responseMsg
Constructor Detail |
public JavaCGIBridge(java.net.URL url)
public JavaCGIBridge()
public JavaCGIBridge(java.net.URL url, java.lang.String userName, java.lang.String passwd)
url
- userName
- passwd
- Method Detail |
public void JavaCGIBridgeSep(java.lang.String field, java.lang.String row, java.lang.String top, java.lang.String bottom)
field
- row,
- top
- bottom
- public void connect() throws java.io.IOException
connect
in class java.net.URLConnection
public void disconnect()
disconnect
in class java.net.HttpURLConnection
public boolean usingProxy()
usingProxy
in class java.net.HttpURLConnection
public java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
in class java.net.URLConnection
connect()
public java.io.OutputStream getOutputStream() throws java.io.IOException
getOutputStream
in class java.net.URLConnection
connect()
public java.lang.String getHeaderField(int n)
getHeaderField
in class java.net.URLConnection
n
- is the field to getgetField(java.lang.String)
,
getHeaders()
public java.lang.String getHeaderField(java.lang.String key)
getHeaderField
in class java.net.URLConnection
key
- specified the header field to getgetHeaders()
public java.lang.String HeaderFieldKey(int n)
n
- is the header fieldgetHeaders()
,
getKey(java.lang.String)
static void send(java.io.OutputStream out, java.lang.String s) throws java.io.IOException
out
- output stream to write tos
- is string to writestatic java.lang.String recv(java.io.InputStream in) throws java.io.IOException
in
- input stream to read fromstatic java.lang.String getKey(java.lang.String str)
str
- public java.lang.String getField(java.lang.String str)
str
- void getHeaders()
basicAuthenticationEncode(java.lang.String, java.lang.String)
,
connect()
,
getField(java.lang.String)
public void addFormValue(java.util.Hashtable ht, java.lang.String formKey, java.lang.String formValue)
ht
- the Hashtable that contains the form variable/value pairsformKey
- the String that contains the form variable to addformValue
- the String that contains the form value to addpublic java.util.Hashtable getKeyValuePairs(java.util.Vector vectorOfVectors)
vectorOfVectors
- the Vector of Vectors for the parsed datagetParsedData(java.net.URL)
public java.util.Vector getParsedData(java.net.URL u) throws JavaCGIBridgeTimeOutException
u
- URL to get parsed data from.JavaCGIBridgeTimeOutException
- getParsedData(java.net.URL)
public java.util.Vector getParsedData(java.net.URL u, java.util.Hashtable ht) throws JavaCGIBridgeTimeOutException
u
- URL to get parsed data from.ht
- Hashtable contains form variables to POSTJavaCGIBridgeTimeOutException
- getRawCGIData(java.net.URL)
public java.lang.String getRawCGIData(java.net.URL u) throws JavaCGIBridgeTimeOutException
u
- URL to get raw HTML from.JavaCGIBridgeTimeOutException
- getRawCGIData(java.net.URL)
public byte[] getRawCGIDataByte(java.net.URL u, java.util.Hashtable ht) throws JavaCGIBridgeTimeOutException
u
- URL to get raw HTML from.JavaCGIBridgeTimeOutException
- public java.lang.String getRawCGIData(java.net.URL u, java.util.Hashtable ht) throws JavaCGIBridgeTimeOutException
u
- URL to get raw HTML from.ht
- Hashtable contains form variables to POSTJavaCGIBridgeTimeOutException
- getParsedData(java.net.URL)
public static int getDefaultThreadJavaCGIBridgeTimeOut()
setDefaultThreadJavaCGIBridgeTimeOut(int)
public static void setDefaultThreadJavaCGIBridgeTimeOut(int t)
t
- default communication time out in millisecondsgetDefaultThreadJavaCGIBridgeTimeOut()
public int getThreadJavaCGIBridgeTimeOut()
setThreadJavaCGIBridgeTimeOut(int)
,
getDefaultThreadJavaCGIBridgeTimeOut()
,
setDefaultThreadJavaCGIBridgeTimeOut(int)
public void setThreadJavaCGIBridgeTimeOut(int t)
t
- communication time out in millisecondsgetThreadJavaCGIBridgeTimeOut()
,
getDefaultThreadJavaCGIBridgeTimeOut()
,
setDefaultThreadJavaCGIBridgeTimeOut(int)
public void setFieldSeparator(java.lang.String s)
s
- String containing new delimiting separatorgetParsedData(java.net.URL)
,
getFieldSeparator()
public java.lang.String getFieldSeparator()
getParsedData(java.net.URL)
,
setFieldSeparator(java.lang.String)
public void setRowSeparator(java.lang.String s)
s
- String containing new delimiting separatorgetParsedData(java.net.URL)
,
getRowSeparator()
public java.lang.String getRowSeparator()
getParsedData(java.net.URL)
,
setRowSeparator(java.lang.String)
public void setTopSeparator(java.lang.String s)
s
- String containing new delimiting separatorgetParsedData(java.net.URL)
,
getTopSeparator()
public java.lang.String getTopSeparator()
getParsedData(java.net.URL)
,
setTopSeparator(java.lang.String)
public void setBottomSeparator(java.lang.String s)
s
- String containing new delimiting separatorgetParsedData(java.net.URL)
,
getBottomSeparator()
public java.lang.String getBottomSeparator()
getParsedData(java.net.URL)
,
setBottomSeparator(java.lang.String)
public void run()
run
in interface java.lang.Runnable
getRawCGIData(java.net.URL)
private java.lang.String getURLEncodedHashTable(java.util.Hashtable ht)
ht
- Hashtable containing form variablesaddFormValue(java.util.Hashtable, java.lang.String, java.lang.String)
private java.lang.String getHttpRequestInThread(java.net.URL u, java.util.Hashtable ht)
u
- URL to retrieve and post data forht
- Form variables to send to URLgetURLEncodedHashTable(java.util.Hashtable)
,
run()
private int base64Length(int strLength)
private java.lang.String base64encode(java.lang.String str)
public java.lang.String basicAuthenticationEncode(java.lang.String user, java.lang.String passwd)
"Authorization: Basic " + base64encode(user+":"+passwd)
base64encode(java.lang.String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |