Example usage for com.google.gwt.jsonp.client JsonpRequestBuilder JsonpRequestBuilder

List of usage examples for com.google.gwt.jsonp.client JsonpRequestBuilder JsonpRequestBuilder

Introduction

In this page you can find the example usage for com.google.gwt.jsonp.client JsonpRequestBuilder JsonpRequestBuilder.

Prototype

JsonpRequestBuilder

Source Link

Usage

From source file:com.imaginedreal.mgwt.trafficflow.client.activities.seattle.SeattleActivity.java

License:Apache License

private void getFlowData() {

    /** /*from  w w w .ja  va2  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   ww w.j  a  v a  2  s .co  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.seanchenxi.gwt.wordpress.json.core.request.JRequestBuilderCSImpl.java

License:Apache License

public JRequestBuilderCSImpl() {
    builder = new JsonpRequestBuilder();
}

From source file:com.sencha.gxt.data.client.loader.ScriptTagProxy.java

License:sencha.com license

public void load(C loadConfig, final Callback<JavaScriptObject, Throwable> callback) {
    String prepend = url.indexOf("?") != -1 ? "&" : "?";
    String u = url + prepend + generateUrl(loadConfig);

    JsonpRequestBuilder b = new JsonpRequestBuilder();
    b.requestObject(u, new AsyncCallback<JavaScriptObject>() {
        @Override/*from  w w  w  .  ja va 2 s . c om*/
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(JavaScriptObject result) {
            callback.onSuccess(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);/*  ww w  . j  a  v  a 2  s.  co m*/
    dataGrabber.requestObject(SERVER_URL + "/data?alt=json-in-script", new AsyncCallback<DataPackage>() {

        @Override
        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()//from  ww w  .j  a v a 2  s .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) {//from w ww .  j  a v a2 s .  com
    String url = makeURL(baseUrl, cmd, paramList, true);
    JsonpRequestBuilder builder = new JsonpRequestBuilder();
    builder.setTimeout(TIMEOUT);
    builder.requestObject(url, cb);
}

From source file:fr.mncc.gwttoolbox.rpc.client.requests.RestCall.java

License:Open Source License

/**
 * Send a request using the JSONP mechanism
 * //  ww w .  ja  v  a  2  s.c  om
 * @param url
 * @param callback on success, returns a GWT javascript object
 */
public static <T extends JavaScriptObject> void retry(final String url, final AsyncCallback<T> callback) {
    final JsonpRequestBuilder rb = new JsonpRequestBuilder();
    rb.requestObject(url, new AsyncCallback<T>() {
        @Override
        public void onFailure(final Throwable caught) {
            if (callback != null)
                callback.onFailure(caught);
        }

        @Override
        public void onSuccess(final T feed) {
            if (callback != null)
                callback.onSuccess(feed);
        }
    });
}

From source file:gov.wa.wsdot.apps.analytics.client.activities.twitter.AnalyticsViewImpl.java

License:Open Source License

private void getStartDate() {

    String url = Consts.HOST_URL + "/summary/startTime";

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    // Set timeout for 30 seconds (30000 milliseconds)
    jsonp.setTimeout(30000);//from   w w  w  .j a v  a  2s . c  o  m
    jsonp.requestObject(url, new AsyncCallback<TweetTimes>() {

        @Override
        public void onFailure(Throwable caught) {
            Window.alert("Failure: " + caught.getMessage());
        }

        @Override
        public void onSuccess(TweetTimes result) {
            // Fire SetDateEvent to change date picker to default date from server
            DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
            Date startDate = dateTimeFormat.parse(result.getStartDate());
            Date endDate = dateTimeFormat.parse(result.getEndDate());

            presenter.getEventBus().fireEvent(new SetDateEvent(startDate, endDate));

        }
    });
}

From source file:gov.wa.wsdot.apps.analytics.client.activities.twitter.view.ranking.RankingView.java

License:Open Source License

public static void getRetweets(String account, Date start, Date end, final MaterialCollection list,
        final String listType) {

    list.clear();//w ww. j a v a2s .co m

    DateTimeFormat fmt = DateTimeFormat.getFormat("/yyyy/M/d");
    String startDate = fmt.format(start);
    String endDate = fmt.format(end);
    String screenName = account;

    String url = Consts.HOST_URL + "/summary/statuses/retweets/" + listType + "/" + screenName + startDate
            + endDate;

    loader.setVisible(true);

    JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
    // Set timeout for 30 seconds (30000 milliseconds)
    jsonp.setTimeout(30000);
    jsonp.requestObject(url, new AsyncCallback<Mention>() {

        @Override
        public void onFailure(Throwable caught) {
            Window.alert("Failure: " + caught.getMessage());
            loader.setVisible(false);
        }

        @Override
        public void onSuccess(Mention mention) {
            if (mention.getMentions() != null) {
                list.clear();
                updateRetweetList(mention.getMentions(), list, listType);
                loader.setVisible(false);
            }
        }
    });
}