root / src / gr / grnet / pithos / web / client / rest / DeleteRequest.java @ eb2ae14b
History | View | Annotate | Download (3.9 kB)
1 | f1aabd89 | Christos Stathis | /*
|
---|---|---|---|
2 | f1aabd89 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | f1aabd89 | Christos Stathis | *
|
4 | f1aabd89 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | f1aabd89 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | f1aabd89 | Christos Stathis | * conditions are met:
|
7 | f1aabd89 | Christos Stathis | *
|
8 | f1aabd89 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | f1aabd89 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | f1aabd89 | Christos Stathis | * disclaimer.
|
11 | f1aabd89 | Christos Stathis | *
|
12 | f1aabd89 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | f1aabd89 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | f1aabd89 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | f1aabd89 | Christos Stathis | * provided with the distribution.
|
16 | f1aabd89 | Christos Stathis | *
|
17 | f1aabd89 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | f1aabd89 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | f1aabd89 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | f1aabd89 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | f1aabd89 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | f1aabd89 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | f1aabd89 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | f1aabd89 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | f1aabd89 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | f1aabd89 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | f1aabd89 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | f1aabd89 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | f1aabd89 | Christos Stathis | *
|
30 | f1aabd89 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | f1aabd89 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | f1aabd89 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | f1aabd89 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | f1aabd89 | Christos Stathis | */
|
35 | f1aabd89 | Christos Stathis | |
36 | f1aabd89 | Christos Stathis | package gr.grnet.pithos.web.client.rest; |
37 | f1aabd89 | Christos Stathis | |
38 | f1aabd89 | Christos Stathis | import com.google.gwt.core.client.Scheduler.ScheduledCommand; |
39 | f1aabd89 | Christos Stathis | import com.google.gwt.http.client.Request; |
40 | f1aabd89 | Christos Stathis | import com.google.gwt.http.client.RequestBuilder; |
41 | f1aabd89 | Christos Stathis | import com.google.gwt.http.client.RequestException; |
42 | f1aabd89 | Christos Stathis | import com.google.gwt.http.client.Response; |
43 | f5023f13 | Christos Stathis | import com.google.gwt.http.client.URL; |
44 | f5023f13 | Christos Stathis | |
45 | f1aabd89 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
46 | f1aabd89 | Christos Stathis | import java.util.HashMap; |
47 | f1aabd89 | Christos Stathis | import java.util.Map; |
48 | f1aabd89 | Christos Stathis | |
49 | f1aabd89 | Christos Stathis | /**
|
50 | f1aabd89 | Christos Stathis | * Created by IntelliJ IDEA. User: chstath Date: 7/5/11 Time: 5:29 PM To change this template use File | Settings | File
|
51 | f1aabd89 | Christos Stathis | * Templates.
|
52 | f1aabd89 | Christos Stathis | */
|
53 | f1aabd89 | Christos Stathis | public abstract class DeleteRequest implements ScheduledCommand { |
54 | b51c628b | Christos Stathis | private String api; |
55 | b51c628b | Christos Stathis | |
56 | 7811b9d1 | Christos Stathis | protected String owner; |
57 | b51c628b | Christos Stathis | |
58 | f1aabd89 | Christos Stathis | private String path; |
59 | f1aabd89 | Christos Stathis | |
60 | f1aabd89 | Christos Stathis | private Map<String, String> headers = new HashMap<String, String>(); |
61 | f1aabd89 | Christos Stathis | |
62 | f1aabd89 | Christos Stathis | public abstract void onSuccess(Resource result); |
63 | f1aabd89 | Christos Stathis | |
64 | f1aabd89 | Christos Stathis | public abstract void onError(Throwable t); |
65 | f1aabd89 | Christos Stathis | |
66 | b51c628b | Christos Stathis | public DeleteRequest(String api, String owner, String path) { |
67 | b51c628b | Christos Stathis | this.api = api;
|
68 | b51c628b | Christos Stathis | this.owner = owner;
|
69 | f1aabd89 | Christos Stathis | this.path = path;
|
70 | f1aabd89 | Christos Stathis | } |
71 | f1aabd89 | Christos Stathis | |
72 | f1aabd89 | Christos Stathis | @Override
|
73 | f1aabd89 | Christos Stathis | public void execute() { |
74 | b51c628b | Christos Stathis | RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, api + owner + path);
|
75 | f1aabd89 | Christos Stathis | for (String header : headers.keySet()) { |
76 | f1aabd89 | Christos Stathis | builder.setHeader(header, headers.get(header)); |
77 | f1aabd89 | Christos Stathis | } |
78 | f1aabd89 | Christos Stathis | try {
|
79 | 7811b9d1 | Christos Stathis | builder.sendRequest("", new RestRequestCallback<Resource>(api + owner + path, Response.SC_NO_CONTENT) { |
80 | f1aabd89 | Christos Stathis | @Override
|
81 | f1aabd89 | Christos Stathis | public void onSuccess(Resource object) { |
82 | f1aabd89 | Christos Stathis | DeleteRequest.this.onSuccess(object); |
83 | f1aabd89 | Christos Stathis | } |
84 | f1aabd89 | Christos Stathis | |
85 | f1aabd89 | Christos Stathis | @Override
|
86 | f1aabd89 | Christos Stathis | public Resource deserialize(Response response) {
|
87 | b51c628b | Christos Stathis | return Resource.createFromResponse(Resource.class, owner, response, null); |
88 | f1aabd89 | Christos Stathis | } |
89 | f1aabd89 | Christos Stathis | |
90 | f1aabd89 | Christos Stathis | @Override
|
91 | 7811b9d1 | Christos Stathis | public void onError(@SuppressWarnings("unused") Request request, Throwable throwable) { |
92 | f1aabd89 | Christos Stathis | DeleteRequest.this.onError(throwable); |
93 | f1aabd89 | Christos Stathis | } |
94 | 9539e23d | Christos Stathis | |
95 | 9539e23d | Christos Stathis | @Override
|
96 | 9539e23d | Christos Stathis | public void onUnauthorized(Response response) { |
97 | 9539e23d | Christos Stathis | DeleteRequest.this.onUnauthorized(response); |
98 | 9539e23d | Christos Stathis | } |
99 | f1aabd89 | Christos Stathis | }); |
100 | f1aabd89 | Christos Stathis | } |
101 | f1aabd89 | Christos Stathis | catch (RequestException e) {
|
102 | f1aabd89 | Christos Stathis | } |
103 | f1aabd89 | Christos Stathis | } |
104 | f1aabd89 | Christos Stathis | |
105 | 9539e23d | Christos Stathis | protected abstract void onUnauthorized(Response response); |
106 | 9539e23d | Christos Stathis | |
107 | 9539e23d | Christos Stathis | public void setHeader(String header, String value) { |
108 | f1aabd89 | Christos Stathis | headers.put(header, value); |
109 | f1aabd89 | Christos Stathis | } |
110 | f1aabd89 | Christos Stathis | } |