List of usage examples for com.google.gwt.http.client RequestBuilder GET
Method GET
To view the source code for com.google.gwt.http.client RequestBuilder GET.
Click Source Link
From source file:ca.upei.ic.timetable.client.Remote.java
License:Apache License
/** * Calls a remote method using HTTP GET// ww w .j av a 2 s.c o m * * @param method * @param params * @param callback */ public Request get(String method, Map<String, String> params, RequestCallback callback) { // build the query StringBuffer q = new StringBuffer(); q.append("?method=" + method); if (null != params) { for (String key : params.keySet()) { q.append("&" + key + "=" + params.get(key)); } } // build the request builder RequestBuilder req = new RequestBuilder(RequestBuilder.GET, url_ + q); req.setRequestData(""); req.setCallback(callback); Request request = null; try { request = req.send(); } catch (RequestException re) { callback.onError(request, re); } return request; }
From source file:cc.kune.core.client.actions.xml.XMLActionsParser.java
License:GNU Affero Public License
/** * Instantiates a new xML actions parser. * * @param errHandler/*from w w w .j a v a 2s. com*/ * the err handler * @param contentViewer * the content viewer * @param actionRegistry * the action registry * @param contentService * the content service * @param session * the session * @param stateManager * the state manager * @param i18n * the i18n * @param newMenusRegistry * the new menus registry * @param services * the services */ @Inject public XMLActionsParser(final ErrorHandler errHandler, final ContentViewerPresenter contentViewer, final ActionRegistryByType actionRegistry, final Provider<ContentServiceAsync> contentService, final Session session, final StateManager stateManager, final I18nTranslationService i18n, final NewMenusForTypeIdsRegistry newMenusRegistry, final Services services) { this.errHandler = errHandler; this.contentViewer = contentViewer; this.actionRegistry = actionRegistry; this.contentService = contentService; this.session = session; this.stateManager = stateManager; this.i18n = i18n; this.newMenusRegistry = newMenusRegistry; submenus = new HashMap<String, SubMenuDescriptor>(); // Based on: // http://www.roseindia.net/tutorials/gwt/retrieving-xml-data.shtml final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, XMLActionsConstants.ACTIONS_XML_LOCATION_PATH_ABS); session.onAppStart(false, new AppStartHandler() { @Override public void onAppStart(final AppStartEvent event) { try { requestBuilder.sendRequest(null, new RequestCallback() { @Override public void onError(final Request request, final Throwable ex) { onFailed(ex); } @Override public void onResponseReceived(final Request request, final Response response) { parse(new XMLKuneClientActions(services, response.getText())); } }); } catch (final RequestException ex) { onFailed(ex); } } }); }
From source file:cc.kune.core.client.auth.WaveClientSimpleAuthenticator.java
License:GNU Affero Public License
/** * Do logout.// w w w.j a v a2s.co m * * @param callback * the callback */ public void doLogout(final AsyncCallback<Void> callback) { // Original: <a href=\"/auth/signout?r=/\">" final RequestBuilder request = new RequestBuilder(RequestBuilder.GET, "/auth/signout"); try { request.setHeader("Content-Type", "application/x-www-form-urlencoded"); final StringBuffer params = new StringBuffer(); request.sendRequest(params.toString(), new RequestCallback() { @Override public void onError(final Request request, final Throwable exception) { StackErrorEvent.fire(eventBus, exception); callback.onFailure(exception); } @Override public void onResponseReceived(final Request request, final Response response) { callback.onSuccess(null); } }); } catch (final RequestException e) { StackErrorEvent.fire(eventBus, e); } }
From source file:cc.kune.core.client.sitebar.search.MultivalueSuggestBox.java
License:GNU Affero Public License
/** * Retrieve Options (name-value pairs) that are suggested from the REST * endpoint//from www. ja va 2 s.c o m * * @param query * - the String search term * @param from * - the 0-based begin index int * @param to * - the end index inclusive int * @param callback * - the OptionQueryCallback to handle the response */ private void queryOptions(final String query, final int from, final int to, final OptionQueryCallback callback) { final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(mrestEndpointUrl + "?" + SearcherConstants.QUERY_PARAM + "=" + query + "&" + SearcherConstants.START_PARAM + "=" + from + "&" + SearcherConstants.LIMIT_PARAM + "=" + PAGE_SIZE)); // Set our headers builder.setHeader("Accept", "application/json; charset=utf-8"); // Fails on chrome // builder.setHeader("Accept-Charset", "UTF-8"); builder.setCallback(new RequestCallback() { @Override public void onError(final com.google.gwt.http.client.Request request, final Throwable exception) { callback.error(exception); } @Override public void onResponseReceived(final com.google.gwt.http.client.Request request, final Response response) { final JSONValue val = JSONParser.parse(response.getText()); final JSONObject obj = val.isObject(); final int totSize = (int) obj.get(OptionResultSet.TOTAL_SIZE).isNumber().doubleValue(); final OptionResultSet options = new OptionResultSet(totSize); final JSONArray optionsArray = obj.get(OptionResultSet.OPTIONS).isArray(); if (options.getTotalSize() > 0 && optionsArray != null) { for (int i = 0; i < optionsArray.size(); i++) { if (optionsArray.get(i) == null) { /* * This happens when a JSON array has an invalid trailing comma */ continue; } final JSONObject jsonOpt = optionsArray.get(i).isObject(); final Option option = new Option(); final String longName = jsonOpt.get(OptionResultSet.DISPLAY_NAME).isString().stringValue(); final String shortName = jsonOpt.get(OptionResultSet.VALUE).isString().stringValue(); final JSONValue groupTypeJsonValue = jsonOpt.get("groupType"); final String prefix = groupTypeJsonValue.isString() == null ? "" : GroupType.PERSONAL.name().equals(groupTypeJsonValue.isString().stringValue()) ? I18n.t("User") + ": " : I18n.t("Group") + ": "; option.setName(prefix + (!longName.equals(shortName) ? longName + " (" + shortName + ")" : shortName)); option.setValue(jsonOpt.get(OptionResultSet.VALUE).isString().stringValue()); options.addOption(option); } } callback.success(options); } }); try { if (lastQuery != null && lastQuery.isPending()) { lastQuery.cancel(); } lastQuery = builder.send(); } catch (final RequestException e) { updateFormFeedback(FormFeedback.ERROR, "Error: " + e.getMessage()); } }
From source file:cc.kune.embed.client.EmbedHelper.java
License:GNU Affero Public License
/** * Process request.// w ww .j a v a 2 s . co m * * @param url * the url * @param callback * the callback */ public static void processRequest(final String url, final Callback<Response, Void> callback) { try { final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); // Needed for CORS builder.setIncludeCredentials(true); @SuppressWarnings("unused") final Request request = builder.sendRequest(null, new RequestCallback() { @Override public void onError(final Request request, final Throwable exception) { Log.error("CORS exception: ", exception); callback.onFailure(null); } @Override public void onResponseReceived(final Request request, final Response response) { if (200 == response.getStatusCode()) { callback.onSuccess(response); } else { Log.error("Couldn't retrieve CORS (" + response.getStatusText() + ")"); callback.onFailure(null); } } }); } catch (final RequestException exception) { Log.error("CORS exception: ", exception); callback.onFailure(null); } }
From source file:ccc.client.gwt.core.GWTRequestExecutor.java
License:Open Source License
private Method getMethod(final HttpMethod method) { switch (method) { case GET:/*from w ww . j av a2s. c o m*/ return RequestBuilder.GET; case POST: return RequestBuilder.POST; case PUT: return RequestBuilder.POST; case DELETE: return RequestBuilder.POST; default: throw new IllegalArgumentException("Unsupported HTTP method: " + method); } }
From source file:ch.sebastienzurfluh.swissmuseum.core.client.model.io.CakeConnector.java
License:Open Source License
private <T> void asyncRequest(final Requests request, final int referenceId, String args, final AsyncCallback<T> callback) { final StringBuilder url = new StringBuilder(cakePath + request.getURL()); url.append(CAKE_ARGS_SEPARATOR).append(args); url.append(CAKE_ARGS_SEPARATOR).append(referenceId); url.append(CAKE_SUFFIX);/*from w w w. j a va2 s. c o m*/ System.out.println("Making async request on " + url); RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url.toString()); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request httpRequest, Throwable exception) { System.out.println("JSON request failure. " + exception.getLocalizedMessage()); // we do nothing else than log callback.onFailure(exception); } @SuppressWarnings("unchecked") public void onResponseReceived(Request httpRequest, Response response) { if (200 == response.getStatusCode()) { System.out.println("Got answer from async request."); JsArray<Entry> entries = evalJson(response.getText().trim()); // BLACKBOX!!! DataType dataType = DataType.PAGE; switch (request) { case GETALLGROUPMENUS: dataType = DataType.GROUP; case GETALLPAGEMENUSFROMGROUP: // menu collection LinkedList<MenuData> dataList = new LinkedList<MenuData>(); for (int i = 0; i < entries.length(); i++) { Entry entry = entries.get(i); dataList.add(parseMenuData(entry, referenceId, dataType)); } // give callback callback.onSuccess((T) dataList); break; case GETDATA: case GETFIRSTDATAOFGROUP: // single data Data parsedData = parseData(entries.get(0), referenceId, DataType.PAGE); callback.onSuccess((T) parsedData); break; case GETRESOURCE: ResourceData parsedData2 = parseResourceData(entries.get(0), referenceId); callback.onSuccess((T) parsedData2); } } } }); } catch (Exception e) { callback.onFailure(e); } }
From source file:ch.sebastienzurfluh.swissmuseum.parcours.client.model.SimpleCakeBridge.java
License:Open Source License
public <ResponseType extends JavaScriptObject> void sendRequest(String requestString, final WithResult<ResponseType> withResult) { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, cakePath + CAKE_ARGS_SEPARATOR + requestString + CAKE_SUFFIX); try {/*from w w w . j a va 2 s . c om*/ builder.sendRequest(null, new RequestCallback() { public void onError(Request httpRequest, Throwable exception) { System.out.println("JSON request failure. " + exception.getLocalizedMessage()); // we do nothing else than log } @SuppressWarnings("unchecked") public void onResponseReceived(Request httpRequest, Response response) { if (200 == response.getStatusCode()) { System.out.println("Got answer from async request."); withResult.execute((ResponseType) evalJson(response.getText().trim())); } } }); } catch (Exception e) { System.out.println("JSON request error. " + e.getLocalizedMessage()); // we do nothing else than log } }
From source file:ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.HtmlPage.java
License:Apache License
public HtmlPage(final String widgetId) { final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, pageUrl = createUrl(widgetId)); try {// ww w . ja va 2 s . c om requestBuilder.sendRequest(null, new HelpRequestCallback()); } catch (final RequestException ex) { displayException(ex); } }
From source file:ch.unifr.pai.twice.comm.clientServerTime.client.ClientServerTimeOffset.java
License:Apache License
/** * The method sends a request asynchronously to the server side ({@link PingServlet}) and measures the time that it takes. The offset is then defined by * dividing the resulting round-trip time by two given the theoretical assumption that the connection is symmetrical (identical up- and downstream speed). * Although this requirement is almost never the case, it is precise enough for not affecting user experience and allows to establish a consistent event * ordering mechanism between distributed systems. * // w ww . j a va 2 s. c om * @param callback * called at the end of the request providing the estimated offset between the server side and the local system clock in milliseconds. */ public static void getServerTimeOffset(final AsyncCallback<Long> callback) { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, GWT.getHostPageBaseURL() + "ping"); final long startTime = getCurrentTime(); try { rb.sendRequest(null, createServerTimeOffsetRequestCallback(callback, startTime)); } catch (RequestException e) { callback.onFailure(e); } }