List of usage examples for com.google.gwt.http.client RequestBuilder setRequestData
public void setRequestData(String requestData)
From source file:org.pentaho.mantle.client.solutionbrowser.fileproperties.PermissionsPanel.java
License:Open Source License
/** * @return//from w ww .ja va 2s . co m */ public List<RequestBuilder> prepareRequests() { ArrayList<RequestBuilder> requestBuilders = new ArrayList<RequestBuilder>(); String moduleBaseURL = GWT.getModuleBaseURL(); String moduleName = GWT.getModuleName(); String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName)); String url = contextURL + "api/repo/files/" + SolutionBrowserPanel.pathToId(fileSummary.getPath()) + "/acl"; //$NON-NLS-1$//$NON-NLS-2$ RequestBuilder builder = new RequestBuilder(RequestBuilder.PUT, url); builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); builder.setHeader("Content-Type", "application/xml"); // At this point if we're inheriting we need to remove all the acls so that the inheriting flag isn't set by // default if (isInheritsAcls(fileInfo)) { removeAllAces(fileInfo); } else { // Check if any of the permission sets should be replaced with ALL. // Any non-inherited Ace with a permission set containing PERM_GRANT_PERM should be replaced // with a single PERM_ALL. NodeList aces = fileInfo.getElementsByTagName(ACES_ELEMENT_NAME); for (int i = 0; i < aces.getLength(); i++) { Element ace = (Element) aces.item(i); NodeList perms = ace.getElementsByTagName(PERMISSIONS_ELEMENT_NAME); for (int j = 0; j < perms.getLength(); j++) { Element perm = (Element) perms.item(j); if (perm.getFirstChild() != null) { if (Integer.parseInt(perm.getFirstChild().getNodeValue()) == PERM_GRANT_PERM) { replacePermissionsWithAll(ace, fileInfo); break; } } } } } // set request data in builder itself builder.setRequestData(fileInfo.toString()); // add builder to list to return to parent for execution requestBuilders.add(builder); return requestBuilders; }
From source file:org.rapla.rest.gwtjsonrpc.client.impl.JsonCall20HttpPost.java
License:Apache License
@Override protected void send() { requestId = ++lastRequestId;/*from ww w . j a v a 2 s. co m*/ final StringBuilder body = new StringBuilder(); body.append("{\"jsonrpc\":\"2.0\",\"method\":\""); body.append(methodName); body.append("\",\"params\":"); body.append(requestParams); body.append(",\"id\":").append(requestId); body.append("}"); final RequestBuilder rb; rb = new RequestBuilder(RequestBuilder.POST, proxy.getServiceEntryPoint()); rb.setHeader("Content-Type", JsonConstants.JSONRPC20_REQ_CT); rb.setHeader("Accept", JsonConstants.JSONRPC20_ACCEPT_CTS); rb.setCallback(this); rb.setRequestData(body.toString()); send(rb); }
From source file:org.rhq.coregui.client.LoginView.java
License:Open Source License
private void login(final String username, final String password) { loginButton.setDisabled(true);/*from w w w. j a v a 2s. c o m*/ try { RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "/portal/j_security_check.do"); requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); // URL-encode the username and password in case they contain URL special characters ('?', '&', '%', '+', // etc.), which would corrupt the request if not encoded. String encodedUsername = URL.encodeQueryString(username); String encodedPassword = URL.encodeQueryString(password); String requestData = "j_username=" + encodedUsername + "&j_password=" + encodedPassword; requestBuilder.setRequestData(requestData); requestBuilder.setCallback(new RequestCallback() { public void onResponseReceived(Request request, Response response) { int statusCode = response.getStatusCode(); if (statusCode == 200) { window.destroy(); fakeForm.setVisible(false); loginShowing = false; UserSessionManager.login(username, password); setLoginError(null); } else { handleError(statusCode); } } public void onError(Request request, Throwable exception) { handleError(0); } }); requestBuilder.send(); } catch (Exception e) { handleError(0); } }
From source file:org.rhq.enterprise.gui.coregui.client.LoginView.java
License:Open Source License
private void login(final String username, final String password) { loginButton.setDisabled(true);/*from ww w . j a v a 2s . co m*/ try { RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "/j_security_check.do"); requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); // URL-encode the username and password in case they contain URL special characters ('?', '&', '%', '+', // etc.), which would corrupt the request if not encoded. String encodedUsername = URL.encodeQueryString(username); String encodedPassword = URL.encodeQueryString(password); String requestData = "j_username=" + encodedUsername + "&j_password=" + encodedPassword; requestBuilder.setRequestData(requestData); requestBuilder.setCallback(new RequestCallback() { public void onResponseReceived(Request request, Response response) { int statusCode = response.getStatusCode(); if (statusCode == 200) { window.destroy(); loginShowing = false; UserSessionManager.login(username, password); } else { handleError(statusCode); } } public void onError(Request request, Throwable exception) { handleError(0); } }); requestBuilder.send(); } catch (Exception e) { handleError(0); } }
From source file:org.sigmah.client.page.login.LoginView.java
License:Open Source License
private void doLogin(final String login, final String password, final Button loginButton, final Image loader) { final String query = "email=" + URL.encodeComponent(login) + "&password=" + URL.encodeComponent(password); final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, "../Login/service"); requestBuilder.setCallback(new RequestCallback() { @Override//from w w w.ja va 2s . c o m public void onResponseReceived(Request request, Response response) { if (response.getText().contains("OK")) Window.Location.reload(); else { MessageBox.alert(I18N.CONSTANTS.loginConnectErrorTitle(), I18N.CONSTANTS.loginConnectErrorBadLogin(), null); loginButton.setEnabled(true); loader.getElement().getStyle().setVisibility(Visibility.HIDDEN); } } @Override public void onError(Request request, Throwable exception) { MessageBox.alert(I18N.CONSTANTS.loginConnectErrorTitle(), exception.getMessage(), null); loginButton.setEnabled(true); loader.getElement().getStyle().setVisibility(Visibility.HIDDEN); } }); requestBuilder.setRequestData(query); requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); loginButton.setEnabled(false); loader.getElement().getStyle().setVisibility(Visibility.VISIBLE); try { requestBuilder.send(); } catch (RequestException ex) { MessageBox.alert(I18N.CONSTANTS.loginConnectErrorTitle(), ex.getMessage(), null); } }
From source file:org.sigmah.shared.servlet.ServletRequestBuilder.java
License:Open Source License
/** * Sends the request with its optional parameter(s) (including {@code POST} parameters). * /*from w w w . ja v a 2 s. c o m*/ * @param callback * The {@code RequestCallback}. * @throws ServletRequestException * If an error occurs during request call. */ public void send(final RequestCallback callback) throws ServletRequestException { final RequestBuilder requestBuilder = new RequestBuilder(requestMethod, urlBuilder.toString()); requestBuilder.setCallback(callback != null ? callback : Void); final StringBuilder builder = new StringBuilder(); if (ClientUtils.isNotEmpty(requestAttributes)) { final Iterator<String> iterator = requestAttributes.keySet().iterator(); while (iterator.hasNext()) { final String next = iterator.next(); final String attribute = requestAttributes.get(next); if (attribute != null) { builder.append(URL.encodeQueryString(next)); builder.append('='); builder.append(URL.encodeQueryString(attribute)); if (iterator.hasNext()) { builder.append('&'); } } } } if (isPostMethod()) { requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); requestBuilder.setRequestData(builder.length() > 0 ? builder.toString() : null); } try { requestBuilder.send(); } catch (final RequestException e) { throw new ServletRequestException("Servlet request '" + builder + "' execution fails.", e); } }
From source file:org.spiffyui.client.rest.RESTility.java
License:Apache License
/** * <p>/*www .j a v a 2 s . c om*/ * Make an HTTP call and get the results as a JSON object. This method handles * cases like login, error parsing, and configuration requests. * </p> * * @param options the options for the REST request */ public static void callREST(RESTOptions options) { if (hasPotentialXss(options.getDataString())) { options.getCallback().onError(new RESTException(RESTException.XSS_ERROR, "", STRINGS.noServerContact(), new HashMap<String, String>(), -1, options.getURL())); return; } RESTILITY.m_restCalls.put(options.getCallback(), new RESTCallStruct(options.getURL(), options.getDataString(), options.getMethod(), options.shouldReplay(), options.getEtag())); RequestBuilder builder = new RESTRequestBuilder(options.getMethod().getMethod(), options.getURL()); /* Set our headers */ builder.setHeader("Accept", "application/json"); builder.setHeader("Accept-Charset", "UTF-8"); if (options.getHeaders() != null) { for (String k : options.getHeaders().keySet()) { builder.setHeader(k, options.getHeaders().get(k)); } } if (RESTILITY.m_bestLocale != null) { /* * The REST end points use the Accept-Language header to determine * the locale to use for the contents of the REST request. Normally * the browser will fill this in with the browser locale and that * doesn't always match the preferred locale from the Identity Vault * so we need to set this value with the correct preferred locale. */ builder.setHeader("Accept-Language", RESTILITY.m_bestLocale); } if (getUserToken() != null && getTokenServerUrl() != null) { builder.setHeader("Authorization", getFullAuthToken()); builder.setHeader("TS-URL", getTokenServerUrl()); } if (options.getEtag() != null) { builder.setHeader("If-Match", options.getEtag()); } if (options.getDataString() != null) { /* Set our request data */ builder.setRequestData(options.getDataString()); //b/c jaxb/jersey chokes when there is no data when content-type is json builder.setHeader("Content-Type", options.getContentType()); } builder.setCallback(RESTILITY.new RESTRequestCallback(options.getCallback())); try { /* If we are in the process of logging in then all other requests will just return with a 401 until the login is finished. We want to delay those requests until the login is complete when we will replay all of them. */ if (options.isLoginRequest() || !g_inLoginProcess) { builder.send(); } } catch (RequestException e) { MessageUtil.showFatalError(e.getMessage()); } }
From source file:org.t3as.snomedct.gwt.client.gwt.AnalyseHandler.java
License:Open Source License
private void sendTextToServer() { statusLabel.setText(""); conceptList.clear();//from ww w . j a va 2s .c o m // don't do anything if we have no text final String text = mainTextArea.getText(); if (text.length() < 1) { statusLabel.setText(messages.pleaseEnterTextLabel()); return; } // disable interaction while we wait for the response glassPanel.setPositionAndShow(); // build up the AnalysisRequest JSON object // start with any options final JSONArray options = new JSONArray(); setSemanticTypesOption(types, options); // defaults options.set(options.size(), new JSONString("word_sense_disambiguation")); options.set(options.size(), new JSONString("composite_phrases 8")); options.set(options.size(), new JSONString("no_derivational_variants")); options.set(options.size(), new JSONString("strict_model")); options.set(options.size(), new JSONString("ignore_word_order")); options.set(options.size(), new JSONString("allow_large_n")); options.set(options.size(), new JSONString("restrict_to_sources SNOMEDCT_US")); final JSONObject analysisRequest = new JSONObject(); analysisRequest.put("text", new JSONString(text)); analysisRequest.put("options", options); // send the input to the server final RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, webserviceUrl); builder.setHeader("Content-Type", MediaType.APPLICATION_JSON); builder.setRequestData(analysisRequest.toString()); // create the async callback builder.setCallback(new SnomedRequestCallback(conceptList, statusLabel, glassPanel, typeCodeToDescription)); // send the request try { builder.send(); } catch (final RequestException e) { statusLabel.setText(messages.problemPerformingAnalysisLabel()); GWT.log("There was a problem performing the analysis: " + e.getMessage(), e); glassPanel.hide(); } }
From source file:org.waveprotocol.box.webclient.search.RemoteSearchesService.java
License:Apache License
@Override public void storeSearches(List<SearchesItem> searches, final StoreCallback callback) { RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, SEARCHES_URL_BASE); requestBuilder.setRequestData(serializeSearches(searches).toJson()); LOG.trace().log("Store searches"); requestBuilder.setCallback(new RequestCallback() { @Override//from w w w .ja v a 2s . c o m public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() != Response.SC_OK) { callback.onFailure("Got back status code " + response.getStatusCode()); } else { LOG.error().log("Searches was stored"); } } @Override public void onError(Request request, Throwable exception) { LOG.error().log("Storing searches error: ", exception); callback.onFailure(exception.getMessage()); } }); try { requestBuilder.send(); } catch (RequestException e) { callback.onFailure(e.getMessage()); } }
From source file:uk.ac.diamond.gwt.rf.queue.client.core.QosRequestTransport.java
License:Open Source License
private void sendBatch(String payload, List<BatchedRequest> currentBatch) { // XXX use super.send? RequestBuilder builder = createRequestBuilder(); configureRequestBuilder(builder);//from w ww .j a v a 2 s.c o m builder.setRequestData(payload); builder.setCallback(createRequestCallbackBatch(currentBatch)); try { wireLogger.finest("Sending fire request"); builder.send(); } catch (RequestException e) { wireLogger.log(Level.SEVERE, " (" + e.getMessage() + ")", e); } }