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:ch.unifr.pai.twice.mousecontrol.client.TouchPadWidget.java

License:Apache License

/**
 * starts the execution of the component
 *///from   ww  w .java  2 s .  co m
public void start() {
    if (!running) {
        label.setText("looking for available remote-clients");
        getAvailableClients(new Command() {

            @Override
            public void execute() {
                label.setText((availableClients == null ? "0" : availableClients.length) + " clients found");
                if (getCurrentClient() != null) {
                    label.setText("looking for cursor on client " + getCurrentClient());
                    lookForCursor = new Timer() {

                        @Override
                        public void run() {
                            try {
                                new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + controlServlet
                                        + "?a=x"
                                        + (getCurrentClient() != null ? "&targetUUID=" + getCurrentClient()
                                                : "")
                                        + (uuid != null ? "&uuid=" + uuid : "")
                                        + (host != null ? "&host=" + host : "")
                                        + (port != null ? "&port=" + port : "")).sendRequest(null,
                                                new RequestCallback() {

                                                    @Override
                                                    public void onResponseReceived(Request request,
                                                            Response response) {
                                                        if (response.getStatusCode() > 400)
                                                            onError(request, null);
                                                        label.setText("GOT DATA: " + response.getText());
                                                        String color = extractColor(response);
                                                        if (color == null || color.isEmpty()
                                                                || color.equals("#null"))
                                                            color = null;
                                                        extractLastAction(response);

                                                        setScreenDimension(extractScreenDimensions(response));
                                                        if (color != null) {
                                                            setColor(color);
                                                            cursorAssigned();
                                                        } else {
                                                            noCursorAvailable();
                                                        }
                                                    }

                                                    @Override
                                                    public void onError(Request request, Throwable exception) {
                                                        noCursorAvailable();
                                                    }
                                                });
                            } catch (RequestException e) {
                                noCursorAvailable();
                            }
                        }
                    };
                    lookForCursor.run();
                }
            }
        });
    }
}

From source file:ch.unifr.pai.twice.mousecontrol.client.TouchPadWidget.java

License:Apache License

/**
 * Sends the given query to the mouse pointer controller servlet
 * //from www . j a va 2 s.co  m
 * @param query
 * @param callback
 */
protected void send(String query, final Command callback) {
    try {
        if (active) {

            new RequestBuilder(RequestBuilder.GET,
                    GWT.getHostPageBaseURL() + controlServlet + "?" + (query != null ? query : "a=x")
                            + (getCurrentClient() != null ? "&targetUUID=" + getCurrentClient() : "")
                            + (uuid != null ? "&uuid=" + uuid : "") + (host != null ? "&host=" + host : "")
                            + (port != null ? "&port=" + port : "") + ("&user=" + Authentication.getUserName()))
                                    .sendRequest(null, new RequestCallback() {

                                        @Override
                                        public void onResponseReceived(Request request, Response response) {
                                            if (response.getStatusCode() > 400)
                                                onError(request, null);
                                            String color = extractColor(response);
                                            if (response.getText().trim().isEmpty()) {
                                                label.setText("No connection available");
                                                noConnection = true;
                                            } else {
                                                if (noConnection) {
                                                    label.setText("");
                                                    noConnection = false;
                                                }

                                                if (color == null || color.isEmpty() || color.equals("#null"))
                                                    color = null;
                                                extractLastAction(response);
                                                setColor(color);
                                                setScreenDimension(extractScreenDimensions(response));
                                                if (callback != null)
                                                    callback.execute();
                                            }
                                        }

                                        @Override
                                        public void onError(Request request, Throwable exception) {
                                            setActive(false);
                                        }
                                    });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ch.unifr.pai.twice.mousecontrol.client.TouchPadWidget.java

License:Apache License

/**
 * Request the server for available shared devices
 * //from   w  w w . j av a  2 s .c o m
 * @param callback
 */
private void getAvailableClients(final Command callback) {
    try {
        new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + controlServlet + "?a=g")
                .sendRequest(null, new RequestCallback() {

                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getText() != null && !response.getText().isEmpty()) {
                            availableClients = response.getText().split("\n");
                        }
                        if (callback != null)
                            callback.execute();
                    }

                    @Override
                    public void onError(Request request, Throwable exception) {
                        GWT.log("Available clients request", exception);
                        if (callback != null)
                            callback.execute();
                    }
                });
    } catch (RequestException e) {
        GWT.log("Request Exception", e);
        if (callback != null)
            callback.execute();

    }
}

From source file:ch.unifr.pai.twice.widgets.mpProxyScreenShot.client.Viewer.java

License:Apache License

