List of usage examples for com.google.gwt.jsonp.client JsonpRequestBuilder setCallbackParam
public void setCallbackParam(String callbackParam)
From source file:cl.uai.client.data.AjaxRequest.java
License:Open Source License
/** * Performs a request to Moodle/* ww w . j a v a2 s . c o 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//w w w. ja va 2 s . c om * * @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);//ww w. j a v a 2 s . c o m } // 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.ghusse.dolomite.flickr.Request.java
License:Open Source License
/** * Sends an unsigned request.//from www . ja v a 2s. c o m * @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.vaadin.client.SuperDevMode.java
License:Apache License
private static void recompileWidgetsetAndStartInDevMode(final String serverUrl) { getLogger()//from ww w.ja v a 2s .c om .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:gov.wa.wsdot.search.client.SearchWidget.java
License:Open Source License
/** * Make call to remote Flickr server//ww w . ja va 2 s .c o m * @param query * @param url_flickr */ private static void getPhotoData(String url, final String query) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setCallbackParam("jsoncallback"); jsonp.requestObject(url, new AsyncCallback<Photos>() { @Override public void onFailure(Throwable caught) { // Just fail silently here. } @Override public void onSuccess(Photos photos) { if (photos.getPhotos().getPhoto() != null) { updatePhotoResults(photos, query); } } }); }
From source file:org.oscim.web.client.SearchBox.java
License:Open Source License
public SearchBox(final Map map) { final Button searchButton = new Button("Search"); final TextBox searchField = new TextBox(); //searchField.setText("Bremen"); final PathLayer mOverlay = new PathLayer(map, 0xCC0000FF); map.layers().add(mOverlay);/* ww w . java 2 s . c om*/ // We can add style names to widgets searchButton.addStyleName("sendButton"); RootPanel.get("nameFieldContainer").add(searchField); RootPanel.get("sendButtonContainer").add(searchButton); // Focus the cursor on the name field when the app loads searchField.setFocus(true); searchField.selectAll(); // Create a cell to render each value in the list. PoiCell poiCell = new PoiCell(); // Create a CellList that uses the cell. final CellList<PoiData> cellList = new CellList<PoiData>(poiCell, PoiData.KEY_PROVIDER); final SingleSelectionModel<PoiData> selectionModel = new SingleSelectionModel<PoiData>( PoiData.KEY_PROVIDER); cellList.setSelectionModel(selectionModel); final ScrollPanel scroller = new ScrollPanel(cellList); RootPanel.get("listContainer").add(scroller); scroller.setSize("350px", "300px"); RootPanel.get("search").getElement().getStyle().setVisibility(Visibility.VISIBLE); scroller.setVisible(false); searchField.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { scroller.setVisible(true); } }); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { final PoiData d = selectionModel.getSelectedObject(); mOverlay.clearPath(); //log.debug("selected " + d.getName() + " " + d.getLatitude() + " " // + d.getLongitude()); BoundingBox b = d.getBoundingBox(); if (b != null) { if (b.maxLatitudeE6 - b.minLatitudeE6 < 100 && b.maxLongitudeE6 - b.minLongitudeE6 < 100) // for small bbox use zoom=16 to get an overview map.animator().animateTo(500, b.getCenterPoint(), 1 << 16, false); else map.animator().animateTo(b); if (d instanceof NominatimData && ((NominatimData) d).getWkt() != null) { String wkt = ((NominatimData) d).getWkt(); WKTReader r = new WKTReader(); GeometryBuffer g = new GeometryBuffer(1024, 10); try { r.parse(wkt, g); } catch (Exception e) { log.debug(wkt); } //FIXME mOverlay.setGeom(g); //log.debug("add polygon " + p.length()); } else { mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6); mOverlay.addPoint(b.maxLatitudeE6, b.maxLongitudeE6); mOverlay.addPoint(b.minLatitudeE6, b.maxLongitudeE6); mOverlay.addPoint(b.minLatitudeE6, b.minLongitudeE6); mOverlay.addPoint(b.maxLatitudeE6, b.minLongitudeE6); } // hide overlay after 5 seconds map.postDelayed(new Runnable() { @Override public void run() { mOverlay.clearPath(); } }, 5000); } else { MapPosition pos = new MapPosition(); map.viewport().setTilt(0); map.viewport().setRotation(0); pos.setZoomLevel(13); pos.setPosition(d.getLatitude(), d.getLongitude()); map.setMapPosition(pos); } scroller.setVisible(false); } }); // Create a handler for the sendButton and nameField class MyHandler implements ClickHandler, KeyUpHandler { /** * Fired when the user clicks on the sendButton. */ public void onClick(ClickEvent event) { sendRequest(); } /** * Fired when the user types in the nameField. */ public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { sendRequest(); } } /** * Send the name from the nameField to the server and wait for a * response. */ private void sendRequest() { String textToServer = searchField.getText(); searchButton.setEnabled(false); String url = URL.encode(NOMINATIM_GLOBAL + textToServer); JsonpRequestBuilder builder = new JsonpRequestBuilder(); builder.setCallbackParam("json_callback"); builder.requestObject(url, new AsyncCallback<JsArray<NominatimData>>() { public void onFailure(Throwable caught) { log.debug("request failed"); searchButton.setEnabled(true); } public void onSuccess(JsArray<NominatimData> data) { List<PoiData> items = new ArrayList<PoiData>(); for (int i = 0, n = data.length(); i < n; i++) { NominatimData d = data.get(i); items.add(d); } cellList.setRowCount(items.size(), true); cellList.setRowData(0, items); scroller.setVisible(true); searchButton.setEnabled(true); } }); } } // Add a handler to send the name to the server MyHandler handler = new MyHandler(); searchButton.addClickHandler(handler); searchField.addKeyUpHandler(handler); }