Groovy Documentation

org.jdesktop.http.async
[Java] Class AsyncHttpRequest

java.lang.Object
  org.jdesktop.beans.AbstractBean
      org.jdesktop.http.async.AsyncHttpRequest

public class AsyncHttpRequest
extends org.jdesktop.beans.AbstractBean

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.

Authors:
rbair


Nested Class Summary
protected class AsyncHttpRequest.AsyncWorker

enum AsyncHttpRequest.ReadyState

 
Field Summary
private boolean asyncFlag

private Exception exception

private PropertyChangeListener onReadyStateChange

private AsyncHttpRequest.ReadyState readyState

private Request req

private String responseText

If the statusText attribute is not available, it MUST raise an exception.

private Session s

private int status

Worker class used to actually perform the background tasks.

private String statusText

private AsyncHttpRequest.AsyncWorker worker

Creates a new instance of AsyncHttpRequest.

 
Constructor Summary
AsyncHttpRequest()

 
Method Summary
void abort()

void addReadyStateChangeListener(PropertyChangeListener listener)

protected AsyncHttpRequest.AsyncWorker createAsyncWorker(String content)

Method that provides a hook for subclasses to create concrete types (such as DOM, JSONObject, etc) when the response has been fully read.

String getAllResponseHeaders()

Exception getException()

Adds the given parameter to the set of parameters.

boolean getFollowRedirects()

Returns the Parameter with the given name, or null if there is no such Parameter.

PropertyChangeListener getOnReadyStateChange()

Parameter getParameter(String name)

Gets an array of all the Parameters for this Request.

Parameter[] getParameters()

AsyncHttpRequest.ReadyState getReadyState()

Initializes the AsyncHttpRequest prior to sending a request.

PropertyChangeListener[] getReadyStateChangeListeners()

String getResponseHeader(String headerLabel)

If the status property is not available it MUST raise an exception.

String getResponseText()

If the statusText property is not available, it MUST raise an exception.

Session getSession()

int getStatus()

Specifies whether the request should automatically follow redirects.

String getStatusText()

protected void handleResponse(String responseText)

This is private because statusText is a read only property.

void open(Method method, String url)

void open(Method method, String url, boolean asyncFlag)

private void open(Method method, String url, boolean asyncFlag, String username)

private void open(Method method, String url, boolean asyncFlag, String username, String password)

void removeReadyStateChangeListener(PropertyChangeListener listener)

protected void reset()

void send()

Sends the request to the server.

void send(String content)

void send(org.w3c.dom.Document dom)

void setFollowsRedirects(boolean flag)

If during the processing of this request an exception occured, then this method will return that Exception.

void setOnReadyStateChange(PropertyChangeListener listener)

Returns the ready-state change listener.

void setParameter(Parameter param)

void setParameter(String name, String value)

void setParameters(Parameter... params)

Clears any response state and resets the readyState to UNINITIALIZED.

private void setReadyState(AsyncHttpRequest.ReadyState state)

void setRequestHeader(String header, String value)

Specifies a request header for the HTTP request.

void setSession(Session s)

Returns the Session used with this Request.

private void setStatus(int status)

private void setStatusText(String text)

AsyncHttpRequest valueOf(String name)

Returns the enum constant of this type with the specified name.

AsyncHttpRequest[] values()

Returns an array containing the constants of this enum type, in the order they are declared.

 
Methods inherited from class org.jdesktop.beans.AbstractBean
org.jdesktop.beans.AbstractBean#clone(), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#addPropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getPropertyChangeListeners(), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#addVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.lang.String, java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#removeVetoableChangeListener(java.beans.VetoableChangeListener), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(java.lang.String), org.jdesktop.beans.AbstractBean#getVetoableChangeListeners(), org.jdesktop.beans.AbstractBean#wait(), org.jdesktop.beans.AbstractBean#wait(long), org.jdesktop.beans.AbstractBean#wait(long, int), org.jdesktop.beans.AbstractBean#equals(java.lang.Object), org.jdesktop.beans.AbstractBean#toString(), org.jdesktop.beans.AbstractBean#hashCode(), org.jdesktop.beans.AbstractBean#getClass(), org.jdesktop.beans.AbstractBean#notify(), org.jdesktop.beans.AbstractBean#notifyAll()
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

asyncFlag

private boolean asyncFlag


exception

private Exception exception


onReadyStateChange

private PropertyChangeListener onReadyStateChange


readyState

private AsyncHttpRequest.ReadyState readyState

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.

Authors:
rbair


req

private Request req


responseText

private String responseText
If the statusText attribute is not available, it MUST raise an exception. It MUST be available when readyState is RECEIVING or LOADED. When available, it MUST represent the HTTP status text sent by the server


s

private Session s


status

private int status
Worker class used to actually perform the background tasks.


statusText

private String statusText


worker

private AsyncHttpRequest.AsyncWorker worker
Creates a new instance of AsyncHttpRequest.


 
Constructor Detail

AsyncHttpRequest

