Example usage for com.google.gwt.http.client RequestCallback RequestCallback

List of usage examples for com.google.gwt.http.client RequestCallback RequestCallback

Introduction

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

Prototype

RequestCallback

Source Link

Usage

From source file:n3phele.client.CacheManager.java

License:Open Source License

public void refresh() {
    RequestBuilder builder = AuthenticatedRequestFactory.newCacheManagerRequest(RequestBuilder.GET,
            ServiceAddress + "?summary=false&changeOnly=true&since=" + stamp);
    if (builder == null)
        return;/*from w w  w.  ja va2 s  .co m*/
    try {
        GWT.log("Sending request");
        @SuppressWarnings("unused")
        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) {
                if (200 == response.getStatusCode()) {
                    Root root = Root.parse(response.getText());
                    GWT.log(response.getText());
                    GWT.log(root.toString());
                    stamp = root.getStamp();
                    ChangeGroup changes = root.getChangeGroup();
                    if (changes != null) {
                        if (changes.getChange() != null) {
                            for (Change x : changes.getChange()) {
                                List<Registration> item;
                                item = cache.get(x.getUri());
                                GWT.log("Got change URI " + x.getUri() + " item " + item);
                                if (x.getUri().equals(cloudUrl)) {
                                    refreshClouds();
                                }
                                if (item != null) {
                                    fireAll(x.getUri(), item);
                                }
                            }
                            if (changes.getChange().size() != 0) {
                                backoff = 0;
                            }
                        }
                    } else {
                        for (Entry<String, List<Registration>> entry : cache.entrySet()) {
                            fireAll(entry.getKey(), entry.getValue());
                        }
                    }

                } else {
                    // displayError("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }

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

From source file:n3phele.client.CacheManager.java

License:Open Source License

protected void refreshClouds() {

    RequestBuilder builder = AuthenticatedRequestFactory.newCacheManagerRequest(RequestBuilder.GET, cloudUrl);
    try {/*from   ww  w . ja va2 s .  com*/
        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()) {
                    Collection<Cloud> p = Cloud.asCollection(response.getText());
                    clouds.clear();
                    clouds.addAll(p.getElements());
                    GWT.log("Got " + clouds.size() + " clouds.");
                    gotClouds = true;
                    eventBus.fireEvent(new CloudListUpdate(cloudUrl));
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
        gotClouds = false;
    } catch (RequestException e) {
        GWT.log("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;//from   w ww .j av a  2 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 .  j  a  va 2s  . 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 v a  2  s .  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 {//from w ww. j  av a2  s.  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()) {
                    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 {/* w  w  w . j av a2 s .c o  m*/
        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";
    }// w w  w  .  j av  a  2s .  c  om
    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 {/*from ww  w .  j a  va2  s. c  o  m*/
        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 ww. jav 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());
    }
}