List of usage examples for com.google.gwt.http.client Request Request
protected Request()
From source file:nl.strohalm.cyclos.mobile.client.utils.RestRequest.java
License:Open Source License
/** * Sends a request using the given callback to notify the results. * This method does not uses authentication, to perform authenticated * requests see {@link #sendAuthenticated(AsyncCallback)} *///from w w w. j a va 2 s. c o m public Request send(AsyncCallback<T> callback) { // Start loading progress CyclosMobile.get().getMainLayout().startLoading(); String url = ""; // Append parameters as GET if (httpMethod == RequestBuilder.GET) { url = Configuration.get().getServiceUrl(this.path, parameters); } else { url = Configuration.get().getServiceUrl(this.path); } RequestBuilder request = new RequestBuilder(httpMethod, url); request.setTimeoutMillis(20 * 1000); // 20 seconds request.setHeader("Accept", "application/json"); request.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); if (httpMethod == RequestBuilder.POST) { request.setHeader("Content-Type", "application/json"); // Send post body parameters if (parameters != null) { String json = parameters.toJSON(); request.setRequestData(json); } else { // Send post without data request.setRequestData(""); } } // Send a JSON post object if (postObject != null) { request.setHeader("Content-Type", "application/json"); request.setRequestData(new JSONObject(postObject).toString()); } if (username != null && !username.isEmpty()) { request.setHeader("Authorization", "Basic " + Base64.encode(username + ":" + password)); } request.setCallback(new RequestCallbackAdapter(callback)); try { // Send request return request.send(); } catch (RequestException e) { callback.onFailure(e); // Stop loading progress CyclosMobile.get().getMainLayout().stopLoading(); // Returns an emulated request, which does nothing return new Request() { @Override public void cancel() { } @Override public boolean isPending() { return false; } }; } }
From source file:org.openmoney.omlets.mobile.client.utils.RestRequest.java
License:Open Source License
/** * Sends a request using the given callback to notify the results. * This method does not uses authentication, to perform authenticated * requests see {@link #sendAuthenticated(AsyncCallback)} */// w ww. ja v a2s.c o m public Request send(AsyncCallback<T> callback) { // Start loading progress OmletsMobile.get().getMainLayout().startLoading(); String url = ""; // Append parameters as GET if (httpMethod == RequestBuilder.GET) { url = Configuration.get().getServiceUrl(this.path, parameters); } else { url = Configuration.get().getServiceUrl(this.path); } ErrorHandler.debug("RestRequest:" + httpMethod + ",url:" + url); RequestBuilder request = new RequestBuilder(httpMethod, url); request.setTimeoutMillis(40 * 1000); // 40 seconds request.setHeader("Accept", "application/json"); request.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); if (httpMethod == RequestBuilder.POST) { request.setHeader("Content-Type", "application/json"); // Send post body parameters if (parameters != null) { String json = parameters.toJSON(); request.setRequestData(json); } else { // Send post without data request.setRequestData(""); } } // Send a JSON post object if (postObject != null) { request.setHeader("Content-Type", "application/json"); request.setRequestData(new JSONObject(postObject).toString()); } if (username != null && !username.isEmpty()) { request.setHeader("Authorization", "Basic " + Base64.encode(username + ":" + password)); } request.setCallback(new RequestCallbackAdapter(callback)); try { // Send request return request.send(); } catch (RequestException e) { callback.onFailure(e); // Stop loading progress OmletsMobile.get().getMainLayout().stopLoading(); // Returns an emulated request, which does nothing return new Request() { @Override public void cancel() { } @Override public boolean isPending() { return false; } }; } }