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.presenter.helpers.RequestWithProgressDialog.java

License:Open Source License

public Request sendRequest(final String requestData, final RequestCallback callback) throws RequestException {
    request = rb.sendRequest(requestData, new RequestCallback() {
        @Override//from  w ww .ja v  a 2 s .c  om
        public void onResponseReceived(Request request, Response response) {
            hideLoadingMessage();
            callback.onResponseReceived(request, response);

        }

        @Override
        public void onError(Request request, Throwable exception) {
            GWT.log(exception.toString(), exception);
            if (retries-- <= 0) {
                alert("Failure " + exception.toString());
                callback.onError(request, exception);
            } else {
                try {
                    alert("Failure " + exception.toString() + " retrying..");
                    request = sendRequest(requestData, callback);
                } catch (RequestException e) {
                    this.onError(request, e);
                }
            }
        }
    });
    if (request != null)
        createLoadingMessage();
    return request;
}

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

License:Open Source License

public void getProcess() {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, processUri);
    try {/*from  w w w. j  a  v  a  2 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()) {
                    CloudProcess process = CloudProcess.asCloudProcess(response.getText());
                    updateProcess(process);
                } else {

                }
            }

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

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

License:Open Source License

public void getProgress() {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, progressUri);
    try {/*from   w  w  w .j  av a  2  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()) {
                    Progress progress = Progress.asProgress(response.getText());
                    updateProgress(progress);
                } else {

                }
            }

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

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

License:Open Source License

public void getRepo() {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, repositoryUri);
    try {/*from www .j  a v a 2 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(response.getStatusCode() + " " + response.getText());
                if (200 == response.getStatusCode()) {
                    Repository repo = Repository.asRepository(response.getText());
                    updateRepo(repo);
                } else {
                    Window.alert("Update failure: " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Update exception: " + e.toString());
    }
}

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

License:Open Source License

private void updateRepoDetails(String url, String name, String description, String target, String kind,
        String root, boolean isPublic, String authId, String password) {

    if (url == null || url.trim().length() == 0) {
        url = cacheManager.ServiceAddress + "repository";
    }//  w w w  .  j  a  v  a  2  s  .  c  o 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");
    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("&target=");
    args.append(URL.encodeQueryString(target));
    args.append("&kind=");
    args.append(URL.encodeQueryString(kind));
    args.append("&root=");
    args.append(URL.encodeQueryString(root));
    args.append("&isPublic=");
    args.append(URL.encode(isPublic ? "true" : "false"));
    if (password != null && password.length() > 0) {
        args.append("&repositoryId=");
        args.append(URL.encodeQueryString(authId));
        args.append("&secret=");
        args.append(URL.encodeQueryString(password));
    }
    GWT.log(args.toString());
    GWT.log(authId);
    GWT.log(password);
    try {
        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(
                            "Repository update error " + response.getStatusText() + " " + response.getText());
                }
            }

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

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

License:Open Source License

/**
 * @param node/*from www .ja  v a  2 s  . c o m*/
 */
public void makePublic(final FileNode node, boolean isPublic) {
    String url = node.getRepository() + "/permissions";
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("isPublic=");
    args.append(URL.encodeQueryString(Boolean.toString(isPublic)));
    args.append("&filename=");
    args.append(URL.encodeQueryString(getCanonicalName(node)));
    try {
        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()) {
                    GWT.log("Reply is" + response.getText());
                    GWT.log("Headers is " + response.getHeadersAsString());
                    GWT.log("Status Text " + response.getStatusText());
                    fetchFiles(repositoryUri, node.getPath());
                } else {
                    Window.alert("Update failure: " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Update exception: " + e.toString());
    }
}

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

License:Open Source License

/**
 * @param node/*ww  w  . j  a  v  a  2 s .c o  m*/
 * @param fileDetailsPanel 
 */
public void getOrigin(final FileNode node, final FileDetailsPanel fileDetailsPanel) {

    String url = node.getRepository() + "/origin" + "?name=" + URL.encodeQueryString(node.getName());
    if (!isNullOrBlank(node.getPath())) {
        url += "&path=" + URL.encodeQueryString(node.getPath());
    }

    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        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(response.getStatusCode() + " " + response.getText());
                if (200 == response.getStatusCode()) {
                    Origin origin = Origin.asOrigin(response.getText());
                    provideOrigin(node, origin, fileDetailsPanel);
                } else {
                    Window.alert(
                            "Origin fetch failure: " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Origin fetch exception: " + e.toString());
    }

}

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

License:Open Source License

/**
 * @param node/*from  w  w w. j a  va 2s  .  c om*/
 * @param originPanel 
 */
public void getSignature(final String file) {

    String url = this.repo.getUri() + "/sign?name=" + URL.encodeQueryString(file);
    final String uri = this.repositoryUri;

    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, url);
    try {
        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(response.getStatusCode() + " " + response.getText());
                if (200 == response.getStatusCode()) {
                    if (uri.equals(RepoContentActivity.this.repositoryUri)) {
                        UploadSignature signature = UploadSignature.asUploadSignature(response.getText());
                        provideSignature(signature);
                    }
                } else {
                    Window.alert(
                            "Signature fetch failure: " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Signature fetch exception: " + e.toString());
    }

}

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

License:Open Source License

public void getRepo(String repoUri) {
    // Send request to server and catch any errors.
    this.lastRepoURI = repoUri;
    // this.lastPrefix = null;
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, repoUri);
    try {/*from ww  w.ja va  2s .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(response.getStatusCode() + " " + response.getText());
                if (200 == response.getStatusCode()) {
                    Repository repo = Repository.asRepository(response.getText());
                    updateRepo(repo);
                } else {
                    Window.alert("Update failure: " + response.getStatusText() + " " + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Update exception: " + e.toString());
    }
}

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

License:Open Source License

/**
 * @param view//from   w  w  w  . j a  va  2  s.  co  m
 */
public void fetchFiles(String repoURI, final String prefix) {
    String url = repoURI + "/list";
    if (prefix != null) {
        url += "?prefix=" + URL.encodeQueryString(prefix);
    }
    this.lastRepoURI = repoURI;
    this.lastPrefix = prefix;
    // 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(response.getText());
                    RepoListResponse result = RepoListResponse.parseJSON(response.getText());
                    List<FileNode> crumbs = result.getCrumbs();
                    List<FileNode> namesWithPlaceholders = result.getFiles();
                    if (crumbs != null && placeholderMap != null) {
                        String lastPath = "";
                        if (crumbs.size() > 1) {
                            FileNode lastCrumb = crumbs.get(crumbs.size() - 1);
                            lastPath = getCanonicalName(lastCrumb) + "/";
                        }
                        GWT.log("lastPath=" + lastPath);
                        if (placeholderMap.containsKey(lastPath)) {
                            java.util.Collection<FileNode> placeholders = placeholderMap.get(lastPath).values();
                            namesWithPlaceholders = new ArrayList<FileNode>(
                                    placeholders.size() + result.getFiles().size());
                            GWT.log("adding placeholder");
                            namesWithPlaceholders.addAll(placeholders);
                            namesWithPlaceholders.addAll(result.getFiles());
                        }
                    }
                    updateRepoContent(result.getCrumbs(), namesWithPlaceholders);
                } else {
                    GWT.log("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        GWT.log("Couldn't retrieve JSON " + e.getMessage());
    }

}