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.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 ww  w.  j a v  a 2s .  com
        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 {// ww  w .jav  a2s .  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";
    }//from w  ww  .  j  av a 2s.  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/*  w  w w.  j  a 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/*from   www  .  ja  v  a 2  s  . co  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/* ww  w  . j av  a  2s.  co m*/
 * @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 www  .j av  a2 s .  com
        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 ww  .j  a v  a  2s . c om*/
 */
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());
    }

}

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

License:Open Source License

public void deleteFile(final FileNode object) {
    String filename = getCanonicalName(object);
    String url = this.repo.getUri() + "/file?filename=" + URL.encodeQueryString(filename);
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url);
    try {/*  w  ww  .  j ava2s  .co  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()) {
                    fetchFiles(object.getRepository(), object.getPath());
                } else {
                    Window.alert("Delete failure: " + response.getStatusText() + " " + response.getText());
                }
            }

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

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

License:Open Source License

public void deleteFolder(final FileNode object) {
    String filename = getCanonicalName(object);

    String url = this.repo.getUri() + "/folder?filename=" + URL.encodeQueryString(filename);
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url);
    try {//from w  ww  .  j  a v a 2  s.  com
        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()) {
                    Window.alert("Delete failure: " + response.getStatusText() + " " + response.getText());
                }
            }

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