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

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

Introduction

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

Prototype

public void setCallback(RequestCallback callback) 

Source Link

Document

Sets the response handler for this request.

Usage

From source file:org.bonitasoft.console.client.view.DashboardPanel.java

License:Open Source License

/**
 * @param aResult/*from   w ww .j  av a 2  s .c  o m*/
 */
protected void displayReport(ReportItem aResult) {
    try {
        RequestBuilder theRequestBuilder = new RequestBuilder(RequestBuilder.GET,
                myReportingDataSource.buildReportURL(aResult, ReportScope.USER));
        theRequestBuilder.setCallback(new RequestCallback() {
            public void onError(Request aRequest, Throwable anException) {
                if (anException instanceof SessionTimeOutException) {
                    // reload the page.
                    Window.Location.reload();
                }
                myReportHTML.setHTML("");
                myOnGoingRequests--;
                nbOfErrors++;
                GWT.log("Unable to display report (error count:" + nbOfErrors + ")", anException);
                if (nbOfErrors >= 3) {
                    GWT.log("Disabling recurrent call after too many consecutive errors.", null);
                    myUpdateTimer.cancel();
                }
            }

            public void onResponseReceived(Request aRequest, Response aResponse) {
                if (1 == myOnGoingRequests) {
                    myReportHTML.setHTML("");
                    if (aResponse.getStatusCode() == Response.SC_OK) {
                        myReportHTML.setHTML(aResponse.getText());
                        nbOfErrors = 0;
                    } else {
                        myReportHTML.setHTML(constants.unableToDisplayReport());
                        nbOfErrors++;
                        GWT.log("Unable to display report (error count:" + nbOfErrors + ") "
                                + aResponse.getText(), null);
                        if (nbOfErrors >= 3) {
                            GWT.log("Disabling recurrent call after too many errors.", null);
                            myUpdateTimer.cancel();
                        }
                    }
                } else {
                    GWT.log("Skipping report result as there is still " + (myOnGoingRequests - 1)
                            + " requests in the pipe.", null);
                }
                myOnGoingRequests--;
            }
        });
        GWT.log("RPC: querying reporting", null);
        theRequestBuilder.send();
    } catch (RequestException e) {
        myReportHTML.setHTML("");
    }

}

From source file:org.bonitasoft.console.client.view.reporting.ReportParametersEditorWidget.java

License:Open Source License

protected void run() {

    if (validate()) {
        try {//w ww.j a  va2  s  .  c  om
            RequestBuilder theRequestBuilder;
            final String theURL = myReportDataSource.buildReportURL(myItem, ReportScope.ADMIN);
            final String theCompleteURL = addParametersToURL(theURL);
            GWT.log("Calling the reporting engine with query: " + theCompleteURL);
            theRequestBuilder = new RequestBuilder(RequestBuilder.GET, theCompleteURL);
            theRequestBuilder.setCallback(new RequestCallback() {
                public void onError(Request aRequest, Throwable anException) {
                    myReportResultPanel.clear();
                    myReportResultPanel
                            .add(new HTML(constants.errorProcessingReport() + anException.getMessage()));
                    myDownloadLink.setHref(null);
                    myDownloadLink.setVisible(false);
                    myRefreshLink.setVisible(false);
                }

                public void onResponseReceived(Request aRequest, Response aResponse) {
                    myReportResultPanel.clear();
                    HTML theReport = new HTML();
                    theReport.setStyleName("bonita_report");
                    if (aResponse.getStatusCode() == Response.SC_OK) {
                        theReport.setHTML(aResponse.getText());
                        myDownloadLink.setHref(theCompleteURL + "&OutputFormat=pdf");
                        myDownloadLink.setVisible(true);
                        myRefreshLink.setVisible(true);
                    } else {
                        theReport.setHTML(constants.unableToDisplayReport() + "<BR/>" + aResponse.getText());
                        GWT.log("Unable to display report" + aResponse.getText(), null);
                        myDownloadLink.setHref(null);
                        myDownloadLink.setVisible(false);
                        myRefreshLink.setVisible(false);
                    }
                    myReportResultPanel.add(theReport);
                }
            });
            myReportResultPanel.clear();
            myReportResultPanel.add(new HTML(constants.loading()));
            theRequestBuilder.send();
        } catch (RequestException e) {
            Window.alert("Error while trying to query the reports:" + e.getMessage());
        }
    }
}

From source file:org.bonitasoft.console.client.view.reporting.UserStatsView.java

License:Open Source License

