WOGWTRequestCallback.java :  » GWT » wogwt » WOGWT » translatable » http » Java Open Source

Java Open Source » GWT » wogwt 
wogwt » WOGWT » translatable » http » WOGWTRequestCallback.java
package wogwt.translatable.http;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;

/**
 * Adds an onSuccess method that can be used instead of onResponseReceived and treats all
 * non-2xx responses as errors and calls onError.
 */
public abstract class WOGWTRequestCallback implements RequestCallback {
  
  /**
   * Calls onSuccess for response codes of 2XX, otherwise, calls onError
   */
  public void onResponseReceived(Request request, Response response) {
    if (!Integer.toString(response.getStatusCode()).startsWith("2")) {
      onError(request, new RequestException(response.getStatusCode() + ": " + response.getStatusText()));
      return;
    }
    onSuccess(request, response);
  }
  
  public abstract void onSuccess(Request request, Response response);
  
  public abstract void onError(Request request, Throwable throwable);
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.