Search in sources :

Example 76 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project pentaho-platform by pentaho.

the class SwitchLocaleCommand method performOperation.

protected void performOperation(boolean feedback) {
    // stuff the locale in the server's session so we can use it
    // to override the browser setting, as needed
    // $NON-NLS-1$
    final String url = GWT.getHostPageBaseURL() + "api/mantle/locale";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    try {
        builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
        builder.sendRequest(locale, new RequestCallback() {

            public void onError(Request request, Throwable exception) {
            // showError(exception);
            }

            public void onResponseReceived(Request request, Response response) {
            }
        });
    } catch (RequestException e) {
    // showError(e);
    }
    String newLocalePath = "Home?locale=" + locale;
    String baseUrl = GWT.getModuleBaseURL();
    int index = baseUrl.indexOf("/mantle/");
    if (index >= 0) {
        newLocalePath = baseUrl.substring(0, index) + "/Home?locale=" + locale;
    }
    Window.Location.replace(newLocalePath);
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Example 77 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project gwt-ol3 by TDesjardins.

the class WfsExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    // create a vector layer
    Vector vectorSource = new Vector();
    VectorLayerOptions vectorLayerOptions = new VectorLayerOptions();
    vectorLayerOptions.setSource(vectorSource);
    ol.layer.Vector wfsLayer = new ol.layer.Vector(vectorLayerOptions);
    // create a view
    View view = new View();
    Coordinate centerCoordinate = new Coordinate(-8908887.277395891, 5381918.072437216);
    view.setCenter(centerCoordinate);
    view.setZoom(12);
    view.setMaxZoom(19);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    map.addLayer(DemoUtils.createOsmLayer());
    map.addLayer(wfsLayer);
    Wfs wfs = new Wfs();
    WfsWriteFeatureOptions wfsWriteFeatureOptions = new WfsWriteFeatureOptions();
    String[] featureTypes = { "water_areas" };
    wfsWriteFeatureOptions.setSrsName("EPSG:3857");
    wfsWriteFeatureOptions.setFeaturePrefix("osm");
    wfsWriteFeatureOptions.setFeatureNS("http://openstreemap.org");
    wfsWriteFeatureOptions.setFeatureTypes(featureTypes);
    // set a filter
    wfsWriteFeatureOptions.setFilter(new IsLike("name", "Mississippi*"));
    wfsWriteFeatureOptions.setOutputFormat("application/json");
    // create WFS-XML node
    Node wfsNode = wfs.writeGetFeature(wfsWriteFeatureOptions);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "https://ahocevar.com/geoserver/wfs");
    requestBuilder.setRequestData(new XMLSerializer().serializeToString(wfsNode));
    requestBuilder.setCallback(new RequestCallback() {

        @Override
        public void onResponseReceived(com.google.gwt.http.client.Request request, Response response) {
            GeoJson geoJson = new GeoJson();
            Feature[] features = geoJson.readFeatures(response.getText());
            vectorSource.addFeatures(features);
            map.getView().fit(vectorSource.getExtent());
        }

        @Override
        public void onError(com.google.gwt.http.client.Request request, Throwable exception) {
            Window.alert(exception.getMessage());
        }
    });
    try {
        requestBuilder.send();
    } catch (RequestException e) {
        Window.alert(e.getMessage());
    }
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) MapOptions(ol.MapOptions) Node(elemental2.dom.Node) GeoJson(ol.format.GeoJson) IsLike(ol.format.filter.IsLike) RequestException(com.google.gwt.http.client.RequestException) Vector(ol.source.Vector) XMLSerializer(com.github.desjardins.elemental.XMLSerializer) Wfs(ol.format.Wfs) View(ol.View) VectorLayerOptions(ol.layer.VectorLayerOptions) Response(com.google.gwt.http.client.Response) WfsWriteFeatureOptions(ol.format.WfsWriteFeatureOptions) RequestCallback(com.google.gwt.http.client.RequestCallback) Coordinate(ol.Coordinate) Map(ol.Map)

Example 78 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project activityinfo by bedatadriven.

the class AttachmentUploadFieldWidget method checkBlobExistance.

public void checkBlobExistance() {
    try {
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uploader.getBaseUrl() + "/exists");
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    addNewRow(uploader.getAttachment());
                    setState(true);
                    fireValueChanged();
                } else {
                    Log.error("Failed to fetch attachment serving url. Status code is not ok. ");
                    setState(false);
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                Log.error("Failed to fetch attachment serving url. ", exception);
                setState(false);
            }
        });
    } catch (Exception e) {
        Log.error("Failed to send request for fetching serving url. ", e);
        setState(false);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request)

Example 79 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project activityinfo by bedatadriven.

the class ImageUploadFieldWidget method fetchImageServingUrl.

public void fetchImageServingUrl() {
    try {
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uploader.getBaseUrl() + "/imageUrl");
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    servingUrl = response.getText();
                    setState(State.LOADED);
                } else {
                    setState(State.FAILED);
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                Log.error("Failed to fetch image serving url. ", exception);
                setState(State.FAILED);
            }
        });
    } catch (Exception e) {
        Log.error("Failed to send request for fetching serving url. ", e);
        setState(State.FAILED);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request)

Example 80 with RequestBuilder

use of com.google.gwt.http.client.RequestBuilder in project ovirt-engine by oVirt.

the class UploadImageModel method onTest.

private void onTest() {
    String imageProxyAddress = (String) AsyncDataProvider.getInstance().getConfigValuePreConverted(ConfigValues.ImageProxyAddress);
    // $NON-NLS-1$ //$NON-NLS-2$
    String url = "https://" + imageProxyAddress + "/info/";
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url);
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onError(Request request, Throwable ex) {
                onTestError(ex);
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                try {
                    getTestResponse().setEntity(response);
                } catch (IllegalArgumentException ex) {
                    onTestError(ex);
                }
            }
        });
    } catch (RequestException ex) {
        onTestError(ex);
    }
}
Also used : Response(com.google.gwt.http.client.Response) RequestBuilder(com.google.gwt.http.client.RequestBuilder) RequestCallback(com.google.gwt.http.client.RequestCallback) Request(com.google.gwt.http.client.Request) RequestException(com.google.gwt.http.client.RequestException)

Aggregations

RequestBuilder (com.google.gwt.http.client.RequestBuilder)132 RequestException (com.google.gwt.http.client.RequestException)116 RequestCallback (com.google.gwt.http.client.RequestCallback)113 Response (com.google.gwt.http.client.Response)111 Request (com.google.gwt.http.client.Request)110 MessageDialogBox (org.pentaho.gwt.widgets.client.dialogs.MessageDialogBox)27 CsrfRequestBuilder (org.pentaho.mantle.client.csrf.CsrfRequestBuilder)22 JSONString (com.google.gwt.json.client.JSONString)19 ArrayList (java.util.ArrayList)16 Bindable (org.pentaho.ui.xul.stereotype.Bindable)15 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)13 JSONObject (com.google.gwt.json.client.JSONObject)11 JsArrayString (com.google.gwt.core.client.JsArrayString)9 JSONArray (com.google.gwt.json.client.JSONArray)8 List (java.util.List)8 HTML (com.google.gwt.user.client.ui.HTML)7 IDialogCallback (org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)7 EmptyRequestCallback (org.pentaho.mantle.client.EmptyRequestCallback)7 PromptDialogBox (org.pentaho.gwt.widgets.client.dialogs.PromptDialogBox)6 RepositoryFile (org.pentaho.gwt.widgets.client.filechooser.RepositoryFile)6