|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jdesktop.beans.AbstractBean
org.jdesktop.http.async.AsyncHttpRequest
public class AsyncHttpRequest
A simple non visual bean that uses HTTP to interact with web servers. This class conforms (except for XML specific functionality) with XMLHttpRequest as defined in the W3C Working Draft Specification http://www.w3.org/TR/XMLHttpRequest/.
Several methods, such as the abort() method, cause the AsyncHttpRequest to be "reset". This means that any state associated with the response is cleared, and the readyState reset to UNINITIALIZED.
AsyncHttpRequest relies on Session for communicating
with the server. It is possible to reuse an existing Session. However, if a
Session is not specified, a new one is constructed for the request.
| Nested Class Summary | |
|---|---|
protected class |
AsyncHttpRequest.AsyncWorker
|
static class |
AsyncHttpRequest.ReadyState
Indicates the state of this AsyncHttpRequest. |
| Constructor Summary | |
|---|---|
AsyncHttpRequest()
Creates a new instance of AsyncHttpRequest. |
|
| Method Summary | |
|---|---|
void |
abort()
Cancels any network activity and resets the object. |
void |
addReadyStateChangeListener(PropertyChangeListener listener)
|
protected AsyncHttpRequest.AsyncWorker |
createAsyncWorker(String content)
|
String |
getAllResponseHeaders()
Gets all of the response headers as one long string. |
Exception |
getException()
If during the processing of this request an exception occured, then this method will return that Exception. |
boolean |
getFollowRedirects()
Returns true if this request should automatically follow redirects, false otherwise. |
PropertyChangeListener |
getOnReadyStateChange()
Returns the ready-state change listener. |
Parameter |
getParameter(String name)
Returns the Parameter with the given name, or null if there is no such Parameter. |
Parameter[] |
getParameters()
Gets an array of all the Parameters for this Request. |
AsyncHttpRequest.ReadyState |
getReadyState()
Gets the ready state of this AsyncHttpRequest. |
PropertyChangeListener[] |
getReadyStateChangeListeners()
|
String |
getResponseHeader(String headerLabel)
Gets a single response header as a string. |
String |
getResponseText()
If the readyState property has a value other than RECEIVING or LOADED, reponseText MUST be the empty string. |
Session |
getSession()
Returns the Session used with this Request. |
int |
getStatus()
If the status property is not available it MUST raise an exception. |
String |
getStatusText()
If the statusText property is not available, it MUST raise an exception. |
protected void |
handleResponse(String responseText)
Method that provides a hook for subclasses to create concrete types (such as DOM, JSONObject, etc) when the response has been fully read. |
void |
open(Method method,
String url)
Initializes the AsyncHttpRequest prior to sending a request. |
void |
open(Method method,
String url,
boolean asyncFlag)
Initializes the AsyncHttpRequest prior to sending a request. |
void |
removeReadyStateChangeListener(PropertyChangeListener listener)
|
protected void |
reset()
Clears any response state and resets the readyState to UNINITIALIZED. |
void |
send()
Sends the request to the server. |
void |
send(Document dom)
|
void |
send(String content)
|
void |
setFollowsRedirects(boolean flag)
Specifies whether the request should automatically follow redirects. |
void |
setOnReadyStateChange(PropertyChangeListener listener)
Sets the listener to use for ready-state change event notification. |
void |
setParameter(Parameter param)
Adds the given parameter to the set of parameters. |
void |
setParameter(String name,
String value)
Adds the given parameter to the set of parameters. |
void |
setParameters(Parameter... params)
Sets the parameters to use with this Request. |
void |
setRequestHeader(String header,
String value)
Specifies a request header for the HTTP request. |
void |
setSession(Session s)
Sets the Session to use with this request. |
| Methods inherited from class org.jdesktop.beans.AbstractBean |
|---|
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clone, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public AsyncHttpRequest()
| Method Detail |
|---|
public void setSession(Session s)
Session to use with this request.
s - the Session to use. This may be null. If null, then a default
Session will be created as necessary. This default Session will
NOT be available via the getSession() method, but will be internal
to this implementation.public Session getSession()
Session used with this Request.
public void setOnReadyStateChange(PropertyChangeListener listener)
listener - the listenerpublic final PropertyChangeListener getOnReadyStateChange()
public final AsyncHttpRequest.ReadyState getReadyState()
Gets the ready state of this AsyncHttpRequest.
Ready state will be one of the following values:
public void open(Method method,
String url)
public void open(Method method,
String url,
boolean asyncFlag)
public void setRequestHeader(String header,
String value)
header - value - public void send()
public void send(String content)
content - public void send(Document dom)
dom - public void abort()
public String getAllResponseHeaders()
Gets all of the response headers as one long string.
If the readyState property has a value other than RECEIVING or LOADED, this method will return null. Otherwise, it will return all the HTTP headers as a single string, with each header line separated by a CR/LF pair. The status line will not be included.
public String getResponseHeader(String headerLabel)
Gets a single response header as a string.
If the readyState property has a value other than RECEIVING or LOADED, this method will return null. Otherwise, it will represent the value of the given HTTP header in the data received so far from the last request sent, as a single string. If more than one header of the given name was received, then the values will be concatenated, separated from each other by a comma followed by a single space. If no headers of that name were received, then it will return the empty String.
headerLabel - the label of the response header to retreive.
public String getResponseText()
public int getStatus()
public String getStatusText()
public void setFollowsRedirects(boolean flag)
flag - indicates whether to follow redirects automaticallypublic final boolean getFollowRedirects()
public Exception getException()
public Parameter getParameter(String name)
name - the name to look for. This must not be null.
public void setParameter(Parameter param)
param - the Parameter to add. This must not be null.
public void setParameter(String name,
String value)
name - the name of the parametervalue - the value of the parameterpublic Parameter[] getParameters()
public void setParameters(Parameter... params)
params - the Parameters to set for this Request. May be null.public void addReadyStateChangeListener(PropertyChangeListener listener)
public void removeReadyStateChangeListener(PropertyChangeListener listener)
public PropertyChangeListener[] getReadyStateChangeListeners()
protected AsyncHttpRequest.AsyncWorker createAsyncWorker(String content)
protected void reset()
protected void handleResponse(String responseText)
throws Exception
Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||