Added retry capabillity to head requests
[pithos-web-client] / src / gr / grnet / pithos / web / client / rest / PostRequest.java
index 50e2a90..fe3da92 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 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 gr.grnet.pithos.web.client.foldertree.Resource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.http.client.Request;
 import com.google.gwt.http.client.RequestBuilder;
 import com.google.gwt.http.client.RequestException;
 import com.google.gwt.http.client.Response;
-import gr.grnet.pithos.web.client.foldertree.Resource;
-import java.util.HashMap;
-import java.util.Map;
 
 public abstract class PostRequest implements ScheduledCommand {
 
@@ -51,6 +54,8 @@ public abstract class PostRequest implements ScheduledCommand {
     protected String owner;
 
     private String path;
+    
+    String data = "";
 
     private Map<String, String> headers = new HashMap<String, String>();
 
@@ -64,6 +69,13 @@ public abstract class PostRequest implements ScheduledCommand {
         this.path = path;
     }
 
+    public PostRequest(String api, String owner, String path, String data) {
+        this.api = api;
+        this.owner = owner;
+        this.path = path;
+        this.data = data;
+    }
+
     @Override
     public void execute() {
         RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, api + owner + path);
@@ -71,7 +83,7 @@ public abstract class PostRequest implements ScheduledCommand {
             builder.setHeader(header, headers.get(header));
         }
         try {
-            builder.sendRequest("", new RestRequestCallback<Resource>(api + owner + path, Response.SC_ACCEPTED) {
+            builder.sendRequest(data, new RestRequestCallback<Resource>(api + owner + path, Response.SC_ACCEPTED) {
                 @Override
                 public void onSuccess(Resource object) {
                     PostRequest.this.onSuccess(object);
@@ -83,7 +95,7 @@ public abstract class PostRequest implements ScheduledCommand {
                 }
 
                 @Override
-                public void onError(@SuppressWarnings("unused") Request request, Throwable throwable) {
+                public void onError(Request request, Throwable throwable) {
                     PostRequest.this.onError(throwable);
                 }
 
@@ -94,6 +106,7 @@ public abstract class PostRequest implements ScheduledCommand {
             });
         }
         catch (RequestException e) {
+               GWT.log("", e);
         }
     }