List of usage examples for com.google.gwt.http.client RequestBuilder send
public Request send() throws RequestException
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 {// www . jav a 2 s . c o 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 w w w. j ava2 s. com } 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/* ww w. j ava 2s . c o 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 .j a v a2s .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 2s.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// w w w.ja va2 s . co 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()); }//ww w. j av a 2 s. co 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//from w w w . jav a 2s.c o m * @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)); } }
From source file:org.emfjson.gwt.handlers.HttpHandler.java
License:Open Source License
public static void create(final ResourceSet resourceSet, URI createService, final Callback<Resource> callback) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(createService.toString())); builder.setHeader("Content-Type", "application/json"); builder.setCallback(new RequestCallback() { @Override/*from w ww . j a v a 2 s . c o m*/ public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 201) { String location = response.getHeader("Location"); Resource resource = resourceSet.createResource(URI.createURI(location)); callback.onSuccess(resource); } else { callback.onFailure(new Exception("Resource has not been created")); } } @Override public void onError(Request request, Throwable exception) { callback.onFailure(exception); } }); try { builder.send(); } catch (RequestException e) { callback.onFailure(e); } }
From source file:org.emfjson.gwt.handlers.HttpHandler.java
License:Open Source License
@Override public void createInputStream(final URI uri, Map<?, ?> options, final Callback<Map<?, ?>> callback) { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(uri.toString())); builder.setHeader("Content-Type", "application/json"); builder.setCallback(new RequestCallback() { @Override//ww w . j a va 2 s .co m public void onResponseReceived(Request request, Response response) { Map<String, Object> resultMap = new HashMap<String, Object>(); Map<String, Object> responseMap = new HashMap<String, Object>(); resultMap.put(URIConverter.OPTION_RESPONSE, responseMap); if (200 == response.getStatusCode()) { String responseText = response.getText(); if (responseText != null) { InputStream stream = new ByteArrayInputStream(responseText.getBytes()); responseMap.put(URIConverter.RESPONSE_RESULT, stream); } callback.onSuccess(resultMap); } else { callback.onFailure(new Exception("Error " + response.getStatusCode())); } } @Override public void onError(Request request, Throwable exception) { callback.onFailure(exception); } }); try { builder.send(); } catch (RequestException e) { callback.onFailure(e); } }