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

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

Introduction

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

Prototype

Method GET

To view the source code for com.google.gwt.http.client RequestBuilder GET.

Click Source Link

Document

Specifies that the HTTP GET method should be used.

Usage

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

License:Open Source License

/**
 * @param node/*ww  w  .  j  av a  2 s.c  o  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 {// ww w. ja  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.RepoContentActivity.java

License:Open Source License

/**
 * @param view//  w ww.  j a  v  a  2s  .  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());
    }

}

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

License:Open Source License

public void getRepositoryList() {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, repositoryCollection);
    try {/*from   w w  w .j  a  v a 2 s .  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("Got reply");
                if (200 == response.getStatusCode()) {
                    Collection<Repository> repository = Repository.asCollection(response.getText());
                    updateRepositoryList(repository.getElements());
                } else {

                }
            }

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

From source file:n3phele.client.presenter.ServiceDetailsActivity.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.  ja v  a  2  s  .c o m*/
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Got error");
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    CloudProcess cloud = CloudProcess.asCloudProcess(response.getText());
                    serviceUri = cloud.getAction();
                    getAction();
                } else {

                }
            }

        });
    } catch (RequestException e) {
    }
}

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

License:Open Source License

public void getAction() {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, serviceUri);
    try {/* www  .j  av  a 2  s .  c  o m*/
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Got error");
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    StackServiceAction stackAction = StackServiceAction.asAction(response.getText());
                    display.setStackAction(stackAction);
                }
            }

        });
    } catch (RequestException e) {
        GWT.log("Got error");
    }
}

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

License:Open Source License

public void getAction(String uri) {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, uri);
    try {//w  w  w. j a va2s  . com
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Got error");
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    stackAction = StackServiceAction.asAction(response.getText());
                    for (Stack s : stackAction.getStackList()) {
                        if (s.getId().equals(stackId)) {
                            stack = s;
                            break;
                        }

                    }
                    if (stack.getVms().size() > 0) {
                        for (String str : stack.getVms()) {
                            getProcess(str);
                        }
                    }
                }
            }

        });
    } catch (RequestException e) {
        GWT.log("Got error");
    }
}

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

License:Open Source License

public void getProcess(String processUri) {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, processUri);
    try {/*from w ww.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("Got reply");
                if (200 == response.getStatusCode()) {
                    CloudProcess process = CloudProcess.asCloudProcess(response.getText());
                    listCloudProcess.add(process);
                    display.setDisplayList(listCloudProcess);
                    getAssimilateAction(process.getName(), process.getAction());

                } else {

                }
            }

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

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

License:Open Source License

public void getAssimilateAction(String name, String uri) {
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.GET, uri);
    final String fname = name;
    try {/*from  www  .  j  a  va  2 s. c o m*/
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Got error");
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (200 == response.getStatusCode()) {
                    AssimilateVMAction action = AssimilateVMAction.asAction(response.getText());
                    updateCloudIP(fname, action.getTargetIP());
                }
            }

        });
    } catch (RequestException e) {
        GWT.log("Got error");
    }
}

From source file:name.cphillipson.experimental.gwt.client.module.common.widget.suggest.MultivalueSuggestBox.java

License:Apache License

/**
 * Retrieve Options (name-value pairs) that are suggested from the REST endpoint
 * //from  w ww .j  av a  2  s  .c  om
 * @param query
 *            - the String search term
 * @param from
 *            - the 0-based begin index int
 * @param to
 *            - the end index inclusive int
 * @param callback
 *            - the OptionQueryCallback to handle the response
 */
private void queryOptions(final String query, final int from, final int to,
        final OptionQueryCallback callback) {
    final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
            URL.encode(m_restEndpointUrl + "?q=" + query + "&indexFrom=" + from + "&indexTo=" + to));

    // Set our headers
    builder.setHeader("Accept", "application/json");
    builder.setHeader("Accept-Charset", "UTF-8");

    builder.setCallback(new RequestCallback() {

        @Override
        public void onResponseReceived(com.google.gwt.http.client.Request request, Response response) {
            final JSONValue val = JSONParser.parse(response.getText());
            final JSONObject obj = val.isObject();
            final int totSize = (int) obj.get(OptionResultSet.TOTAL_SIZE).isNumber().doubleValue();
            final OptionResultSet options = new OptionResultSet(totSize);
            final JSONArray optionsArray = obj.get(OptionResultSet.OPTIONS).isArray();

            if (options.getTotalSize() > 0 && optionsArray != null) {

                for (int i = 0; i < optionsArray.size(); i++) {
                    if (optionsArray.get(i) == null) {
                        /*
                         * This happens when a JSON array has an invalid trailing comma
                         */
                        continue;
                    }

                    final JSONObject jsonOpt = optionsArray.get(i).isObject();
                    final Option option = new Option();
                    option.setName(jsonOpt.get(OptionResultSet.DISPLAY_NAME).isString().stringValue());
                    option.setValue(jsonOpt.get(OptionResultSet.VALUE).isString().stringValue());
                    options.addOption(option);
                }
            }
            callback.success(options);
        }

        @Override
        public void onError(com.google.gwt.http.client.Request request, Throwable exception) {
            callback.error(exception);
        }
    });

    try {
        builder.send();
    } catch (final RequestException e) {
        updateFormFeedback(FormFeedback.ERROR, "Error: " + e.getMessage());
    }
}