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:org.dataconservancy.dcs.access.ui.client.Application.java
License:Apache License
private void viewEntity(String id) { String entityurl = id;/*w ww . ja va 2 s. c om*/ if (!entityurl.startsWith(accessurl)) { Window.alert("Cannot view external entity: " + id); return; } JsonpRequestBuilder rb = new JsonpRequestBuilder(); rb.requestObject(entityurl, new AsyncCallback<JsDcp>() { public void onFailure(Throwable caught) { reportInternalError("Viewing entity", caught); } public void onSuccess(JsDcp result) { displayEntity(result); } }); }
From source file:org.dataconservancy.dcs.access.ui.client.Application.java
License:Apache License
private void viewSearch(final Search.UserField[] userfields, final String[] userqueries, int offset, final String searchtokenprefix) { content.clear();// ww w . j ava 2 s .c o m if (userfields == null || userqueries == null) { content.add(createAdvancedSearchWidget(userfields, userqueries)); return; } String query = Search.createQuery(userfields, userqueries); // content.add(new Label(query)); JsonpRequestBuilder rb = new JsonpRequestBuilder(); String searchurl = searchURL(query, offset, true, MAX_SEARCH_RESULTS); content.add(createAdvancedSearchWidget(userfields, userqueries)); rb.requestObject(searchurl, new AsyncCallback<JsSearchResult>() { public void onFailure(Throwable caught) { reportInternalError("Searching", caught); } public void onSuccess(JsSearchResult result) { displaySearchResults(content, searchtokenprefix, result); } }); }
From source file:org.dataconservancy.dcs.access.ui.client.Application.java
License:Apache License
private void collectSearchResults(final String query, final int offset, final JsDcp dcp, final AsyncCallback<JsDcp> topcb) { String searchurl = searchURL(query, offset, false, 50); JsonpRequestBuilder rb = new JsonpRequestBuilder(); rb.requestObject(searchurl, new AsyncCallback<JsSearchResult>() { public void onFailure(Throwable caught) { topcb.onFailure(caught);/* w w w.ja v a2s . c o m*/ } public void onSuccess(JsSearchResult result) { for (int i = 0; i < result.matches().length(); i++) { Util.add(dcp, result.matches().get(i)); } int nextoffset = offset + result.matches().length(); if (nextoffset == result.total()) { topcb.onSuccess(dcp); } else { collectSearchResults(query, nextoffset, dcp, topcb); } } }); }
From source file:org.gwtnode.examples.features.feature.JsonpFeature.java
License:Apache License
@Override public void call() { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.requestObject(URL, new AsyncCallback<JavaScriptObject>() { @Override/*from w ww . ja v a2 s.c o m*/ public void onFailure(Throwable caught) { process.stdout().write("JSONP request failed: " + caught); } @Override public void onSuccess(JavaScriptObject result) { process.stdout().write("JSONP request succeeded: " + util.inspect(result)); } }); }
From source file:org.openremote.web.console.service.JSONPControllerConnector.java
License:Open Source License
private void doJsonpRequest(String url, JSONPControllerCallback callback, Integer timeout) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); if (timeout != null) { jsonp.setTimeout(timeout);/* w w w .j a v a 2s . c o m*/ } jsonp.requestObject(url, callback); }
From source file:org.oscim.tiling.source.JsonTileDataSource.java
License:Open Source License
void doGet(final String url) { JsonpRequestBuilder builder = new JsonpRequestBuilder(); //builder.setCallbackParam("json_callback"); mRequestHandle = builder.requestObject(url, new AsyncCallback<JavaScriptObject>() { public void onFailure(Throwable caught) { mSink.completed(FAILED);/*from w ww . jav a 2 s .c om*/ log.debug("fail! {} {}", mRequestHandle, caught.getMessage()); //mRequestHandle.cancel(); } public void onSuccess(JavaScriptObject jso) { if (mTile.state(State.NONE)) { log.debug("tile cleared {}", url); mSink.completed(FAILED); return; } if (jso == null) { log.debug("Couldn't retrieve JSON for {}", url); mSink.completed(FAILED); return; } try { if (mTileDecoder.decode(mTile, mSink, jso)) { mSink.completed(SUCCESS); return; } } catch (Exception e) { log.debug("Couldn't retrieve JSON for {} {}" + url, e); // FIXME need to check where it might be thrown mSink.completed(FAILED); } } }); }
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);/*from w w w. j av a 2s . c o m*/ // 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); }
From source file:org.simbit.gwt.labyrinth.provider.rest.restlet.RestletRestImpl.java
License:Apache License
public void getJsonXss(String url, final AsyncCallback<JSONObject> callback) { JsonpRequestBuilder builder = new JsonpRequestBuilder(); builder.requestObject(url, new AsyncCallback<JavaScriptObject>() { public void onSuccess(JavaScriptObject response) { callback.onSuccess(new JSONObject(response)); }/*from w w w . ja v a 2s . c om*/ public void onFailure(Throwable caught) { callback.onFailure(caught); } }); }
From source file:org.thechiselgroup.biomixer.client.workbench.util.url.JsonpUrlFetchService.java
License:Apache License
/** * This is primarily used by the {@link RetryAsyncCallbackErrorHandler} that * this uses internally./*ww w .j a v a2 s.c o m*/ * * @param url * @param callback * @param previousNumberTries */ public void fetchURL(final String url, final AsyncCallback<String> callback, int previousNumberTries) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Could change timeout, but probably better to change retry attempt // number...except that exacerbates server load. Maybe longer timeout is // ok. jsonp.setTimeout(jsonp.getTimeout() * 4); jsonp.requestObject(url, new ErrorHandlingAsyncCallback<JavaScriptObject>( new RetryAsyncCallbackErrorHandler(callback, url, previousNumberTries, this)) { @Override protected void runOnSuccess(JavaScriptObject result) throws Exception { // Had trouble with injection...explicitly creating // instead. ErrorCodeJSONParser errorCodeParser = new ErrorCodeJSONParser(new JsJsonParser()); JSONObject jsonObject = new JSONObject(result); // This JSONObect method changes what appear to be // array entries to be string-integer indexed property // entries. // This happens when an array is presented without // explicit numeric indices. String jsonString = jsonObject.toString(); // Need to check for understood errors in response, such // as 403 forbidden. Integer errorCode = errorCodeParser.parse(jsonString); if (null != errorCode && 500 == errorCode) { // 500 errors don't get here! Caught lower down? // We can retry this once, since I have already seen // cases of very singular failures here. boolean retryAttempted = ((RetryAsyncCallbackErrorHandler) callback).manualRetry(); if (retryAttempted) { return; } // else if (403 == errorCode) { // // This error code, forbidden, is something I // want // // to ignore at the moment. // return; // } } else { // if (null == errorCode) { callback.onSuccess(jsonString); return; } // This wasn't a success, and we got an error code // we don't understand. // Treat as an error for the callback. callback.onFailure(new Exception("Error code, status: " + errorCode + ".")); throw new Exception("Status " + errorCode); } }); }
From source file:tigase.jaxmpp.gwt.client.dns.WebDnsResolver.java
License:Open Source License
private void resolveDomain(String domain, com.google.gwt.user.client.rpc.AsyncCallback<DnsResult> callback) { String url = getResolverUrl(); // adding parameters for resolver to process url += "?version=2"; url += "&domain=" + URL.encodeQueryString(domain); JsonpRequestBuilder builder = new JsonpRequestBuilder(); builder.requestObject(url, callback); }