@Override
public void onModuleLoad() {
    Timer t = new Timer() {

        @Override/*w  w w  . ja va2s  .  c  o  m*/
        public void run() {
            try {
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Window.Location.getProtocol() + "//"
                        + Window.Location.getHost() + "/miceScreenShot/manager");
                rb.sendRequest(null, new RequestCallback() {

                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        RootPanel.getBodyElement().setInnerHTML(response.getText());
                    }

                    @Override
                    public void onError(Request request, Throwable exception) {
                    }
                });
            } catch (RequestException e) {
                e.printStackTrace();
            }
        }
    };
    t.run();
    //      t.scheduleRepeating(1000);

}

From source file:com.appspot.attractiveness.client.RatingWidget.java

License:Apache License

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 *//*from  w  w  w  .j a va 2  s . c o  m*/
@Override
public void onModuleLoad() {
    // Setup RequestFactory
    EventBus eventBus = new SimpleEventBus();
    requestFactory = GWT.create(AttractivenessRequestFactory.class);
    requestFactory.initialize(eventBus);

    AuthRequest request = new AuthRequest(FB_OAUTH_URL, CLIENT_ID).withScopes(RELATIONSHIPS_SCOPE,
            ABOUT_ME_SCOPE);
    Auth.get().login(request, new Callback<String, Throwable>() {
        @Override
        public void onSuccess(String result) {
            // TODO: This should be externalized into a seperate Facebook
            // Opengraph GWT library
            String fbQueryUrl = PERSON_GRAPH_QUERY + "access_token=" + result;
            fbQueryUrl = URL.encode(fbQueryUrl);
            try {
                new RequestBuilder(RequestBuilder.GET, fbQueryUrl).sendRequest(null, new RequestCallback() {
                    @Override
                    public void onResponseReceived(Request request, Response response) {
                        PersonJso personData = PersonJso.fromJSON(response.getText());
                        Window.alert(
                                "Gender: " + personData.getGender() + ", Birthday: " + personData.getBirthday()
                                        + ", RelStatus: " + personData.getRelationshipStatus());
                    }

                    @Override
                    public void onError(Request request, Throwable exception) {
                        Window.alert("I was unable to get data: " + exception.getMessage());
                    }
                });
            } catch (RequestException ex) {
                Window.alert(ex.getMessage());
            }
        }

        @Override
        public void onFailure(Throwable reason) {
            Window.alert("Failed to Authenticate: " + reason.getMessage());
        }
    });

    RootPanel.get("contentDiv").add(this);
}

From source file:com.arcbees.analytics.client.ClientAnalytics.java

License:Apache License

public void fallback(JsArrayMixed arguments) {
    if ("send".equals(arguments.getString(0))) {
        JSONObject jsonOptions = new JSONObject(arguments.getObject(arguments.length() - 1));
        StringBuilder url = new StringBuilder();
        url.append(fallbackPath).append("?");
        url.append(ProtocolTranslator.getFieldName("hitType")).append("=")
                .append(URL.encodeQueryString(arguments.getString(1)));

        for (String key : jsonOptions.keySet()) {
            if (!"hitCallback".equals(key)) {
                JSONValue jsonValue = jsonOptions.get(key);
                String strValue = "";
                if (jsonValue.isBoolean() != null) {
                    strValue = jsonValue.isBoolean().booleanValue() + "";
                } else if (jsonValue.isNumber() != null) {
                    strValue = jsonValue.isNumber().doubleValue() + "";
                } else if (jsonValue.isString() != null) {
                    strValue = jsonValue.isString().stringValue();
                }/*from w  w w. ja  v a2  s  .c om*/
                url.append("&").append(ProtocolTranslator.getFieldName(key)).append("=")
                        .append(URL.encodeQueryString(strValue));
            }
        }
        try {
            RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url.toString());
            requestBuilder.setCallback(new RequestCallback() {

                @Override
                public void onResponseReceived(Request request, Response response) {
                    // TODO call hitcallback if needed.
                }

                @Override
                public void onError(Request request, Throwable exception) {
                    // TODO Auto-generated method stub
                }
            });
            requestBuilder.send();
        } catch (RequestException e) {
        }
    }
}

From source file:com.badlogic.gdx.backends.gwt.GwtNet.java

License:Apache License

