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

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

Introduction

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

Prototype

protected RequestBuilder(String httpMethod, String url) 

Source Link

Document

Creates a builder using the parameters values for configuration.

Usage

From source file:org.celstec.arlearn2.gwtcommonlib.client.auth.OauthTwitter.java

License:Open Source License

public static void autenticate() {

    String url = "https://api.twitter.com/oauth/request_token";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    //        builder.setHeader("Content-Type", "application/json");
    builder.setHeader("Authorization",
            "oauth_callback=\"http%3A%2F%2Fmyapp.com%3A3005%2Ftwitter%2Fprocess_callback\"");

    try {//from  w  w  w . j  a  v a 2 s. co  m
        Request request = builder.sendRequest("", new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                System.out.println("response received");
                if (200 == response.getStatusCode()) {

                }

            }

            @Override
            public void onError(Request request, Throwable exception) {

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

From source file:org.chtijbug.workbench.drools.client.navbar.LogoWidgetView.java

License:Apache License

@PostConstruct
public void init() {
    final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "banner/banner.html");
    rb.setCallback(new RequestCallback() {
        @Override//from w w w .j  av a 2 s .  c om
        public void onResponseReceived(final Request request, final Response response) {
            final HTMLPanel html = new HTMLPanel(response.getText());
            container.setWidget(html);
        }

        @Override
        public void onError(final Request request, final Throwable exception) {
            container.setWidget(new Label(AppConstants.INSTANCE.logoBannerError()));
        }
    });
    try {
        final Request r = rb.send();
    } catch (RequestException re) {
        container.setWidget(new Label(AppConstants.INSTANCE.logoBannerError()));
    }

    initWidget(container);
}

From source file:org.cleanlogic.cesiumjs4gwt.showcase.basic.AbstractSourceButton.java

License:Apache License

public void onClick(ClickEvent event) {
    RequestBuilder reqBuilder = new RequestBuilder(RequestBuilder.GET, this.sourceCodeURL);
    try {// w  w  w. j  a  v  a2s. c om
        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.cleanlogic.ol4gwt.showcase.examples.VectorWFSGetFeature.java

License:Apache License

@Override
public void buildPanel() {
    StyleOptions styleOptions = new StyleOptions();
    styleOptions.stroke = StrokeStyle.create(Color.create(0, 0, 255, 1.0), 2);
    VectorLayerOptions vectorLayerOptions = new VectorLayerOptions();
    vectorLayerOptions.source = vectorSource;
    //        vectorLayerOptions.style = new Style[] {new Style(styleOptions)};
    VectorLayer vectorLayer = new VectorLayer(vectorLayerOptions);

    BingMapsSourceOptions bingMapsSourceOptions = new BingMapsSourceOptions();
    bingMapsSourceOptions.imagerySet = "Aerial";
    bingMapsSourceOptions.key = "AkGbxXx6tDWf1swIhPJyoAVp06H0s0gDTYslNWWHZ6RoPqMpB9ld5FY1WutX8UoF";
    TileLayer raster = TileLayer.create(new BingMapsSource(bingMapsSourceOptions));

    ViewOptions viewOptions = new ViewOptions();
    viewOptions.center = Coordinate.create(-8908887.277395891, 5381918.072437216);
    viewOptions.maxZoom = 19;/*from  w w  w .j a v a2 s  .  co m*/
    viewOptions.zoom = 12;

    MapOptions mapOptions = new MapOptions();
    mapOptions.layers = new Collection<>(new BaseLayer[] { raster, vectorLayer });
    mapOptions.view = new View(viewOptions);

    final MapPanel mapPanel = new MapPanel(mapOptions);
    mapPanel.setHeight("400px");

    Filter filter = FilterUtils.and(new IsLikeFilter("name", "Mississippi*"),
            new EqualToFilter("waterway", "riverbank"));

    GetFeatureOptions getFeatureOptions = new GetFeatureOptions();
    getFeatureOptions.srsName = "EPSG:3857";
    getFeatureOptions.featureNS = "http://openstreemap.org";
    getFeatureOptions.featurePrefix = "osm";
    getFeatureOptions.featureTypes = new String[] { "water_areas" };
    getFeatureOptions.outputFormat = "application/json";
    getFeatureOptions.filter = filter;
    WFSFormat wfsFormat = new WFSFormat();
    Node node = wfsFormat.writeGetFeature(getFeatureOptions);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST,
            "https://ahocevar.com/geoserver/wfs");
    requestBuilder.setRequestData(new XMLSerializer().serializeToString(node));
    requestBuilder.setCallback(new RequestCallback() {
        @Override
        public void onResponseReceived(Request request, Response response) {
            GeoJSONFormat format = new GeoJSONFormat();
            Feature[] features = format.readFeatures(response.getText());
            vectorSource.addFeatures(features);
            mapPanel.getMap().getView().fit(vectorSource.getExtent());
        }

        @Override
        public void onError(Request request, Throwable throwable) {
            GWT.log(throwable.toString());
        }
    });

    contentPanel.add(new HTML(
            "<p>This example generates a GetFeature request which uses a PropertyIsEqualTo and a PropertyIsLike filter, and then posts the request to load the features that match the query.</p>"));
    contentPanel.add(mapPanel);

    initWidget(contentPanel);
    try {
        requestBuilder.send();
    } catch (RequestException ex) {
        GWT.log(ex.getLocalizedMessage());
    }
}

From source file:org.client.JavaApp2Workbook.java

License:Open Source License

/**
 * Resolve one type of content that a Xholon app can have.
 * @param fileName A local file name, or remote uri (http), or null.
 * @param contentType One of "_xhn" "ih" "cd" "csh" etc.
 *///ww  w.j  a  v a2s . c o  m
protected void resolve(String fileName, String contentType) {
    //this.println("trying to resolve " + fileName + " " + contentType);
    if (fileName == null) {
        // app is probably using a ClientBundle
        String txt = app.rcConfig(contentType, (ClientBundleWithLookup) app.findGwtClientBundle());
        resolveDone(txt, contentType);
        return;
    }
    final String _contentType = contentType;
    final String _fileName = fileName;
    final IXholon _this = this;
    try {
        new RequestBuilder(RequestBuilder.GET, fileName).sendRequest("", new RequestCallback() {
            @Override
            public void onResponseReceived(Request req, Response resp) {
                if (resp.getStatusCode() == resp.SC_OK) {
                    resolveDone(resp.getText(), _contentType);
                } else {
                    _this.println("\nrequest: GET " + _fileName);
                    _this.println("status code:" + resp.getStatusCode());
                    _this.println("status text:" + resp.getStatusText());
                    _this.println("text:\n" + resp.getText());
                    resolveDone(null, _contentType);
                }
            }

            @Override
            public void onError(Request req, Throwable e) {
                _this.println("onError:" + e.getMessage());
                resolveDone(null, _contentType);
            }
        });
    } catch (RequestException e) {
        _this.println("RequestException:" + e.getMessage());
        resolveDone(null, _contentType);
    }
}

From source file:org.curriki.gwt.client.widgets.metadata.MetadataEdit.java

License:Open Source License

private void displaySkills(String value, final VerticalPanel panel) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/SearchI2G/render?uri="
            + URL.encodeComponent(value) + "&language=" + URL.encodeComponent(getLanguages()));
    try {/*from   ww  w .ja  va  2s  . c om*/
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                Window.alert("Error at rendering: " + exception);
            }

            public void onResponseReceived(Request request, Response response) {
                if (200 != response.getStatusCode()) {
                    Window.alert(
                            "Error " + response.getStatusCode() + " at rendering: " + response.getStatusText());
                    return;
                }
                panel.clear();
                panel.add(new HTML(response.getText()));

            }
        });
    } catch (RequestException e) {
        Window.alert("Error at launching rendering: " + e);
    }
}

