com.maryanovsky.gwtutils.client.net
Class AbstractResponseHandler

java.lang.Object
  extended by com.maryanovsky.gwtutils.client.net.AbstractResponseHandler
All Implemented Interfaces:
RequestCallback
Direct Known Subclasses:
XmlResponseHandler

public abstract class AbstractResponseHandler
extends Object
implements RequestCallback

A base implementation of a RequestCallback.


Field Summary
protected  String requestUrl
          The URL of the request.
 
Constructor Summary
AbstractResponseHandler(String requestUrl)
          Creates a new AbstractResponseHandler with the specified URL of the request.
 
Method Summary
protected  void onAnyResponse()
          Invoked whenever any kind of response arrives, before any of the other methods.
 void onError(Request request, Throwable exception)
          Invokes onAnyResponse() and then onRequestError(Request, Throwable).
protected  void onRequestError(Request request, Throwable exception)
          Invoked when an error occurs during the request.
 void onResponseReceived(Request request, Response response)
          If the response code is 200, parses the response and passes the result to onSuccessfulResponse(Response).
protected abstract  void onSuccessfulResponse(Response response)
          Invoked when a successful response has arrived.
protected  void onUnexpectedStatusCode(Request request, Response response)
          Invoked when the HTTP response code is not 200.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestUrl

protected final String requestUrl
The URL of the request.

Constructor Detail

AbstractResponseHandler

public AbstractResponseHandler(String requestUrl)
Creates a new AbstractResponseHandler with the specified URL of the request.

Method Detail

onError

public final void onError(Request request,
                          Throwable exception)
Invokes onAnyResponse() and then onRequestError(Request, Throwable).

Specified by:
onError in interface RequestCallback

onResponseReceived

public void onResponseReceived(Request request,
                               Response response)
If the response code is 200, parses the response and passes the result to onSuccessfulResponse(Response). If the response code is not 200, invokes onUnexpectedStatusCode(Request, Response).

Specified by:
onResponseReceived in interface RequestCallback

onSuccessfulResponse

protected abstract void onSuccessfulResponse(Response response)
Invoked when a successful response has arrived. The default implementation does nothing.


onRequestError

protected void onRequestError(Request request,
                              Throwable exception)
Invoked when an error occurs during the request. The default implementation displays an error message in an alert window.

Parameters:
request - The request during which the error occurred.
exception - The error that occurred.

onUnexpectedStatusCode

protected void onUnexpectedStatusCode(Request request,
                                      Response response)
Invoked when the HTTP response code is not 200. The default implementation displays an error message in an alert window.

Parameters:
request - The request that was sent to the server.
response - The response received from the server.

onAnyResponse

protected void onAnyResponse()
Invoked whenever any kind of response arrives, before any of the other methods. The default implementation does nothing.