2 * Copyright 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client.rest;
21 import gr.ebs.gss.client.GSS;
23 import com.google.gwt.http.client.Request;
24 import com.google.gwt.http.client.RequestBuilder;
25 import com.google.gwt.http.client.RequestCallback;
26 import com.google.gwt.http.client.Response;
33 public abstract class PostCommand extends RestCommand{
34 boolean complete = false;
37 public PostCommand(final String path, String data, final int okStatusCode) {
38 this(path, data, okStatusCode, true);
41 public PostCommand(final String path, String data, final int okStatusCode, boolean showLoading) {
42 setShowLoadingIndicator(showLoading);
43 if(isShowLoadingIndicator())
44 GSS.get().showLoadingIndicator();
46 RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, path);
49 handleHeaders(builder, path);
50 builder.sendRequest(data, new RequestCallback() {
53 public void onError(Request arg0, Throwable arg1) {
55 PostCommand.this.onError(arg1);
59 public void onResponseReceived(Request req, Response resp) {
61 int status = resp.getStatusCode();
62 // Normalize IE status 1223 to a regular 204.
66 if (status == okStatusCode) {
67 postBody = resp.getText();
69 } else if (status == 403)
72 PostCommand.this.onError(new RestException(path, status, resp.getStatusText(), resp.getText()));
76 } catch (Exception ex) {
82 public boolean isComplete() {
87 public boolean execute() {
88 boolean com = isComplete();
90 if (isShowLoadingIndicator())
91 GSS.get().hideLoadingIndicator();
97 public String getPostBody() {