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:org.gwtnode.examples.features.feature.HttpFeature.java

License:Apache License

@Override
public void call() {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode("/Features.js"));
    try {/*from   w  ww .j  a v a2s. c om*/
        builder.sendRequest(null, new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                process.stdout().write("HTTP request succeeded!");
            }

            @Override
            public void onError(Request request, Throwable exception) {
                process.stdout().write("HTTP request failed");
            }
        });
    } catch (RequestException e) {
        process.stdout().write("Http request failed: " + e);
    }
}

From source file:org.gwtopenmaps.demo.openlayers.client.basic.AbstractSourceButton.java

License:Apache License

public void onClick(ClickEvent event) {
    RequestBuilder reqBuilder = new RequestBuilder(RequestBuilder.GET, this.sourceCodeURL);
    try {//w  ww  .j av  a2s. c o m
        reqBuilder.sendRequest("", new RequestCallback() {
            public void onResponseReceived(Request request, Response response) {
                showSourceCode(response.getText());
            }

            public void onError(Request request, Throwable exception) {
            }
        });
    } catch (RequestException ex) {
    }

}

From source file:org.jboss.as.console.client.shared.runtime.logging.store.LogStore.java

License:Open Source License

private void doStreamLogFile(final String fileName, final Dispatcher.Channel channel) {
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, encode(streamUrl(fileName)));
    requestBuilder.setHeader("Accept", "text/plain");
    requestBuilder.setHeader("Content-Type", "text/plain");
    String bearerToken = DMRHandler.getBearerToken();
    if (bearerToken != null)
        requestBuilder.setHeader("Authorization", "Bearer " + bearerToken);

    requestBuilder.setIncludeCredentials(true);
    try {/* ww w .ja va2s  .c om*/
        // store the request in order to cancel it later
        pendingStreamingRequest = new PendingStreamingRequest(fileName,
                requestBuilder.sendRequest(null, new RequestCallback() {
                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getStatusCode() >= 400) {
                            channel.nack(new IllegalStateException("Failed to stream log file " + fileName
                                    + ": " + response.getStatusCode() + " - " + response.getStatusText()));
                        } else {
                            LogFile newLogFile = new LogFile(fileName, response.getText());
                            newLogFile.setFollow(false);
                            states.put(fileName, newLogFile);
                            activate(newLogFile);
                            channel.ack();
                        }
                    }

                    @Override
                    public void onError(Request request, Throwable exception) {
                        channel.nack(exception);
                    }
                }), channel);
    } catch (RequestException e) {
        channel.nack(e);
    }
}

From source file:org.jboss.as.quickstarts.gwthelloworld.client.local.HelloWorldClient.java

License:Apache License

/**
 * Handles a click of the button by sending an AJAX request to the HelloWorldResource and then updating the {@code result}
 * label in response.//from w w w. j  ava 2s  .c om
 * 
 * @param e Details of the click event. Ignored by this handler.
 */
@UiHandler("sayHelloButton")
public void onButtonClick(ClickEvent e) {
    try {
        new RequestBuilder(RequestBuilder.GET, "hello/json/" + URL.encodePathSegment(name.getValue()))
                .sendRequest(null, new RequestCallback() {

                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getStatusCode() == Response.SC_OK) {
                            HelloResponse r = (HelloResponse) JsonUtils.safeEval(response.getText());
                            result.setText(r.getResult());
                        } else {
                            handleError("Server responded with status code " + response.getStatusCode());
                        }
                    }

                    @Override
                    public void onError(Request request, Throwable exception) {
                        handleError(exception.getMessage());
                    }
                });
    } catch (RequestException exception) {
        handleError(exception.getMessage());
    }
}

From source file:org.jboss.bpm.console.client.Authentication.java

License:Open Source License

