Package org.lobobrowser.html.test
Class SimpleHttpRequest
java.lang.Object
org.lobobrowser.html.test.SimpleHttpRequest
- All Implemented Interfaces:
HttpRequest
The
SimpleHttpRequest
class implements
the HttpRequest
interface.
The HttpRequest
implementation provided
by this class is simple, with no caching. It creates
a new thread for each new asynchronous request.- Author:
- J. H. S.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected URLConnection
TheURLConnection
is assigned to this field while it is ongoing.protected String
protected String
protected String
protected String
Response headers are set in this string after a response is received.protected Map
Response headers are set in this map after a response is received.Fields inherited from interface org.lobobrowser.html.HttpRequest
STATE_COMPLETE, STATE_INTERACTIVE, STATE_LOADED, STATE_LOADING, STATE_UNINITIALIZED
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Aborts an ongoing request.void
Adds a listener of ReadyState changes.Gets a string with all the response headers.protected String
This is the charset used to post data provided tosend(String)
.int
Gets the state of the request, a value between 0 and 4.byte[]
Gets the request response bytes.getResponseHeader
(String headerName) Gets a response header value.Gets the request response as an AWT image.Gets the request response as text.Gets the request response as an XML DOM.int
Gets the status of the response.Gets the status text of the request, e.g.void
Starts an asynchronous request.void
Opens a request.void
Opens an asynchronous request.void
Opens an request.void
Opens a request.void
Opens the request.void
Sends POST content, if any, and causes the request to proceed.protected void
This is a synchronous implementation ofsend(String)
method functionality.
-
Field Details
-
requestMethod
-
requestUserName
-
requestPassword
-
connection
TheURLConnection
is assigned to this field while it is ongoing. -
responseHeadersMap
Response headers are set in this map after a response is received. -
responseHeaders
Response headers are set in this string after a response is received.
-
-
Constructor Details
-
SimpleHttpRequest
-
-
Method Details
-
getReadyState
public int getReadyState()Description copied from interface:HttpRequest
Gets the state of the request, a value between 0 and 4.- Specified by:
getReadyState
in interfaceHttpRequest
- Returns:
- A value corresponding to one of the STATE* constants in this class.
-
getResponseText
Description copied from interface:HttpRequest
Gets the request response as text.- Specified by:
getResponseText
in interfaceHttpRequest
-
getResponseXML
Description copied from interface:HttpRequest
Gets the request response as an XML DOM.- Specified by:
getResponseXML
in interfaceHttpRequest
-
getResponseBytes
public byte[] getResponseBytes()Description copied from interface:HttpRequest
Gets the request response bytes.- Specified by:
getResponseBytes
in interfaceHttpRequest
-
getResponseImage
Description copied from interface:HttpRequest
Gets the request response as an AWT image.- Specified by:
getResponseImage
in interfaceHttpRequest
-
getStatus
public int getStatus()Description copied from interface:HttpRequest
Gets the status of the response. Note that this can be 0 for file requests in addition to 200 for successful HTTP requests.- Specified by:
getStatus
in interfaceHttpRequest
-
getStatusText
Description copied from interface:HttpRequest
Gets the status text of the request, e.g. "OK" for 200.- Specified by:
getStatusText
in interfaceHttpRequest
-
abort
public void abort()Description copied from interface:HttpRequest
Aborts an ongoing request.- Specified by:
abort
in interfaceHttpRequest
-
getAllResponseHeaders
Description copied from interface:HttpRequest
Gets a string with all the response headers.- Specified by:
getAllResponseHeaders
in interfaceHttpRequest
-
getResponseHeader
Description copied from interface:HttpRequest
Gets a response header value.- Specified by:
getResponseHeader
in interfaceHttpRequest
- Parameters:
headerName
- The name of the header.
-
open
Description copied from interface:HttpRequest
Starts an asynchronous request.- Specified by:
open
in interfaceHttpRequest
- Parameters:
method
- The request method.url
- The destination URL.- Throws:
IOException
-
open
Description copied from interface:HttpRequest
Opens an asynchronous request.- Specified by:
open
in interfaceHttpRequest
- Parameters:
method
- The request method.url
- The destination URL.- Throws:
IOException
-
open
Description copied from interface:HttpRequest
Opens an request.- Specified by:
open
in interfaceHttpRequest
- Parameters:
method
- The request method.url
- The destination URL.asyncFlag
- Whether the request is asynchronous.- Throws:
IOException
-
open
Description copied from interface:HttpRequest
Opens a request.- Specified by:
open
in interfaceHttpRequest
- Parameters:
method
- The request method.url
- The destination URL.asyncFlag
- Whether the request should be asynchronous.- Throws:
IOException
-
open
Description copied from interface:HttpRequest
Opens a request.- Specified by:
open
in interfaceHttpRequest
- Parameters:
method
- The request method.url
- The destination URL.asyncFlag
- Whether the request should be asynchronous.userName
- The HTTP authentication user name.- Throws:
IOException
-
open
public void open(String method, URL url, boolean asyncFlag, String userName, String password) throws IOException Opens the request. Callsend(String)
to complete it.- Specified by:
open
in interfaceHttpRequest
- Parameters:
method
- The request method.url
- The request URL.asyncFlag
- Whether the request should be asynchronous.userName
- The user name of the request (not supported.)password
- The password of the request (not supported.)- Throws:
IOException
-
send
Sends POST content, if any, and causes the request to proceed.In the case of asynchronous requests, a new thread is created.
- Specified by:
send
in interfaceHttpRequest
- Parameters:
content
- POST content ornull
if there's no such content.- Throws:
IOException
-
getPostCharset
This is the charset used to post data provided tosend(String)
. It returns "UTF-8" unless overridden. -
sendSync
This is a synchronous implementation ofsend(String)
method functionality. It may be overridden to change the behavior of the class.- Parameters:
content
- POST content if any. It may benull
.- Throws:
IOException
-
addReadyStateChangeListener
Description copied from interface:HttpRequest
Adds a listener of ReadyState changes. The listener should be invoked even in the case of errors.- Specified by:
addReadyStateChangeListener
in interfaceHttpRequest
- Parameters:
listener
- An instanceof ofReadyStateChangeListener
-