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.view.AccountListView.java

License:Open Source License

private void kill(String uri) {
    String url = uri;//  www.  j a  va 2s .  c o  m
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url);

    try {
        @SuppressWarnings("unused")
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("Couldn't delete " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (204 == response.getStatusCode()) {
                    if (AccountListView.this.accountListActivity != null)
                        AccountListView.this.accountListActivity.getAccountList();
                } else {
                    Window.alert("Couldn't delete (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        Window.alert("Couldn't delete " + e.getMessage());

    }

}

From source file:n3phele.client.view.ActivityListView.java

License:Open Source License

private void kill(String uri) {
    String url = uri;/*from w  w  w  . j  a v a2  s  . c o m*/
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url);

    try {
        @SuppressWarnings("unused")
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("Couldn't delete " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (204 == response.getStatusCode()) {
                } else {
                    Window.alert("Couldn't delete (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        Window.alert("Couldn't delete " + e.getMessage());

    }
}

From source file:n3phele.client.view.ForgotPasswordView.java

License:Open Source License

private void createUser(String url, final String email, String firstName, String lastName) {

    // Send request to server and catch any errors.
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    builder.setUser("signup");
    builder.setPassword("newuser");
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("email=");
    args.append(URL.encodeQueryString(email));
    args.append("&firstName=");
    args.append(URL.encodeQueryString(firstName));
    args.append("&lastName=");
    args.append(URL.encodeQueryString(lastName));

    try {/*from   w ww.j ava  2 s . c  o  m*/
        @SuppressWarnings("unused")
        Request request = builder.sendRequest(args.toString(), new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("User create error " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (201 == response.getStatusCode()) {
                    Window.alert("User " + email + " password reset. Check your email for details.");
                } else {
                    Window.alert("User password reset failure " + response.getStatusText() + "\n"
                            + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("User password reset exception " + e.getMessage());
    }
}

From source file:n3phele.client.view.NewUserView.java

License:Open Source License

private void createUser(String url, final String email, String firstName, String lastName, String password,
        String ec2Id, String ec2Secret) {

    // Send request to server and catch any errors.
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    builder.setUser("signup");
    builder.setPassword("newuser");
    builder.setHeader("Content-type", "application/x-www-form-urlencoded");
    StringBuilder args = new StringBuilder();
    args.append("email=");
    args.append(URL.encodeQueryString(email));
    args.append("&firstName=");
    args.append(URL.encodeQueryString(firstName));
    args.append("&lastName=");
    args.append(URL.encodeQueryString(lastName));
    if (password != null && password.length() > 0) {
        args.append("&secret=");
        args.append(URL.encodeQueryString(password));
    }//from  w  ww  . j a  v a 2  s .c o  m
    if (ec2Id != null && ec2Id.length() != 0) {
        args.append("&ec2Id=");
        args.append(URL.encodeQueryString(ec2Id));
        args.append("&ec2Secret=");
        args.append(URL.encodeQueryString(ec2Secret));
    }
    try {
        @SuppressWarnings("unused")
        Request request = builder.sendRequest(args.toString(), new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("User create error " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                GWT.log("Got reply");
                if (201 == response.getStatusCode()) {
                    Window.alert("User " + email + " created.");
                } else {
                    Window.alert("User create failure " + response.getStatusText() + "\n" + response.getText());
                }
            }

        });
    } catch (RequestException e) {
        Window.alert("Account create exception " + e.getMessage());
    }
}

From source file:n3phele.client.view.RepoListView.java

License:Open Source License

private void kill(String uri) {
    String url = uri;//www  . j  a  v  a2 s  .c o m
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url);

    try {
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("Couldn't delete " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (204 == response.getStatusCode()) {
                    if (RepoListView.this.repositoryListActivity != null)
                        RepoListView.this.repositoryListActivity.getRepositoryList();
                } else {
                    Window.alert("Couldn't delete (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        Window.alert("Couldn't delete " + e.getMessage());

    }
}

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
 * /*w  w w .  j  a  v a2 s  .  co  m*/
 * @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());
    }
}

From source file:net.autosauler.ballance.client.gui.ChangeLogPanel.java

License:Apache License

/**
 * Instantiates a new change log panel.//from w w  w  . j  a  v  a 2 s.  c  o m
 */
private ChangeLogPanel() {

    MainPanel.setCommInfo(true);
    try {
        new RequestBuilder(RequestBuilder.GET, "CHANGELOG").sendRequest("", new RequestCallback() {
            @Override
            public void onError(Request res, Throwable throwable) {
                MainPanel.setCommInfo(false);
                Log.error(throwable.getMessage());
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                MainPanel.setCommInfo(false);
                String text = response.getText();
                HTML w = new HTML("<p>" + text + "</p>");
                d.setWidget(w);

            }
        });
    } catch (RequestException e) {
        MainPanel.setCommInfo(false);
        Log.error(e.getMessage());
    }

    d = new DecoratorPanel();
    d.setWidth("100%");

    initWidget(d);
}

From source file:net.dancioi.jcsphotogallery.client.model.ReadXMLGeneric.java

License:Open Source License

/**
 * Gets the XML file from http server./*w  ww .  j a  va2  s  .c o  m*/
 */
public void readXmlFile(final String file, final int flag) {
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, file);
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                showException("Error sending request");
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    parseXMLString(response.getText(), flag); // careful here, this is an asynchronous callback.
                } else if (404 == response.getStatusCode()) {
                    showException("File " + file + " not found on server. Wrong name or missing.");
                } else {
                    showException("Other exception on GET the " + file + " file");
                }
            }
        });
    } catch (RequestException ex) {
        new ReadException("Error sending request");
    }
}

From source file:net.dancioi.webdav.client.Put.java

License:Open Source License

protected void tryRequest(RequestBuilderWebdav builder) {
    try {/*from  w  w  w  .  jav a 2 s .  c o m*/
        builder.sendRequest(dataContent, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                //setConnected(false); //"Could not connect to server."
            }

            public void onResponseReceived(Request request, Response response) {
                if (201 == response.getStatusCode()) {

                } else {
                    commandException = new CommandException(response.getStatusCode(), response.getStatusText());
                }
            }
        });
    } catch (RequestException e) {
        // do something with this.
        // failed to send the request
    }
}

From source file:net.dancioi.webdav.client.WdHttpMethod.java

License:Open Source License

protected void tryRequest(RequestBuilderWebdav builder) {

    try {/*from w w  w .j  a va  2s. co  m*/
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                setConnected(false); //"Could not connect to server."
            }

            public void onResponseReceived(Request request, Response response) {
                setStatusCode(response.getStatusCode());
                setResponseText(response.getText());
                setResponseStatus(response.getStatusText());
                goNext();
            }
        });
    } catch (RequestException e) {
        // do something with this.
        // failed to send the request
    }
}