Example usage for com.google.gwt.http.client RequestBuilder sendRequest

List of usage examples for com.google.gwt.http.client RequestBuilder sendRequest

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestBuilder sendRequest.

Prototype

public Request sendRequest(String requestData, RequestCallback callback) throws RequestException 

Source Link

Document

Sends an HTTP request based on the current builder configuration with the specified data and callback.

Usage

From source file:n3phele.client.model.BulkGet.java

License:Open Source License

static void get(BulkGetRequest bulk, RequestCallback callback) {
    String url = "https://n3phele.appspot.com/resources/";
    url = URL.encode(url);//  w ww  .j  ava 2  s .co m
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");

    try {
        Request request = builder.sendRequest(bulk.toString(), callback);
    } catch (RequestException e) {
        //displayError("Couldn't retrieve JSON "+e.getMessage());
    }
}

From source file:n3phele.client.presenter.AbstractActivityProgressActivity.java

License:Open Source License

public void refresh(int start) {

    String url = collectionUrl;/*  www . j  a  v a2  s .  c o  m*/
    url += "?summary=true&start=" + start + "&end=" + (start + pageSize - 1);
    this.start = start;
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    GWT.log("got progress");
                    Collection<Progress> c = Progress.asCollection(response.getText());
                    updateData(c.getUri(), c.getElements(), c.getTotal());
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }
}

From source file:n3phele.client.presenter.AbstractActivityProgressActivity.java

License:Open Source License

protected void refresh(String key) {

    String url = URL.encode(key + "?summary=true");
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {//w w  w  . java  2  s .co m
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    Progress p = Progress.asProgress(response.getText());
                    updateData(p.getUri(), p);
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }
}

From source file:n3phele.client.presenter.AbstractCloudProcessActivity.java

License:Open Source License

public void refresh(int start) {

    String url = buildUrlForProcesses(start);
    this.start = start;

    final int total = this.total;

    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {/*from  w  w  w  .ja va 2s  . c  o  m*/
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    GWT.log("got cloudProcess");
                    Collection<CloudProcessSummary> c = CloudProcessSummary.asCollection(response.getText());

                    int collectionSize = total;
                    if (collectionSize == 0) {
                        collectionSize = c.getTotal();
                    }
                    updateData(c.getUri(), c.getElements(), collectionSize);

                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }
}

From source file:n3phele.client.presenter.AbstractCloudProcessActivity.java

License:Open Source License

protected void refresh(String key) {

    String url = URL.encode(key + "?summary=true");
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {/* w  w w .j  a v  a2 s .c  om*/
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    CloudProcessSummary p = CloudProcessSummary.asCloudProcessSummary(response.getText());
                    updateData(p.getUri(), p);
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }
}

From source file:n3phele.client.presenter.AccountActivity.java

License:Open Source License

public void getAccount() {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, accountUri);
    try {//from   w  w  w. j a  va2s  .  c  om
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // displayError("Couldn't retrieve JSON "+exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    Account account = Account.asAccount(response.getText());
                    updateAccount(account);
                } else {

                }
            }

        });
    } catch (RequestException e) {
        //displayError("Couldn't retrieve JSON "+e.getMessage());
    }
}

From source file:n3phele.client.presenter.AccountActivity.java

License:Open Source License

private void updateAccountDetails(String url, String name, String description, String cloud, String cloudId,
        final String password) {

    // Send request to server and catch any errors.
    if (url == null || url.trim().length() == 0) {
        url = cacheManager.ServiceAddress + "account";
    }//from   w  w  w  .j  a v a  2s .c o  m
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("name=");
    args.append(URL.encodeQueryString(name));
    if (description != null && description.length() != 0) {
        args.append("&description=");
        args.append(URL.encodeQueryString(description));
    }
    args.append("&cloud=");
    args.append(URL.encodeQueryString(cloud));
    if (password != null && password.length() > 0) {
        args.append("&accountId=");
        args.append(URL.encodeQueryString(cloudId));
        args.append("&secret=");
        args.append(URL.encodeQueryString(password));
    }
    try {
        @SuppressWarnings("unused")
        Request request = builder.sendRequest(args.toString(), new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // displayError("Couldn't retrieve JSON "+exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    goToPrevious();
                } else if (201 == response.getStatusCode()) {
                    goToPrevious();
                } else {
                    Window.alert("Account update error " + response.getStatusText());
                }
            }

        });
    } catch (RequestException e) {
        //displayError("Couldn't retrieve JSON "+e.getMessage());
    }
}

From source file:n3phele.client.presenter.AccountListActivity.java

License:Open Source License

public void getAccountList() {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, accountCollection);
    try {/*w ww  . j ava2 s  .  c om*/
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // displayError("Couldn't retrieve JSON "+exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    Collection<Account> account = Account.asCollection(response.getText());
                    updateAccountList(account.getElements());
                } else {

                }
            }

        });
    } catch (RequestException e) {
        //displayError("Couldn't retrieve JSON "+e.getMessage());
    }
}

From source file:n3phele.client.presenter.ActivtiyActivity.java

License:Open Source License

protected void refreshActivity(String key) {

    String url = key;/*from  w  w  w . j  av  a  2 s . c  om*/
    // String url = objectUri;
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    ActivtiyActivity.this.activity = Activity.asActivity(response.getText());
                    ActivtiyActivity.this.objectUri = activity.getCommand();
                    ActivtiyActivity.super.initData();
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }
}

From source file:n3phele.client.presenter.CommandActivity.java

License:Open Source License

protected void refresh(String key) {

    String url = key;//  www.  j av a 2s.  c o m
    // String url = objectUri;
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    Command p = Command.asCommand(response.getText());
                    updateData(p.getUri(), p);
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }
}