public AsyncHttpRequest()


 
Method Detail

abort

public void abort()


addReadyStateChangeListener

public void addReadyStateChangeListener(PropertyChangeListener listener)


createAsyncWorker

protected AsyncHttpRequest.AsyncWorker createAsyncWorker(String content)
Method that provides a hook for subclasses to create concrete types (such as DOM, JSONObject, etc) when the response has been fully read. There is no need to call super.handleResponse(txt).


getAllResponseHeaders

public String getAllResponseHeaders()


getException

public Exception getException()
Adds the given parameter to the set of parameters. These are reset whenever this AsyncHttpRequest is reset.
Parameters:
param - the Parameter to add. This must not be null.


getFollowRedirects

public final boolean getFollowRedirects()
Returns the Parameter with the given name, or null if there is no such Parameter. These are reset whenever this AsyncHttpRequest is reset.
Parameters:
name - the name to look for. This must not be null.
Returns:
the Parameter with the given name.


getOnReadyStateChange

public final PropertyChangeListener getOnReadyStateChange()


getParameter

public Parameter getParameter(String name)
Gets an array of all the Parameters for this Request. This array will never be null. Ordering of items is not guaranteed. These are reset whenever this AsyncHttpRequest is reset.
Returns:
the array of Parameters for this request


getParameters

public Parameter[] getParameters()


getReadyState

public final AsyncHttpRequest.ReadyState getReadyState()
Initializes the AsyncHttpRequest prior to sending a request.


getReadyStateChangeListeners

public PropertyChangeListener[] getReadyStateChangeListeners()


getResponseHeader

public String getResponseHeader(String headerLabel)
If the status property is not available it MUST raise an exception. It MUST be available when readyState is RECEIVING or LOADED. When available, it MUST represent the HTTP status code.


getResponseText

public String getResponseText()
If the statusText property is not available, it MUST raise an exception. It MUST be available when readyState is RECEIVING or LOADED. When available, it MUST represent the HTTP status text sent by the server


getSession

public Session getSession()


getStatus

public int getStatus()
Specifies whether the request should automatically follow redirects. By default, this is set to false.
Parameters:
flag - indicates whether to follow redirects automatically


getStatusText

public String getStatusText()


handleResponse

protected void handleResponse(String responseText)
This is private because statusText is a read only property. This method ensures that the statusText property change event is fired. This MUST be called on the EDT.


open

public void open(Method method, String url)


open

public void open(Method method, String url, boolean asyncFlag)


open

private void open(Method method, String url, boolean asyncFlag, String username)


open

private void open(Method method, String url, boolean asyncFlag, String username, String password)


removeReadyStateChangeListener

public void removeReadyStateChangeListener(PropertyChangeListener listener)


reset

protected void reset()


send

public void send()
Sends the request to the server. If the readyState property has a value other than OPEN, then an IllegalStateException will be thrown. At the beginning of this method the readyState will be set to SENT. If the async flag is set to false, then the method will not return until the request has completed (ie: the method will block). Otherwise, a background task is used and this method will return immediately. Note: Authors should specify the Content-Type header via setRequestHeader before invoking send() with an argument. Redirects must be followed. Proxies should be supported Authentication should be supported. State management (cookies)? caching(?) et etc Immediately before receiving the message body (if any), the readyState attribute will be changed to RECEIVING. When the request has completed loading, the readyState attribute will be set to LOADED. In case of a HEAD request, readyState will be set to LOADED immediately after having been set to RECEIVING.


send

public void send(String content)


send

public void send(org.w3c.dom.Document dom)


setFollowsRedirects

public void setFollowsRedirects(boolean flag)
If during the processing of this request an exception occured, then this method will return that Exception. Otherwise, it returns null. It MUST return null if in any state other than LOADED


setOnReadyStateChange

public void setOnReadyStateChange(PropertyChangeListener listener)
Returns the ready-state change listener. This method returns whatever is set via the #setOnReadyStateChange method. If listeners were added via #addReadyStateChangeListener, they are not reflected in this method.
Returns:
the onReadyStateChange listener.


setParameter

public void setParameter(Parameter param)


setParameter

public void setParameter(String name, String value)


setParameters

public void setParameters(Parameter... params)
Clears any response state and resets the readyState to UNINITIALIZED. Any overriding implementations MUST call super.reset() at the end of the implementation.


setReadyState

private void setReadyState(AsyncHttpRequest.ReadyState state)


setRequestHeader

public void setRequestHeader(String header, String value)
Specifies a request header for the HTTP request.
Parameters:
header
value


setSession

public void setSession(Session s)
Returns the Session used with this Request.
Returns:
the Session. May be null.


setStatus

private void setStatus(int status)


setStatusText

private void setStatusText(String text)


valueOf

AsyncHttpRequest valueOf(String name)
Returns the enum constant of this type with the specified name.


values

AsyncHttpRequest[] values()
Returns an array containing the constants of this enum type, in the order they are declared.


 

Groovy Documentation