List of usage examples for com.google.gwt.jsonp.client JsonpRequestBuilder requestObject
public <T extends JavaScriptObject> JsonpRequest<T> requestObject(String url, AsyncCallback<T> callback)
From source file:cc.kune.embed.client.EmbedHelper.java
License:GNU Affero Public License
/** * Process json request./* w ww .j a v a 2 s. co m*/ * * @param url * the url * @param callback * the callback */ public static void processJSONRequest(final String url, final Callback<JavaScriptObject, Void> callback) { final JsonpRequestBuilder builder = new JsonpRequestBuilder(); builder.setTimeout(60000); @SuppressWarnings("unused") final JsonpRequest<JavaScriptObject> request = builder.requestObject(url, new AsyncCallback<JavaScriptObject>() { @Override public void onFailure(final Throwable exception) { Log.error("JSON exception: ", exception); callback.onFailure(null); } @Override public void onSuccess(final JavaScriptObject result) { callback.onSuccess(result); } }); }
From source file:cl.uai.client.data.AjaxRequest.java
License:Open Source License
/** * Performs a request to Moodle/*from ww w. ja v a 2 s. c om*/ * * @param params * @param callback */ public static void ajaxRequest(String params, AsyncCallback<AjaxData> callback) { final String url = EMarkingConfiguration.getMoodleUrl() + "?ids=" + MarkingInterface.getDraftId() + "&" + params; logger.fine(url); JsonpRequestBuilder requestBuilder = new JsonpRequestBuilder(); requestBuilder.setTimeout(30000); requestBuilder.setCallbackParam("callback"); requestBuilder.requestObject(url, callback); }
From source file:cl.webcursos.salas.client.AjaxRequest.java
License:Open Source License
/** * Performs a request to Moodle/*from ww w. ja v a 2 s . c o m*/ * * @param params * @param callback */ public static void ajaxRequest(String params, AsyncCallback<AjaxData> callback) { final String url = moodleUrl + "?" + params; logger.fine(url); JsonpRequestBuilder requestBuilder = new JsonpRequestBuilder(); requestBuilder.setTimeout(30000); requestBuilder.setCallbackParam("callback"); requestBuilder.requestObject(url, callback); }
From source file:com.dawg6.web.dhcalc.client.Service.java
License:Open Source License
public void httpRequest(String url, final AsyncCallback<String> handler) { try {// w w w. j av a2s . c o m JsonpRequestBuilder builder = new JsonpRequestBuilder(); builder.requestObject(url, new AsyncCallback<JavaScriptObject>() { @Override public void onFailure(Throwable caught) { handler.onFailure(caught); } @Override public void onSuccess(JavaScriptObject result) { JSONObject json = new JSONObject(result); handler.onSuccess(json.toString()); } }); } catch (RuntimeException e) { handler.onFailure(e); } catch (Exception e) { handler.onFailure(e); } }
From source file:com.emitrom.gwt4.touch2.demo.client.views.data.jsonp.JsonPViewImpl.java
License:Open Source License
private void addListeners() { final String url = "http://free.worldweatheronline.com/feed/weather.ashx" + "?key=23f6a0ab24185952101705" + "&q=94301" + "&format=json" + "&num_of_days=5"; button.addTapHandler(new TapHandler() { @Override//from w ww. j ava2 s . c o m public void onTap(Button button, EventObject event) { loadmask.show(); /** * Typically called in the presenter. We are keeping it here so * we can show how to retrieve the data. */ JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.requestObject(url, new AsyncCallback<JavaScriptObject>() { @Override public void onFailure(Throwable caught) { loadmask.hide(); MessageBox.alert(caught.getMessage()); } @Override public void onSuccess(JavaScriptObject result) { loadmask.hide(); setHtml(new JSONObject(result).toString()); } }); } }); }
From source file:com.ghusse.dolomite.flickr.Request.java
License:Open Source License
/** * Sends an unsigned request./*ww w. j ava 2s . c om*/ * @param callback Callback object. * @param args Request arguments. */ protected void sendUnsignedRequest(final AsyncCallback<T> callback, final Map<String, String> args) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setCallbackParam("jsoncallback"); boolean first = true; StringBuilder uri = new StringBuilder(API_URL); for (Map.Entry<String, String> entry : args.entrySet()) { uri.append(first ? "?" : "&"); first = false; uri.append(entry.getKey()); uri.append("="); uri.append(entry.getValue()); } jsonp.requestObject(uri.toString(), new AsyncCallback<T>() { @Override public void onFailure(final Throwable caught) { callback.onFailure(caught); } @Override public void onSuccess(final T result) { if (result == null) { callback.onFailure(new NullResultException()); } else if (!result.getStatus()) { callback.onFailure(new FlickrException(result.getCode(), new JSONObject(result).toString())); } else { callback.onSuccess(result); } } }); }
From source file:com.gwtmobile.ui.kitchensink.client.communication.JsonpPage.java
License:Apache License
private void makeJsonpCall() { String url = "http://gwtmobile-services.appspot.com/jsonp"; JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.requestObject(url, new AsyncCallback<Hello>() { @Override//from www .j a v a 2s.c o m public void onFailure(Throwable throwable) { text.setHTML("Error: " + throwable); } @Override public void onSuccess(Hello hello) { text.setHTML(hello.world()); } }); }
From source file:com.imaginedreal.gwt.palantir.client.activities.search.SearchActivity.java
License:Apache License
@Override public void onSearchTextChanged(String filter) { String url = TITLE_SEARCH_URL + UriUtils.encode(filter) + "/page/1/limit/5"; view.showProgressIndicator();//from w w w .j ava 2 s .c om JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setTimeout(30000); // Set timeout for 30 seconds jsonp.requestObject(url, new AsyncCallback<BookJso>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); } @Override public void onSuccess(BookJso result) { if (result.getBookShare() != null) { books.clear(); Book book; int numBooks = result.getBookShare().getBook().getList().getResult().length(); for (int i = 0; i < numBooks; i++) { book = new Book(); book.setTitle(result.getBookShare().getBook().getList().getResult().get(i).getTitle()); book.setBriefSynopsis( result.getBookShare().getBook().getList().getResult().get(i).getBriefSynopsis()); String isbn = result.getBookShare().getBook().getList().getResult().get(i).getIsbn13(); book.setIsbn13(isbn); book.setBookCoverUrl("http://covers.openlibrary.org/b/isbn/" + isbn + "-M.jpg"); books.add(book); } } view.hideProgressIndicator(); view.render(books); view.refresh(); } }); }
From source file:com.imaginedreal.mgwt.trafficflow.client.activities.seattle.SeattleActivity.java
License:Apache License
private void getFlowData() { /** /* w w w.ja v a 2s . com*/ * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.STATIONS, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { String currentMap = localStorage.getItem("KEY_CURRENT_MAP"); boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (3 * 60000)); // Refresh every 3 minutes. } view.showProgressIndicator(); if (!currentMap.equalsIgnoreCase("seattle")) { shouldUpdate = true; localStorage.setItem("KEY_CURRENT_MAP", "seattle"); } if (shouldUpdate) { try { String url = Consts.HOST_URL + "/api/flowdata/MinuteDataNW"; JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setTimeout(30000); // 30 seconds jsonp.requestObject(url, new AsyncCallback<FlowDataFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); GWT.log("Failure calling traffic flow api."); } @Override public void onSuccess(FlowDataFeed result) { stationItems.clear(); if (result.getFlowData() != null) { int numStations = result.getFlowData().getStations().length(); String timestamp = result.getFlowData().getTimestamp(); timestamp = timestamp.replaceAll("PST|PDT", ""); Date date = parseDateFormat.parse(timestamp); String lastUpdated = displayDateFormat.format(date); localStorage.setItem("KEY_LAST_UPDATED", lastUpdated); StationItem item; for (int i = 0; i < numStations; i++) { String stationId = result.getFlowData().getStations().get(i).getId(); String status = result.getFlowData().getStations().get(i).getStat(); if (stationItemsMap.containsKey(stationId) && status.equalsIgnoreCase("good")) { item = new StationItem(); item.setId(stationId); item.setVolume(result.getFlowData().getStations().get(i).getVol()); item.setSpeed(result.getFlowData().getStations().get(i).getSpd()); item.setOccupancy(result.getFlowData().getStations().get(i).getOcc()); stationItems.add(item); } } } // Purge existing stations covered by incoming data dbService.deleteStations(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new stations and data. dbService.insertStations(stationItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { view.hideProgressIndicator(); } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add( new CacheItem(Tables.STATIONS, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Get all the stations and data just inserted. dbService.getStations(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getStations(result); } }); } }); } }); } }); } }); } catch (Exception e) { // TODO Do something with the exception } } else { dbService.getStations(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getStations(result); } }); } } }); }
From source file:com.imaginedreal.mgwt.trafficflow.client.activities.tacoma.TacomaActivity.java
License:Apache License
private void getFlowData() { /** // w ww . ja v a2 s .c om * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.STATIONS, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { String currentMap = localStorage.getItem("KEY_CURRENT_MAP"); boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (3 * 60000)); // Refresh every 3 minutes. } view.showProgressIndicator(); if (!currentMap.equalsIgnoreCase("tacoma")) { shouldUpdate = true; localStorage.setItem("KEY_CURRENT_MAP", "tacoma"); } if (shouldUpdate) { try { String url = Consts.HOST_URL + "/api/flowdata/MinuteDataOR"; JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setTimeout(30000); // 30 seconds jsonp.requestObject(url, new AsyncCallback<FlowDataFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); GWT.log("Failure calling traffic flow api."); } @Override public void onSuccess(FlowDataFeed result) { stationItems.clear(); if (result.getFlowData() != null) { int numStations = result.getFlowData().getStations().length(); String timestamp = result.getFlowData().getTimestamp(); timestamp = timestamp.replaceAll("PST|PDT", ""); Date date = parseDateFormat.parse(timestamp); String lastUpdated = displayDateFormat.format(date); localStorage.setItem("KEY_LAST_UPDATED", lastUpdated); StationItem item; for (int i = 0; i < numStations; i++) { String stationId = result.getFlowData().getStations().get(i).getId(); String status = result.getFlowData().getStations().get(i).getStat(); if (stationItemsMap.containsKey(stationId) && status.equalsIgnoreCase("good")) { item = new StationItem(); item.setId(stationId); item.setVolume(result.getFlowData().getStations().get(i).getVol()); item.setSpeed(result.getFlowData().getStations().get(i).getSpd()); item.setOccupancy(result.getFlowData().getStations().get(i).getOcc()); stationItems.add(item); } } } // Purge existing stations covered by incoming data dbService.deleteStations(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new stations and data. dbService.insertStations(stationItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { view.hideProgressIndicator(); } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add( new CacheItem(Tables.STATIONS, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Get all the stations and data just inserted. dbService.getStations(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getStations(result); } }); } }); } }); } }); } }); } catch (Exception e) { view.hideProgressIndicator(); } } else { dbService.getStations(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getStations(result); } }); } } }); }