List of usage examples for com.google.gwt.http.client RequestCallback RequestCallback
RequestCallback
From source file:com.medassets.report.client.other.ContentWidget.java
License:Apache License
/** * Get the source code for a raw file.// w w w.jav a2 s . c o m * * @param filename the filename to load * @param callback the callback to call when loaded */ public void getRawSource(final String filename, final Callback<String> callback) { if (rawSource.containsKey(filename)) { callback.onSuccess(rawSource.get(filename)); } else { RequestCallback rc = new RequestCallback() { public void onError(Request request, Throwable exception) { callback.onError(); } public void onResponseReceived(Request request, Response response) { String text = response.getText(); rawSource.put(filename, text); callback.onSuccess(text); } }; String className = this.getClass().getName(); className = className.substring(className.lastIndexOf(".") + 1); sendSourceRequest(rc, "raw/" + filename + ".html"); } }
From source file:com.medassets.report.client.other.ContentWidget.java
License:Apache License
/** * Request the styles associated with the widget. * * @param callback the callback used when the styles become available *///from www.j a v a 2s. c o m public void getStyle(final Callback<String> callback) { if (styleDefs != null) { callback.onSuccess(styleDefs); } else { RequestCallback rc = new RequestCallback() { public void onError(Request request, Throwable exception) { callback.onError(); } public void onResponseReceived(Request request, Response response) { styleDefs = response.getText(); callback.onSuccess(styleDefs); } }; String srcPath = "gwtShowcaseSource/css/clean"; if (LocaleInfo.getCurrentLocale().isRTL()) { srcPath += "_rtl"; } String className = this.getClass().getName(); className = className.substring(className.lastIndexOf(".") + 1); sendSourceRequest(rc, srcPath + "/" + className + ".html"); } }
From source file:com.medassets.report.client.other.ContentWidget.java
License:Apache License
/** * Request the source code associated with the widget. * * @param callback the callback used when the source become available *//*from ww w .j av a2 s . c om*/ public void getSource(final Callback<String> callback) { if (sourceCode != null) { callback.onSuccess(sourceCode); } else { RequestCallback rc = new RequestCallback() { public void onError(Request request, Throwable exception) { callback.onError(); } public void onResponseReceived(Request request, Response response) { sourceCode = response.getText(); callback.onSuccess(sourceCode); } }; String className = this.getClass().getName(); className = className.substring(className.lastIndexOf(".") + 1); sendSourceRequest(rc, "gwtShowcaseSource/java/" + className + ".html"); } }
From source file:com.milmaps.client.MapTouchController.java
License:Open Source License
private void sendReport(String name, final GeodeticCoords gc) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "/pli-service/rs/sender/sendReportGeo"); String report = "<report name=\"" + name + "\" ip=\"127.0.0.1\" port=\"10011\" mcastIface=\"\" lat=\"" + gc.latitude().degrees() + "\" lon=\"" + gc.longitude().degrees() + "\"/>"; try {/*w w w .java 2 s. c om*/ builder.sendRequest(report, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { m_mapView.fullUpdateView(); } @Override public void onError(Request request, Throwable exception) { } }); } catch (RequestException ex) { Window.alert("fail"); Logger.getLogger(MapTouchController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.milmaps.client.MobileEntryPoint.java
License:Open Source License
private void sendReport(double lat, double lon) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, "/pli-service/rs/sender/sendReportGeo"); String report = "<report name=\"Me\" ip=\"127.0.0.1\" port=\"10011\" mcastIface=\"\" lat=\"" + lat + "\" lon=\"" + lon + "\"/>"; try {//from www . j av a 2 s .co m builder.sendRequest(report, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { m_mapView.fullUpdateView(); } @Override public void onError(Request request, Throwable exception) { } }); } catch (RequestException ex) { Window.alert("fail"); Logger.getLogger(MapTouchController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.moesol.gwt.maps.client.tms.FeatureReader.java
License:Open Source License
public void getFeatures(int level, double lat, double lng, final AsyncCallback<List<Feature>> callback) { String url = m_baseUrlPattern.replace("{level}", String.valueOf(level)) .replace("{lat}", String.valueOf(lat)).replace("{lng}", String.valueOf(lng)); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setHeader("Accept", "application/json"); try {//w ww .ja v a2s .c o m requestBuilder.sendRequest(null, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { callback.onSuccess(parseFeatures(response.getText())); } @Override public void onError(Request request, Throwable exception) { callback.onFailure(exception); } }); } catch (RequestException e) { callback.onFailure(e); } }
From source file:com.nanosim.client.ContentWidget.java
License:Apache License
public void onSelection(SelectionEvent<Integer> event) { // Show the associated widget in the deck panel int tabIndex = event.getSelectedItem().intValue(); deckPanel.showWidget(tabIndex);//from w w w. ja v a2 s .c o m // Load the source code String tabHTML = getTabBar().getTabHTML(tabIndex); if (!sourceLoaded && tabHTML.equals(constants.contentWidgetSource())) { sourceLoaded = true; String className = this.getClass().getName(); className = className.substring(className.lastIndexOf(".") + 1); requestSourceContents(NanosimConstants.DST_SOURCE_EXAMPLE + className + ".html", sourceWidget, null); } // Load the style definitions if (hasStyle() && tabHTML.equals(constants.contentWidgetStyle())) { final String theme = HomeScreen.CUR_THEME; if (styleDefs.containsKey(theme)) { styleWidget.setHTML(styleDefs.get(theme)); } else { styleDefs.put(theme, ""); RequestCallback callback = new RequestCallback() { public void onError(Request request, Throwable exception) { styleDefs.put(theme, "Style not available."); } public void onResponseReceived(Request request, Response response) { styleDefs.put(theme, response.getText()); } }; String srcPath = NanosimConstants.DST_SOURCE_STYLE + theme; String className = this.getClass().getName(); className = className.substring(className.lastIndexOf(".") + 1); requestSourceContents(srcPath + "/" + className + ".html", styleWidget, callback); } } }
From source file:com.nanosim.client.ContentWidget.java
License:Apache License
/** * Load the contents of a remote file into the specified widget. * //from w w w. j av a2 s.co m * @param url a partial path relative to the module base URL * @param target the target Widget to place the contents * @param callback the callback when the call completes */ protected void requestSourceContents(String url, final HTML target, final RequestCallback callback) { // Show the loading image if (loadingImage == null) { loadingImage = "<img src=\"" + GWT.getModuleBaseURL() + "images/loading.gif\">"; } DOM.setStyleAttribute(target.getElement(), "textAlign", "left"); target.setHTML(" " + loadingImage); // Request the contents of the file RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getModuleBaseURL() + url); RequestCallback realCallback = new RequestCallback() { public void onError(Request request, Throwable exception) { target.setHTML("Cannot find resource"); if (callback != null) { callback.onError(request, exception); } } public void onResponseReceived(Request request, Response response) { target.setHTML(response.getText()); if (callback != null) { callback.onResponseReceived(request, response); } } }; builder.setCallback(realCallback); // Send the request Request request = null; try { request = builder.send(); } catch (RequestException e) { realCallback.onError(request, e); } }
From source file:com.oracle.wci.user.registration.client.AsyncCall.java
License:Apache License
/** * Do post information via AJAX call to the server. * //from w ww .j a v a 2 s. co m * @param url * @param requestData */ public static void doPost(String url, String requestData) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); try { builder.setTimeoutMillis(MAX_TIMEOUT); // Request response = builder.sendRequest(requestData, new RequestCallback() { public void onResponseReceived(Request request, Response response) { } public void onError(Request request, Throwable exception) { if (exception instanceof RequestTimeoutException) { Window.alert(((RequestTimeoutException) exception).getMessage()); } else { Window.alert(exception.getMessage()); } } }); } catch (com.google.gwt.http.client.RequestException e) { Window.alert("Unable to send the request: " + e.getMessage()); } }
From source file:com.qtitools.player.client.util.xml.XMLDocument.java
License:Open Source License
/** * Create assessment from xml//from ww w .j a v a2 s . c o m */ public XMLDocument(String url, IDocumentLoaded l) { listener = l; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); baseUrl = url.substring(0, url.lastIndexOf("/") + 1); errorString = null; try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { // Couldn't connect to server (could be timeout, SOP violation, etc.) errorString = "Error" + exception.toString(); } public void onResponseReceived(Request request, Response response) { // StatusCode == 0 when loading from local file try { if (response.getStatusCode() == 200 || response.getStatusCode() == 0) { dom = XMLParser.parse(response.getText()); listener.finishedLoading(dom, baseUrl); } else { // Handle the error. Can get the status text from response.getStatusText() errorString = "Wrong status: " + response.getText(); listener.loadingErrorHandler(errorString); } } catch (Exception e) { listener.loadingErrorHandler(e.getMessage()); } } }); } catch (RequestException e) { // Couldn't connect to server errorString = "Can't connect to the server: " + e.toString(); } catch (DOMException e) { errorString = "Could not parse file: " + url; } if (errorString != null) listener.loadingErrorHandler(errorString); }