2 * Copyright (c) 2011 Greek Research and Technology Network
4 package gr.grnet.pithos.web.client.rest;
6 import com.google.gwt.http.client.Request;
7 import com.google.gwt.http.client.RequestCallback;
8 import com.google.gwt.http.client.Response;
9 import com.google.gwt.user.client.rpc.AsyncCallback;
11 public abstract class RestGetCallback implements RequestCallback {
13 private static final int HTTP_OK = 200;
15 private AsyncCallback callback;
17 private int okcode = -1;
19 public RestGetCallback(String aPath, AsyncCallback aCallback) {
24 public RestGetCallback(String aPath, AsyncCallback aCallback, int okCode) {
31 public void onError(Request request, Throwable exception) {
32 callback.onFailure(exception);
36 public void onResponseReceived(Request request, Response response) {
38 if (okcode == -1 && response.getStatusCode() == HTTP_OK)
39 callback.onSuccess(deserialize(response));
40 //this one is only used for trash handling where empty trash has 201 status code
41 else if(okcode !=-1 && (response.getStatusCode() == okcode || response.getStatusCode() == HTTP_OK))
42 callback.onSuccess(deserialize(response));
44 callback.onFailure(new RestException(path, response.getStatusCode(), response.getStatusText(), response.getText()));
45 } catch (Exception e) {
46 callback.onFailure(e);
50 public abstract Object deserialize(Response response);