List of usage examples for com.google.gwt.jsonp.client JsonpRequestBuilder setTimeout
public void setTimeout(int timeout)
From source file:cc.kune.embed.client.EmbedHelper.java
License:GNU Affero Public License
/** * Process json request.//from w w w . ja va 2 s .c o 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 w w w. j a va 2s. co m*/ * * @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 w w w.ja v a2s . co 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.cgxlib.xq.client.plugins.deferred.PromiseReqBuilderJSONP.java
License:Apache License
public PromiseReqBuilderJSONP(String url, String callbackParam, int timeout) { JsonpRequestBuilder builder = new JsonpRequestBuilder(); if (timeout > 0) { builder.setTimeout(timeout); }/* www . j av a2s. com*/ // jQuery allows a parameter callback=? to figure out the callback parameter if (callbackParam == null) { MatchResult tmp = callbackRegex.exec(url); if (tmp != null && tmp.getGroupCount() == 4) { callbackParam = tmp.getGroup(2); url = tmp.getGroup(1) + tmp.getGroup(3); } } if (callbackParam != null) { builder.setCallbackParam(callbackParam); } send(builder, url, new AsyncCallback<Object>() { public void onFailure(Throwable caught) { dfd.reject(caught); } public void onSuccess(Object result) { dfd.resolve(result); } }); }
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 av a2 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 ww . j ava 2 s . c o m*/ * 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() { /** /*from w w w.j ava 2s. c o m*/ * 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); } }); } } }); }
From source file:com.sharad.quizbowl.ui.client.QuizbowlUI.java
License:Open Source License
public void onModuleLoad() { JsonpRequestBuilder dataGrabber = new JsonpRequestBuilder(); dataGrabber.setTimeout(30000); dataGrabber.requestObject(SERVER_URL + "/data?alt=json-in-script", new AsyncCallback<DataPackage>() { @Override//from w w w . ja v a 2 s . c o m public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); } @Override public void onSuccess(DataPackage result) { YEARS = result.getYears(); TOURNAMENTS = result.getTournaments(); DIFFICULTIES = result.getDifficulties(); CATEGORIES = result.getCategories(); NUM_QUESTIONS = result.getNumQuestions(); NUM_USERS = result.getNumUsers(); NUM_SCORES = result.getNumScores(); for (int i = 0; i < CATEGORIES.length(); i++) { CATEGORIES_LIST.add(CATEGORIES.get(i)); } final HomeWidget home = new HomeWidget(YEARS, TOURNAMENTS, DIFFICULTIES, CATEGORIES); RootLayoutPanel.get().add(home); Timer timer = new Timer() { @Override public void run() { home.search.searchBox.setFocus(true); } }; timer.schedule(400); } }); }
From source file:com.vaadin.client.SuperDevMode.java
License:Apache License
private static void recompileWidgetsetAndStartInDevMode(final String serverUrl) { getLogger()//ww w. ja v a2s . c o m .info("Recompiling widgetset using<br/>" + serverUrl + "<br/>and then reloading in super dev mode"); VNotification n = new VNotification(); n.show("<b>Recompiling widgetset, please wait</b>", VNotification.CENTERED, VNotification.STYLE_SYSTEM); JsonpRequestBuilder b = new JsonpRequestBuilder(); b.setCallbackParam("_callback"); b.setTimeout(COMPILE_TIMEOUT_IN_SECONDS * 1000); b.requestObject( serverUrl + "recompile/" + GWT.getModuleName() + "?" + getRecompileParameters(GWT.getModuleName()), new AsyncCallback<RecompileResult>() { @Override public void onSuccess(RecompileResult result) { getLogger().fine("JSONP compile call successful"); if (!result.ok()) { getLogger().fine("* result: " + result); failed(); return; } setSession(getSuperDevModeHookKey(), getSuperDevWidgetSetUrl(GWT.getModuleName(), serverUrl)); setSession(SKIP_RECOMPILE, "1"); getLogger().fine("* result: OK. Reloading"); Location.reload(); } @Override public void onFailure(Throwable caught) { getLogger().severe("JSONP compile call failed"); // Don't log exception as they are shown as // notifications getLogger().severe(caught.getClass().getSimpleName() + ": " + caught.getMessage()); failed(); } private void failed() { VNotification n = new VNotification(); n.addEventListener(new EventListener() { @Override public void notificationHidden(HideEvent event) { recompileWidgetsetAndStartInDevMode(serverUrl); } }); n.show("Recompilation failed.<br/>" + "Make sure CodeServer is running, " + "check its output and click to retry", VNotification.CENTERED, VNotification.STYLE_SYSTEM); } }); }
From source file:edu.caltech.ipac.firefly.core.JsonUtils.java
public static <T extends JavaScriptObject> void jsonpRequest(String baseUrl, String cmd, List<Param> paramList, AsyncCallback<T> cb) {//w w w . j a va2 s . c om String url = makeURL(baseUrl, cmd, paramList, true); JsonpRequestBuilder builder = new JsonpRequestBuilder(); builder.setTimeout(TIMEOUT); builder.requestObject(url, cb); }