private void queryReport(int aRow, int aCol, int aReportIndex) {
    final RequestBuilder theRequestBuilder;
    if (aReportIndex < bonitaReports.length) {
        GWT.log("Calling report generation for: " + bonitaReports[aReportIndex].getUUID().getValue());
        try {//from w  w  w  . j a v a2  s.  co  m

            final HTML theCell;
            if (aCol % 2 == 0) {
                myCurrentRow = new FlowPanel();
                myCurrentRow.setStyleName("reporting_block");
                myReportListPanel.add(myCurrentRow);
            }
            theCell = new HTML();
            theCell.setHTML(myLoadingMessage);
            theCell.setStyleName("report_item");
            myCurrentRow.add(theCell);
            theRequestBuilder = new RequestBuilder(RequestBuilder.GET,
                    myReportingDataSource.buildReportURL(bonitaReports[aReportIndex], ReportScope.USER));
            theRequestBuilder.setCallback(new BonitaReportRequestCallback(aRow, aCol, aReportIndex, theCell));
            theRequestBuilder.send();
        } catch (RequestException e) {
            GWT.log("Error while trying to query the reports:" + e.getMessage(), e);
        }
    } else {
        myReloadButton.setVisible(true);
    }
}

From source file:org.bonitasoft.console.client.view.UserSettingsEditionView.java

License:Open Source License

private void buildSelectableReport(final ReportItem aReportItem, final HTML aContainer) {
    if (aContainer == null) {
        GWT.log("Container must not be null. Exit.", null);
        return;//from   ww w .  ja  v a2 s .c om
    }

    try {
        if (aReportItem == null || aReportItem.getFileName() == null
                || aReportItem.getFileName().length() == 0) {
            GWT.log("Report name must neither be null nor empty. Exit.", null);
            return;
        }
        if (aReportItem.getUUID().equals(myUserProfile.getDefaultReportUUID())
                || (myUserProfile.getDefaultReportUUID() == null
                        && aReportItem.getUUID().equals(ConsoleConstants.DEFAULT_REPORT_UUID))) {
            // Select the report if it is the one used by the user.
            selectReportContainer(aContainer);
        }
        RequestBuilder theRequestBuilder = new RequestBuilder(RequestBuilder.GET, buildReportURL(aReportItem));
        theRequestBuilder.setCallback(new RequestCallback() {
            public void onError(Request aRequest, Throwable anException) {
                aContainer.setHTML(constants.unableToDisplayReport());
            }

            public void onResponseReceived(Request aRequest, Response aResponse) {
                if (aResponse.getStatusCode() == Response.SC_OK) {
                    aContainer.setHTML(aResponse.getText());
                } else {
                    aContainer.setHTML(constants.unableToDisplayReport());
                }
                aContainer.addClickHandler(new ClickHandler() {

                    public void onClick(ClickEvent anEvent) {
                        selectReportContainer(aContainer);
                        mySelectedReport = aReportItem;
                    }

                });
            }
        });
        aContainer.setHTML(loadingHTML);
        theRequestBuilder.send();
    } catch (RequestException e) {
        aContainer.setHTML(constants.unableToDisplayReport());
    }

}

From source file:org.bonitasoft.web.toolkit.client.data.api.request.HttpRequest.java

License:Open Source License

/**
 * Send the HTTP request with data/*from   ww  w .j  a va 2 s .co  m*/
 *
 * @param method
 *        The method to use between RequestBuilder.GET, RequestBuilder.POST, RequestBuilder.PUT, RequestBuilder.DELETE
 * @param callback
 *        The APICallback to call onSuccess or onError.
 * @param url
 *        The URL of the API
 * @param datas
 *        The data to send
 */
public void send(final Method method, final String url, final String datas, final String contentType,
        final HttpCallback callback) {
    final RequestBuilder builder = new RequestBuilder(method, url);
    if (datas != null) {
        builder.setRequestData(datas);
    }
    if (contentType != null) {
        builder.setHeader("Content-Type",
                (contentType != null ? contentType : "text/plain") + ";charset=UTF-8");
    }

    if (UserSessionVariables.getUserVariable(UserSessionVariables.API_TOKEN) != null) {
        builder.setHeader("X-Bonita-API-Token",
                UserSessionVariables.getUserVariable(UserSessionVariables.API_TOKEN));
    }

    builder.setTimeoutMillis(30000);
    builder.setCallback(callback);
    Request request = null;
    try {
        request = builder.send();
    } catch (final RequestException e) {
        callback.onError(request, e);
    }
}

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 ww  w.  ja  va 2  s. 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 {
        final Request r = rb.send();
    } catch (RequestException re) {
        container.setWidget(new Label(AppConstants.INSTANCE.logoBannerError()));
    }

    initWidget(container);
}

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 a  2 s. c o  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.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 www  .  j av  a2  s  .  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());
        }//from  w  w w.j  a  v  a 2 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.eclipse.che.plugin.tour.client.TourExtension.java

License:Open Source License

/**
 * Download and parse the given URL/*w ww .  java  2  s  .c om*/
 * @param url the URL containing JSON file to be analyzed
 */
protected void remoteFetch(String url) {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
    try {
        rb.setCallback(new ParseJsonFileCallback());
        rb.send();

    } catch (RequestException e) {
        notificationManager.showNotification(new Notification("Unable to get tour" + e.getMessage(), ERROR));
    }
}