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.RequestCallback;
25 import com.google.gwt.http.client.Response;
32 public abstract class PostCommand extends RestCommand{
33 boolean complete = false;
36 public PostCommand(final String path, String data, final int okStatusCode){
37 this(path, data, okStatusCode, true);
39 public PostCommand(final String path, String data, final int okStatusCode, boolean showLoading){
40 setShowLoadingIndicator(showLoading);
41 if(isShowLoadingIndicator())
42 GSS.get().showLoadingIndicator();
44 RestRequestBuilder builder = new RestRequestBuilder("POST", path);
47 handleHeaders(builder, path);
48 builder.sendRequest(data, new RequestCallback() {
51 public void onError(Request arg0, Throwable arg1) {
53 PostCommand.this.onError(arg1);
57 public void onResponseReceived(Request arg0, Response arg1) {
59 if(arg1.getStatusCode() == okStatusCode){
60 postBody = arg1.getText();
63 else if(arg1.getStatusCode() == 403)
66 PostCommand.this.onError(new RestException(path, arg1.getStatusCode(), arg1.getStatusText(), arg1.getText()));
70 } catch (Exception ex) {
76 public boolean isComplete() {
80 public boolean execute() {
81 boolean com = isComplete();
83 if(isShowLoadingIndicator())
84 GSS.get().hideLoadingIndicator();
92 * Retrieve the postBody.
94 * @return the postBody
96 public String getPostBody() {