/**
 * Login using specific credentials./* w ww.j a  v  a  2  s  .  c  o  m*/
 * This delegates to {@link com.google.gwt.http.client.RequestBuilder#setUser(String)}
 * and {@link com.google.gwt.http.client.RequestBuilder#setPassword(String)}
 */
private void requestAssignedRoles() {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, rolesUrl);

    ConsoleLog.debug("Request roles: " + rb.getUrl());

    /*if (user != null && pass != null)
    {
      rb.setUser(user);
      rb.setPassword(pass);
            
      if (!GWT.isScript()) // hosted mode only
      {
        rb.setHeader("xtest-user", user);
        rb.setHeader("xtest-pass", pass); // NOTE: This is plaintext, use for testing only
      }
    }*/

    try {
        rb.sendRequest(null, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                ConsoleLog.debug("requestAssignedRoles() HTTP " + response.getStatusCode());

                // parse roles
                if (200 == response.getStatusCode()) {
                    rolesAssigned = Authentication.parseRolesAssigned(response.getText());
                    if (callback != null)
                        callback.onLoginSuccess(request, response);
                } else {
                    onError(request, new Exception(response.getText()));
                }
            }

            public void onError(Request request, Throwable t) {
                // auth failed
                // Couldn't connect to server (could be timeout, SOP violation, etc.)
                if (callback != null)
                    callback.onLoginFailed(request, t);
                else
                    throw new RuntimeException("Unknown exception upon login attempt", t);
            }
        });
    }

    catch (RequestException e1) {
        // Couldn't connect to server
        throw new RuntimeException("Unknown error upon login attempt", e1);
    }
}

From source file:org.jboss.bpm.console.client.BootstrapAction.java

License:Open Source License

public RequestBuilder.Method getRequestMethod() {
    return RequestBuilder.GET;
}

From source file:org.jboss.bpm.console.client.LoginView.java

License:Open Source License

private void requestSessionID() {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,
            config.getConsoleServerUrl() + "/rs/identity/sid");

    try {/*from w  ww .  j  a  v  a2 s .c  o m*/
        rb.sendRequest(null, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                ConsoleLog.debug("SID: " + response.getText());
                ConsoleLog.debug("Cookies: " + Cookies.getCookieNames());
                final String sid = response.getText();

                auth = new Authentication(config, sid, URLBuilder.getInstance().getUserInRoleURL(KNOWN_ROLES));

                auth.setCallback(new Authentication.AuthCallback() {

                    public void onLoginSuccess(Request request, Response response) {
                        // clear the form
                        usernameInput.setText("");
                        passwordInput.setText("");

                        // display main console
                        window.hide();

                        // assemble main layout
                        DeferredCommand.addCommand(new Command() {
                            public void execute() {
                                // move the loading div to foreground
                                DOM.getElementById("splash").getStyle().setProperty("zIndex", "1000");
                                DOM.getElementById("ui_loading").getStyle().setProperty("visibility",
                                        "visible");

                                // launch workspace
                                GWT.runAsync(new RunAsyncCallback() {
                                    public void onFailure(Throwable throwable) {
                                        GWT.log("Code splitting failed", throwable);
                                        MessageBox.error("Code splitting failed", throwable.getMessage());
                                    }

                                    public void onSuccess() {

                                        List<String> roles = auth.getRolesAssigned();
                                        StringBuilder roleString = new StringBuilder();
                                        int index = 1;
                                        for (String s : roles) {
                                            roleString.append(s);
                                            if (index < roles.size())
                                                roleString.append(",");
                                            index++;

                                        }

                                        // populate authentication context
                                        // this will trigger the AuthenticaionModule
                                        // and finally initialize the workspace UI

                                        Registry.get(SecurityService.class).setDeferredNotification(false);

                                        MessageBuilder.createMessage().toSubject("AuthorizationListener")
                                                .signalling().with(SecurityParts.Name, auth.getUsername())
                                                .with(SecurityParts.Roles, roleString.toString())
                                                .noErrorHandling().sendNowWith(ErraiBus.get());

                                        Timer t = new Timer() {

                                            public void run() {
                                                // hide the loading div
                                                DeferredCommand.addCommand(new Command() {
                                                    public void execute() {
                                                        DOM.getElementById("ui_loading").getStyle()
                                                                .setProperty("visibility", "hidden");
                                                        DOM.getElementById("splash").getStyle()
                                                                .setProperty("visibility", "hidden");
                                                    }
                                                });

                                            }
                                        };
                                        t.schedule(2000);

                                    }
                                });

                            }
                        });

                        window = null;
                    }

                    public void onLoginFailed(Request request, Throwable t) {
                        usernameInput.setText("");
                        passwordInput.setText("");
                        messagePanel.setHTML(
                                "<div style='color:#CC0000;'>Authentication failed. Please try again:</div>");
                    }
                });

                Registry.set(Authentication.class, auth);

                createLayoutWindowPanel();
                window.pack();
                window.center();

                // focus
                usernameInput.setFocus(true);

            }

            public void onError(Request request, Throwable t) {
                ConsoleLog.error("Failed to initiate session", t);
            }
        });
    } catch (RequestException e) {
        ConsoleLog.error("Request error", e);
    }
}

