/*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2013 GRNET S.A. All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
package gr.grnet.pithos.web.client.rest;
+import com.google.gwt.http.client.Header;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
-import gr.grnet.pithos.web.client.foldertree.Resource;
+import gr.grnet.pithos.web.client.Helpers;
+import gr.grnet.pithos.web.client.Pithos;
+import gr.grnet.pithos.web.client.Resource;
public abstract class RestRequestCallback<T extends Resource> implements RequestCallback {
@Override
public void onResponseReceived(Request request, Response response) {
+ Helpers.LOGResponse(response);
+
try {
if (response.getStatusCode() == HTTP_OK || (okcode !=-1 && response.getStatusCode() == okcode))
onSuccess(deserialize(response));
+ else if (response.getStatusCode() == Response.SC_UNAUTHORIZED) {
+ log(request, response);
+ onUnauthorized(response);
+ }
else {
String statusText = "";
String text = "";
onError(request, new RestException(path, response.getStatusCode(), statusText, text));
}
} catch (Exception e) {
+ Pithos.LOG(e);
onError(request, e);
}
}
+ private native void log(Request req, Response resp)/*-{
+ if ($wnd.console && $wnd.console.log) {
+ $wnd.console.log(req.@com.google.gwt.http.client.Request::toString()());
+ $wnd.console.log(resp.@com.google.gwt.http.client.Response::toString()());
+ $wnd.console.log(resp.@com.google.gwt.http.client.Response::getStatusCode()());
+ $wnd.console.log(resp.@com.google.gwt.http.client.Response::getStatusText()());
+ $wnd.console.log(resp.@com.google.gwt.http.client.Response::getStatusCode()());
+ $wnd.console.log(resp.@com.google.gwt.http.client.Response::getText()());
+ $wnd.console.log(resp.@com.google.gwt.http.client.Response::getHeadersAsString()());
+ }
+ }-*/;
+
public abstract void onSuccess(T result);
public abstract T deserialize(Response response);
+
+ public abstract void onUnauthorized(Response response);
}