From source file:org.dashbuilder.client.navbar.LogoWidgetView.java

License:Apache License

@PostConstruct
public void init() {
    final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "banner/banner.html");
    rb.setCallback(new RequestCallback() {
        @Override//from w  w  w.  j  ava  2s.  c o m
        public void onResponseReceived(final Request request, final Response response) {
            final HTMLPanel html = new HTMLPanel(response.getText());
            container.setWidget(html);
        }

        @Override
        public void onError(final Request request, final Throwable exception) {
            container.setWidget(new Label(AppConstants.INSTANCE.logoBannerError()));
        }
    });
    try {
        rb.send();
    } catch (RequestException re) {
        container.setWidget(new Label(AppConstants.INSTANCE.logoBannerError()));
    }

    initWidget(container);
}

From source file:org.dashbuilder.client.navbar.TopMenuBar.java

License:Apache License

public void setNavHeaderHtml(String htmlFile) {
    DOMUtil.removeAllChildren(navHeader);

    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, htmlFile);
    rb.setCallback(new RequestCallback() {

        public void onResponseReceived(Request request, Response response) {
            HTMLPanel html = new HTMLPanel(response.getText());
            navHeader.appendChild((Node) html.getElement());
        }// w ww. j a va2  s  . c o  m

        public void onError(Request request, Throwable exception) {
            Label label = new Label(AppConstants.INSTANCE.logoBannerError());
            navHeader.appendChild((Node) label.getElement());
        }
    });

    try {
        rb.send();
    } catch (RequestException re) {
        Label label = new Label(AppConstants.INSTANCE.logoBannerError());
        navHeader.appendChild((Node) label.getElement());
    }
}

From source file:org.datacleaner.monitor.util.DCRequestBuilder.java

License:Open Source License

public DCRequestBuilder(Method method, String url) {
    _requestBuilder = new RequestBuilder(method, url);
}

From source file:org.dataconservancy.dcs.access.client.HttpGet.java

License:Apache License

/**
 * Do multiple http requests and only return success when all complete. May
 * be more than one failure reported./* w  w  w . j  a v  a  2 s . c  o  m*/
 * 
 * cb.success returns a String[] parallel to urls with the results
 * 
 * @param urls
 * @param cb
 */
public static void request(final String[] urls, final Callback<String[]> cb) {
    final String[] result = new String[urls.length];

    for (int i = 0; i < urls.length; i++) {
        RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, urls[i]);
        final int which = i;

        try {
            rb.sendRequest(null, new RequestCallback() {
                public void onError(Request req, Throwable e) {
                    cb.failure(e.getMessage());
                }

                public void onResponseReceived(Request req, Response resp) {
                    if (resp.getStatusCode() != 200) {
                        cb.failure(resp.getText());
                    } else {
                        result[which] = resp.getText();

                        for (int j = 0; j < result.length; j++) {
                            if (result[j] == null) {
                                return;
                            }
                        }

                        cb.success(result);
                    }
                }
            });
        } catch (RequestException e) {
            cb.failure(e.getMessage());
        }
    }
}