From source file:org.jboss.bpm.console.client.LoginView.java

License:Open Source License

/**
 * The j_security_check URL is a kind of temporary resource that only exists
 * if tomcat decided that the login page should be shown.
 *//*from   w  ww  .j  ava  2s .com*/
private void requestProtectedResource() {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,
            config.getConsoleServerUrl() + "/rs/identity/secure/sid");

    try {
        rb.sendRequest(null, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                ConsoleLog.debug("requestProtectedResource() HTTP " + response.getStatusCode());
                auth.login(getUsername(), getPassword());
            }

            public void onError(Request request, Throwable t) {
                ConsoleLog.error("Failed to request protected resource", t);
            }
        });
    } catch (RequestException e) {
        ConsoleLog.error("Request error", e);
    }
}

From source file:org.jboss.dmr.client.dispatch.impl.DMRHandler.java

License:Open Source License

private RequestBuilder chooseRequestBuilder(final ModelNode operation) {
    RequestBuilder requestBuilder;// w  w  w .  j ava2s .c om
    final String op = operation.get(OP).asString();
    if (READ_RESOURCE_DESCRIPTION_OPERATION.equals(op)) {
        String endpoint = endpointConfig.getUrl();
        if (endpoint.endsWith("/")) {
            endpoint = endpoint.substring(0, endpoint.length() - 1);
        }
        String descriptionUrl = endpoint + descriptionOperationToUrl(operation);
        requestBuilder = new RequestBuilder(RequestBuilder.GET,
                com.google.gwt.http.client.URL.encode(descriptionUrl));
        requestBuilder.setHeader(HEADER_ACCEPT, DMR_ENCODED);
        requestBuilder.setHeader(HEADER_CONTENT_TYPE, DMR_ENCODED);
        requestBuilder.setIncludeCredentials(true);
        requestBuilder.setRequestData(null);
    } else {
        requestBuilder = postRequestBuilder();
        requestBuilder.setRequestData(operation.toBase64String());
    }

    // obtain the bearer token and use it to set an Authorization "Bearer" header
    String bearerToken = getBearerToken();
    if (bearerToken != null) {
        requestBuilder.setHeader("Authorization", "Bearer " + bearerToken);
    }

    return requestBuilder;
}

From source file:org.jboss.errai.enterprise.jaxrs.client.shared.interceptor.RestCallResultManipulatingInterceptor.java

License:Apache License

@Override
public void aroundInvoke(final RestCallContext context) {
    String url = context.getRequestBuilder().getUrl();
    url = url.substring(0, url.indexOf("?")) + "?result=result";
    context.setRequestBuilder(new RequestBuilder(RequestBuilder.GET, url));

    context.proceed(new RemoteCallback<String>() {
        @Override//from  w  ww.j a  va  2  s  .  com
        public void callback(String response) {
            context.setResult(response + "_intercepted");
        }
    });
}