List of usage examples for com.google.gwt.http.client RequestBuilder POST
Method POST
To view the source code for com.google.gwt.http.client RequestBuilder POST.
Click Source Link
From source file:com.totsp.gwittir.rest.client.transports.XRESTTransport.java
License:Open Source License
public RequestControl put(String mimeType, String url, String payload, final AsyncCallback<String> callback) { RequestBuilder b = new RequestBuilder(RequestBuilder.POST, url); b.setHeader(X_REST_METHOD_HEADER, "PUT"); b.setHeader(ACCEPT_HEADER, mimeType); b.setHeader(CONTENT_TYPE_HEADER, mimeType); b.setRequestData(payload);//w w w .j av a2s .co m return super.doRequest(b, new GenericRequestCallback(HTTPTransport.PUT_RESPONSE_CODES, false, callback)); }
From source file:com.vaadin.client.communication.Heartbeat.java
License:Apache License
/** * Sends a heartbeat to the server/*from w w w. j a va 2s . com*/ */ public void send() { timer.cancel(); final RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, uri); final RequestCallback callback = new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { int status = response.getStatusCode(); if (status == Response.SC_OK) { connection.getConnectionStateHandler().heartbeatOk(); } else { // Handler should stop the application if heartbeat should // no longer be sent connection.getConnectionStateHandler().heartbeatInvalidStatusCode(request, response); } schedule(); } @Override public void onError(Request request, Throwable exception) { // Handler should stop the application if heartbeat should no // longer be sent connection.getConnectionStateHandler().heartbeatException(request, exception); schedule(); } }; rb.setCallback(callback); try { getLogger().fine("Sending heartbeat request..."); rb.send(); } catch (RequestException re) { callback.onError(null, re); } }
From source file:com.vaadin.client.communication.XhrConnection.java
License:Apache License
/** * Sends an asynchronous UIDL request to the server using the given URI. * // ww w. ja v a2s . com * @param payload * The URI to use for the request. May includes GET parameters * @throws RequestException * if the request could not be sent */ public void send(JsonObject payload) { RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, getUri()); // TODO enable timeout // rb.setTimeoutMillis(timeoutMillis); // TODO this should be configurable rb.setHeader("Content-Type", JsonConstants.JSON_CONTENT_TYPE); rb.setRequestData(payload.toJson()); XhrResponseHandler responseHandler = createResponseHandler(); responseHandler.setPayload(payload); responseHandler.setRequestStartTime(Profiler.getRelativeTimeMillis()); rb.setCallback(responseHandler); getLogger().info("Sending xhr message to server: " + payload.toJson()); try { final Request request = rb.send(); if (webkitMaybeIgnoringRequests && BrowserInfo.get().isWebkit()) { final int retryTimeout = 250; new Timer() { @Override public void run() { // Use native js to access private field in Request if (resendRequest(request) && webkitMaybeIgnoringRequests) { // Schedule retry if still needed schedule(retryTimeout); } } }.schedule(retryTimeout); } } catch (RequestException e) { getConnectionStateHandler().xhrException(new XhrConnectionError(null, payload, e)); } }
From source file:com.vaadin.terminal.gwt.client.ApplicationConnection.java
License:Open Source License
/** * Sends an asynchronous UIDL request to the server using the given URI. * // w w w . j a v a 2 s . c o m * @param uri * The URI to use for the request. May includes GET parameters * @param payload * The contents of the request to send * @param requestCallback * The handler for the response * @throws RequestException * if the request could not be sent */ protected void doAsyncUIDLRequest(String uri, String payload, RequestCallback requestCallback) throws RequestException { RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, uri); // TODO enable timeout // rb.setTimeoutMillis(timeoutMillis); rb.setHeader("Content-Type", "text/plain;charset=utf-8"); rb.setRequestData(payload); rb.setCallback(requestCallback); rb.send(); }
From source file:de.kp.ames.search.client.http.ConnectionManager.java
License:Open Source License
/** * @param url//w w w . j a va 2 s . c o m * @param requestData * @param callback */ public void sendPostRequest(final String url, final HashMap<String, String> headers, final String requestData, final ConnectionCallback callback) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url)); builder.setTimeoutMillis(CoreGlobals.CONNECTION_TIMEOUT); /* * Set header parameters */ if (headers.isEmpty() == false) { Set<String> keys = headers.keySet(); for (String key : keys) { builder.setHeader(key, headers.get(key)); } } /* * Set request data */ if (requestData != null) builder.setRequestData(requestData); /* * Set request callback */ builder.setCallback(new RequestCallback() { public void onResponseReceived(Request request, Response response) { if (STATUS_CODE_OK == response.getStatusCode()) { SC.logWarn("====> cm.onResponseReceived"); handleSuccess(response, callback); } else { handleFailure(response, callback); } } public void onError(Request request, Throwable exception) { if (exception instanceof RequestTimeoutException) { handleTimeout(exception, callback); } else { handleError(exception, callback); } } }); try { builder.send(); } catch (RequestException e) { handleError(e, callback); } }
From source file:de.kp.ames.web.client.core.http.ConnectionManager.java
License:Open Source License
/** * @param url/*from ww w.j a v a 2 s . c o m*/ * @param requestData * @param callback */ public void sendPostRequest(final String url, final HashMap<String, String> headers, final String requestData, final ConnectionCallback callback) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(url)); builder.setTimeoutMillis(GuiConstants.CONNECTION_TIMEOUT); /* * Set header parameters */ if (headers.isEmpty() == false) { Set<String> keys = headers.keySet(); for (String key : keys) { builder.setHeader(key, headers.get(key)); } } /* * Set request data */ if (requestData != null) builder.setRequestData(requestData); /* * Set request callback */ builder.setCallback(new RequestCallback() { public void onResponseReceived(Request request, Response response) { if (STATUS_CODE_OK == response.getStatusCode()) { handleSuccess(response, callback); } else { handleFailure(response, callback); } } public void onError(Request request, Throwable exception) { if (exception instanceof RequestTimeoutException) { handleTimeout(exception, callback); } else { handleError(exception, callback); } } }); try { builder.send(); } catch (RequestException e) { handleError(e, callback); } }
From source file:ecc.gwt.warning.client.JsonRpc.java
License:Apache License
/** * Executes a json-rpc request.//from w ww .jav a2s .c o m * * @param url * The location of the service * @param username * The username for basic authentification * @param password * The password for basic authentification * @param params * An array of objects containing the parameters * @param callback * A callbackhandler like in gwt's rpc. */ public void request(final String url, String username, String password, Map paramMap, boolean isStream, final AsyncCallback callback) { HashMap request = new HashMap(); request.putAll(paramMap); //request.put("id", new Integer(requestSerial++)); if (username == null) if (requestUser != null) username = requestUser; if (password == null) if (requestPassword != null) password = requestPassword; RequestCallback handler = new RequestCallback() { public void onResponseReceived(Request request, Response response) { try { String resp = response.getText(); if (resp.equals("")) throw new RuntimeException("empty"); HashMap reply = (HashMap) decode(resp); if (reply == null) { RuntimeException runtimeException = new RuntimeException("parse: " + response.getText()); fireFailure(runtimeException); callback.onFailure(runtimeException); } if (isErrorResponse(reply)) { RuntimeException runtimeException = new RuntimeException("error: " + reply.get("error")); fireFailure(runtimeException); callback.onFailure(runtimeException); } else if (isSuccessfulResponse(reply)) { callback.onSuccess(reply.get("result")); } else { RuntimeException runtimeException = new RuntimeException("syntax: " + response.getText()); fireFailure(runtimeException); callback.onFailure(runtimeException); } } catch (RuntimeException e) { fireFailure(e); callback.onFailure(e); } finally { decreaseRequestCounter(); } } public void onError(Request request, Throwable exception) { try { if (exception instanceof RequestTimeoutException) { RuntimeException runtimeException = new RuntimeException("timeout"); fireFailure(runtimeException); callback.onFailure(runtimeException); } else { RuntimeException runtimeException = new RuntimeException("other"); fireFailure(runtimeException); callback.onFailure(runtimeException); } } catch (RuntimeException e) { fireFailure(e); callback.onFailure(e); } finally { decreaseRequestCounter(); } } private boolean isErrorResponse(HashMap response) { return response.get("error") != null && response.get("result") == null; } private boolean isSuccessfulResponse(HashMap response) { return response.get("error") == null && response.containsKey("result"); } }; increaseRequestCounter(); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); if (requestTimeout > 0) builder.setTimeoutMillis(requestTimeout); String body = ""; if (isStream) { builder.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); body = new String(encode(request)); } else { builder.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); StringBuffer sb = new StringBuffer(); for (Iterator iterator = request.entrySet().iterator(); iterator.hasNext();) { Map.Entry<String, Object> entry = (Map.Entry<String, Object>) iterator.next(); sb.append(entry.getKey()).append("=").append(String.valueOf(entry.getValue())).append("&"); } body = sb.toString(); if (body.endsWith("&")) body = body.substring(0, body.length() - 1); } builder.setHeader("Content-Length", Integer.toString(body.length())); if (requestCookie != null) if (Cookies.getCookie(requestCookie) != null) builder.setHeader("X-Cookie", Cookies.getCookie(requestCookie)); if (username != null) builder.setUser(username); if (password != null) builder.setPassword(password); try { builder.sendRequest(body, handler); } catch (RequestException exception) { handler.onError(null, exception); } }
From source file:edu.cudenver.bios.glimmpse.client.panels.ResultsDisplayPanel.java
License:Open Source License
private void sendPowerRequest() { showWorkingDialog();/*from w ww. ja va 2 s .c o m*/ String requestEntityBody = manager.getPowerRequestXML(); matrixDisplayPanel.loadFromXML(requestEntityBody); RequestBuilder builder = null; switch (solutionType) { case POWER: builder = new RequestBuilder(RequestBuilder.POST, POWER_URL); break; case TOTAL_N: builder = new RequestBuilder(RequestBuilder.POST, SAMPLE_SIZE_URL); break; } try { builder.setHeader("Content-Type", "text/xml"); builder.sendRequest(requestEntityBody, new RequestCallback() { public void onError(Request request, Throwable exception) { showError("Calculation failed: " + exception.getMessage()); } public void onResponseReceived(Request request, Response response) { if (STATUS_CODE_OK == response.getStatusCode() || STATUS_CODE_CREATED == response.getStatusCode()) { showResults(response.getText()); } else { showError("Calculation failed: [HTTP STATUS " + response.getStatusCode() + "] " + response.getText()); } } }); } catch (Exception e) { showError("Failed to send the request: " + e.getMessage()); } }
From source file:edu.nrao.dss.client.forms.JSONCallback.java
License:Open Source License
public static void post(String uri, String[] keys, String[] values, final JSONCallback cb) { RequestBuilder post = new RequestBuilder(RequestBuilder.POST, uri); post.setHeader("Accept", "application/json"); post.setHeader("Content-Type", "application/x-www-form-encoded"); try {//from ww w.ja v a 2 s . c o m post.sendRequest(kv2url(keys, values), new JSONRequest(cb, uri)); } catch (RequestException e) { } }
From source file:edu.nrao.dss.client.widget.NomineePanel.java
License:Open Source License
private void initLayout() { setHeading("Nominee Periods"); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, rootUrl); JsonReader<BaseListLoadResult<NomineeType>> reader = new JsonReader<BaseListLoadResult<NomineeType>>( new NomineeType()); proxy = new DynamicHttpProxy<BaseListLoadResult<NomineeType>>(builder); loader = new BaseListLoader<BaseListLoadResult<NomineeModel>>(proxy, reader); store = new ListStore<NomineeModel>(getLoader()); nominees = new ListView<NomineeModel>(); nominees.setStore(store);//from w ww . jav a 2s . c o m // Q: How to change the format of a field, i.e., duration and score? // Well, we've already solved the formatting problem by formatting on the server side, but in theory you could do something like: // nominees.setTemplate("<b>{sess_name}</b> {sess_type} ({proj_name}) {score:number(\"0000.0000\")} for {durationStr}"); // see: http://dev.sencha.com/deploy/gxtdocs/com/extjs/gxt/ui/client/core/XTemplate.html // but we'd really like to do something like this: //nominees.setSimpleTemplate("<b>{sess_name}</b> ({proj_name}) {duration} minutes {TimeUtil.min2sex(duration)}"); nominees.setSimpleTemplate("<b>{sess_name}</b> {sess_type} ({proj_name}) {scoreStr} for {durationStr}"); add(nominees); nominees.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<BaseModel>>() { public void handleEvent(SelectionChangedEvent<BaseModel> be) { BaseModelData baseModelData = (BaseModelData) (be.getSelectedItem()); if (baseModelData == null) { return; } // add the selected period to the Period Explorer schedule.scheduleExplorer.addRecord(nominee2Period(baseModelData)); schedule.scheduleExplorer.loadData(); // and show the Session's scores on the calendar String name = baseModelData.get("sess_name") + " (" + baseModelData.get("proj_name") + ")"; schedule.calendarControl.showSessionScores(name); //schedule.updateCalendar(); } }); }