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

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

Introduction

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

Prototype

public void setHeader(String header, String value) 

Source Link

Document

Sets a request header with the given name and value.

Usage

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";
    }/*from   w  w  w.  j  a v  a2  s.  com*/
    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.CommandActivity.java

License:Open Source License

public void run(Command data, String name, Map<String, String> paramMap, List<FileSpecification> inputFiles,
        List<FileSpecification> outputFiles, boolean sendEmail, String account, long profileId) {
    ExecuteCommandRequest request = new ExecuteCommandRequest();
    if (name == null || name.trim().length() == 0) {
        name = data.getName();/* ww w.  j  a v a 2 s .co  m*/
    } else {
        name = name.trim();
    }
    request.setName(name);
    request.setAccount(account);
    request.setParameters(paramMap);
    request.setInputFiles(inputFiles);
    request.setOutputFiles(outputFiles);
    request.setNotify(sendEmail);
    request.setUser(AuthenticatedRequestFactory.getDefaultUsername());
    request.setCommand(data.getUri());
    request.setProfileId(profileId);
    String url = cacheManager.ServiceAddress + "activity";
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/json");

    try {
        Request msg = builder.sendRequest(request.toString(), new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                GWT.log("Couldn't retrieve JSON " + exception.getMessage());
                Window.alert("Couldn't retrieve JSON " + exception.getMessage());
            }

            public void onResponseReceived(Request request, Response response) {
                if (201 == response.getStatusCode()) {
                    GWT.log(response.getText() + " " + response.getHeadersAsString());
                    //cacheManager.refreshProgressList(); // deal with "eventual consistency" of queries
                    goToPrevious();
                } else {
                    Window.alert("Error code: " + response.getStatusCode() + " Status Text:"
                            + response.getStatusText() + "\n" + response.getText());
                    GWT.log("Couldn't submit command (" + response.getStatusText() + " " + response.getText()
                            + ")");

                }
            }
        });
    } catch (RequestException e) {
        Window.alert("Request exception " + e.getMessage() + "\n" + e.toString());
    }

}

From source file:n3phele.client.presenter.CreateServiceActivity.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.equals("null")) {
        url = cacheManager.ServiceAddress + "account";
    }//from   w  w  w . java2s .  com
    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.getStatusCode() + response.getStatusText());
                }
            }

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

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

License:Open Source License

public void exec(String name, Context context) {
    List<String> params = new ArrayList<String>();
    String action = "StackService";
    if (name == null || name.trim().length() == 0) {
        name = null;/*from   ww w. j a  va 2 s .  c  o  m*/
    }
    params.add("action=" + URL.encodeQueryString(action));
    String arg = "";
    params.add("arg=" + URL.encodeQueryString(arg.trim()));
    if (name != null)
        params.add("name=" + URL.encodeQueryString(name.trim()));

    String url = cacheManager.ServiceAddress + "process/exec";
    String seperator = "?";
    for (String param : params) {
        url = url + seperator + param;
        seperator = "&";
    }
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.POST, url);
    builder.setHeader("Content-type", "application/json");

    try {
        GWT.log("Context :" + context.toJSON().toString());
        Request msg = builder.sendRequest(context == null ? null : context.toJSON().toString(),
                new RequestCallback() {
                    public void onError(Request request, Throwable exception) {
                        GWT.log("Couldn't retrieve JSON " + exception.getMessage());
                        Window.alert("Couldn't retrieve JSON " + exception.getMessage());
                    }

                    public void onResponseReceived(Request request, Response response) {
                        if (201 == response.getStatusCode()) {
                            GWT.log(response.getText() + " " + response.getHeader("location"));
                            goToPrevious();
                        } else {
                            Window.alert("Error code: " + response.getStatusCode() + " Status Text:"
                                    + response.getStatusText() + "\n" + response.getText());
                            GWT.log("Couldn't submit command (" + response.getStatusText() + " "
                                    + response.getText() + ")");

                        }
                    }
                });
    } catch (RequestException e) {
        Window.alert("Request exception " + e.getMessage() + "\n" + e.toString());
    }
}

From source file:n3phele.client.presenter.helpers.AuthenticatedRequestFactory.java

License:Open Source License

public static RequestBuilder newCacheManagerRequest(Method httpMethod, String url) {
    if (!authenticated) {
        GWT.log("Attempts to build a request when no credentials present");
        return null;
    }/*  w  w w  .  j  a  va 2 s .  c om*/
    RequestBuilder request = new RequestBuilder(httpMethod, url);
    request.setTimeoutMillis(35000);
    request.setHeader("Authorization", base64);
    //request.setUser(defaultUsername);
    //request.setPassword(defaultPassword);
    return request;
}

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 ww w.  jav a2s.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  a2  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.UserActivity.java

License:Open Source License

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

    // 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("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  w  w .  j  a  v a 2  s .  c o  m*/
    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()) {
                    if (isSelf) {
                        User user = User.asUser(response.getText());
                        String pw = password;
                        if (pw == null || pw.length() == 0) {
                            pw = AuthenticatedRequestFactory.getDefaultPassword();
                        }
                        AuthenticatedRequestFactory.setCredentials(user.getName(), pw, user);
                        N3phele.basePanel.updateUser(user);
                    }
                    goToPrevious();
                } else {
                    Window.alert("Update failure: " + response.getStatusText() + " " + response.getText());
                }
            }

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

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

License:Open Source License

private void kill(String uri) {
    String url = uri;/*from w ww  . j  a v  a2 s.c o  m*/
    // Send request to server and catch any errors.
    RequestBuilder builder = AuthenticatedRequestFactory.newRequest(RequestBuilder.DELETE, url);
    builder.setHeader("account",
            account.getUri().substring(account.getUri().lastIndexOf('/') + 1, account.getUri().length()));
    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 (AccountHyperlinkView.this.presenter != null) {
                        presenter.initTimerDelete();
                    }
                    //presenter.callGetTopLevel();
                    //AccountHyperlinkView.this.presenter.getVSList();
                } 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  w w. j a  v  a 2s . 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());
    }
}