List of usage examples for com.google.gwt.http.client RequestBuilder RequestBuilder
protected RequestBuilder(String httpMethod, String url)
From source file:anzsoft.xmpp4gwt.client.Bosh2Connector.java
License:Open Source License
public void setHttpBase(final String boshUrl) { if (boshUrl.startsWith("http://") || boshUrl.startsWith("https://")) { setCrossDomainHttpBase(boshUrl); return;// w ww.j a v a2s .co m } builder = new RequestBuilder(RequestBuilder.POST, boshUrl); builder.setHeader("Connection", "close"); }
From source file:br.com.pegasus.solutions.smartgwt.lib.client.view.impl.advanced.bar.infra.ExporterData.java
License:Apache License
private static void processRequest(String params) { try {//from w ww.ja v a 2 s. co m RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, GWT.getModuleBaseURL() + "ExportServlet"); requestBuilder.setHeader("Content-type", "application/x-www-form-urlencoded"); requestBuilder.sendRequest(params, new RequestCallback() { public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { ExporterData.callExportServlet .fireEvent(new ClickEvent(ExporterData.callExportServlet.getJsObj())); } else { MessageUtil .showError("An Error occurred response status code: " + response.getStatusCode()); } } public void onError(Request request, Throwable exception) { MessageUtil.showError(exception.getMessage()); } }); } catch (RequestException e) { MessageUtil.showError(e.getMessage()); } }
From source file:br.com.pegasus.solutions.smartgwt.lib.client.view.impl.util.HttpRequestUtil.java
License:Apache License
/** * do request/*from ww w. j a va2s.c om*/ * * @param servletName {@link String} * @param params {@link String} * @param iRequestBuilderSucessAction {@link IRequestBuilderFailedAction} * @param iFailedAction {@link IRequestBuilderFailedAction} * @throws RequestException * @return void */ private static void doRequest(final IRequestBuilderSucessAction iRequestBuilderSucessAction, final IRequestBuilderFailedAction iFailedAction, String url, String params, RequestBuilder.Method method) throws RequestException { RequestBuilder requestBuilder = new RequestBuilder(method, url); requestBuilder.setHeader("Content-type", "application/x-www-form-urlencoded"); requestBuilder.sendRequest(params, new RequestCallback() { public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode() && iRequestBuilderSucessAction != null) { iRequestBuilderSucessAction.executeAction(request, response); } } public void onError(Request request, Throwable exception) { if (iFailedAction != null) { iFailedAction.executeAction(request, exception); } else { MessageUtil.showError(exception.getMessage()); } } }); }
From source file:bufferings.ktr.wjr.client.service.KtrWjrJsonServiceAsync.java
License:Apache License
/** * Sends a request to the ktrwjr servlet. * //from w ww . j ava2s . c o m * @param params * the parameters. * @param callback * the callback. * @throws RequestException * thrown when the error occured. */ void sendRequest(List<Pair> params, RequestCallback callback) throws RequestException { RequestBuilder builder = new RequestBuilder(POST, JSON_SERVLET_URL); builder.setHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_X_WWW_FORM_URLENCODED); builder.sendRequest(format(params), callback); }
From source file:ca.upei.ic.timetable.client.Remote.java
License:Apache License
/** * Calls a remote method using HTTP GET/*from w w w . j a v a2 s.co 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:ca.upei.ic.timetable.client.Remote.java
License:Apache License
/** * Calls a remote method using HTTP POST * // w ww . j av a2s. c om * @param method * @param contentType * @param data * @param callback */ public Request post(String method, String contentType, String data, RequestCallback callback) { StringBuffer q = new StringBuffer(); q.append("?method=" + method); RequestBuilder req = new RequestBuilder(RequestBuilder.POST, url_ + q); req.setHeader("Content-type", contentType); req.setRequestData(data); 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 ww w. j a va2 s . co m * 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 login./* w w w .ja v a2 s.c om*/ * * @param userWithoutDomain * the user without domain * @param passwd * the passwd * @param callback * the callback */ public void doLogin(final String userWithoutDomain, final String passwd, final AsyncCallback<Void> callback) { final RequestBuilder request = new RequestBuilder(RequestBuilder.POST, "/auth/signin"); final StringBuffer params = new StringBuffer(); params.append("address="); params.append(URL.encodeQueryString(userWithoutDomain)); params.append("&password="); params.append(URL.encodeQueryString(passwd)); params.append("&signIn="); params.append(URL.encodeQueryString("Sign in")); try { request.setHeader("Content-Type", "application/x-www-form-urlencoded"); 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.auth.WaveClientSimpleAuthenticator.java
License:GNU Affero Public License
/** * Do logout.//w w w . j a va 2 s. c om * * @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 w ww .j a v a 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()); } }