@Override
public void sendHttpRequest(final HttpRequest httpRequest, final HttpResponseListener httpResultListener) {
    if (httpRequest.getUrl() == null) {
        httpResultListener.failed(new GdxRuntimeException("can't process a HTTP request without URL set"));
        return;/*from   w  w w  .ja  v a  2s.c o m*/
    }

    final String method = httpRequest.getMethod();
    final String value = httpRequest.getContent();
    final boolean valueInBody = method.equalsIgnoreCase(HttpMethods.POST) || method.equals(HttpMethods.PUT);

    RequestBuilder builder;

    String url = httpRequest.getUrl();
    if (method.equalsIgnoreCase(HttpMethods.GET)) {
        if (value != null) {
            url += "?" + value;
        }
        builder = new RequestBuilder(RequestBuilder.GET, url);
    } else if (method.equalsIgnoreCase(HttpMethods.POST)) {
        builder = new RequestBuilder(RequestBuilder.POST, url);
    } else if (method.equalsIgnoreCase(HttpMethods.DELETE)) {
        if (value != null) {
            url += "?" + value;
        }
        builder = new RequestBuilder(RequestBuilder.DELETE, url);
    } else if (method.equalsIgnoreCase(HttpMethods.PUT)) {
        builder = new RequestBuilder(RequestBuilder.PUT, url);
    } else {
        throw new GdxRuntimeException("Unsupported HTTP Method");
    }

    Map<String, String> content = httpRequest.getHeaders();
    Set<String> keySet = content.keySet();
    for (String name : keySet) {
        builder.setHeader(name, content.get(name));
    }

    builder.setTimeoutMillis(httpRequest.getTimeOut());

    builder.setIncludeCredentials(httpRequest.getIncludeCredentials());

    try {
        Request request = builder.sendRequest(valueInBody ? value : null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                httpResultListener.handleHttpResponse(new HttpClientResponse(response));
                requests.remove(httpRequest);
                listeners.remove(httpRequest);
            }

            @Override
            public void onError(Request request, Throwable exception) {
                httpResultListener.failed(exception);
                requests.remove(httpRequest);
                listeners.remove(httpRequest);
            }
        });
        requests.put(httpRequest, request);
        listeners.put(httpRequest, httpResultListener);

    } catch (Throwable e) {
        httpResultListener.failed(e);
    }

}

From source file:com.badlogic.gdx.backends.gwt.preloader.TextLoader.java

License:Apache License

public TextLoader(String url, LoaderCallback<String> callback) {
    this.callback = callback;
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    try {/*  w  w w  .  ja  v a 2  s .c  o  m*/
        builder.sendRequest(null, new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                TextLoader.this.callback.success(response.getText());
            }

            @Override
            public void onError(Request request, Throwable exception) {
                TextLoader.this.callback.error();
            }
        });
    } catch (RequestException e) {
        callback.error();
    }
}

From source file:com.bramosystems.oss.player.showcase.client.PlaylistPane.java

License:Apache License

private void loadList(String provider) {
    String spf = GWT.getHostPageBaseURL() + "media/jspf-core.json";
    if (provider.equals("bst.vimeo")) {
        spf = GWT.getHostPageBaseURL() + "media/jspf-vimeo.json";
    } else if (provider.equals("bst.youtube")) {
        spf = GWT.getHostPageBaseURL() + "media/jspf-youtube.json";
    }/* w w w.  ja  v a 2  s  . c o  m*/

    try {
        RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, spf);
        rb.sendRequest(null, new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                try {
                    SPFPlaylist spf = PlaylistFactory.parseJspfPlaylist(response.getText());
                    entries = spf.toPlaylist();
                    refreshView();
                } catch (ParseException ex) {
                    GWT.log("Parse Exception", ex);
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
            }
        });
    } catch (RequestException ex) {
        GWT.log("Request Exception", ex);
    }
}

From source file:com.brentryan.client.widgets.dialogs.AboutDialog.java

public AboutDialog() {

    aboutDialog.addButton(new Button("aboutOk", new ButtonConfig() {

        {// ww w . j a  v a  2s  .  c  o m
            setText(DIALOG_CONSTANTS.Ok());
            setButtonListener(new ButtonListenerAdapter() {

                public void onClick(Button button, EventObject e) {
                    aboutDialog.destroy(true);
                }
            });
        }
    }));

    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "License.html");
    rb.setTimeoutMillis(30000);

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

            public void onError(Request request, Throwable exception) {
                aboutDialog.destroy(true);
                MessageBox.alert(DIALOG_CONSTANTS.ErrorTitle(), CONSTANTS.LicenseError());
            }

            public void onResponseReceived(Request request, Response response) {
                // add content to the center region
                BorderLayout layout = aboutDialog.getLayout();
                ContentPanel contentPanel = new ContentPanel();
                contentPanel.add(new HTML(response.getText()));
                layout.add(contentPanel);
                aboutDialog.show();
            }
        });
    } catch (RequestException e) {
        GWT.log("Error while retrieving BrentRyan license", e);
    }

    initWidget(aboutDialog);
}