List of usage examples for com.google.gwt.http.client RequestBuilder send
public Request send() throws RequestException
From source file:org.waveprotocol.box.webclient.search.RemoteSearchesService.java
License:Apache License
@Override public void getSearches(final GetCallback callback) { String url = SEARCHES_URL_BASE; LOG.trace().log("Getting searches"); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setCallback(new RequestCallback() { @Override//from w w w. ja v a 2s .c om public void onResponseReceived(Request request, Response response) { LOG.trace().log("Searches was received: ", response.getText()); if (response.getStatusCode() != Response.SC_OK) { callback.onFailure("Got back status code " + response.getStatusCode()); } else if (!response.getHeader("Content-Type").startsWith("application/json")) { callback.onFailure("Search service did not return json"); } else { SearchesJsoImpl searchPatterns; try { searchPatterns = JsonMessage.parse(response.getText()); } catch (JsonException e) { callback.onFailure(e.getMessage()); return; } List<SearchesItem> searches = deserializeSearches(searchPatterns); callback.onSuccess(searches); } } @Override public void onError(Request request, Throwable exception) { LOG.error().log("Getting searches error: ", exception); callback.onFailure(exception.getMessage()); } }); try { requestBuilder.send(); } catch (RequestException e) { callback.onFailure(e.getMessage()); } }
From source file:org.waveprotocol.box.webclient.stat.dialog.StatDialog.java
License:Apache License
private void showUrl(String url) { clear();//ww w. ja v a 2 s . c om RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { show(response.getText()); } @Override public void onError(Request request, Throwable ex) { Window.alert(ex.getMessage()); } }); try { requestBuilder.send(); } catch (RequestException ex) { Window.alert(ex.getMessage()); } }
From source file:org.waveprotocol.wave.client.doodad.attachment.AttachmentManagerImpl.java
License:Apache License
private void getAttachmentsInfo(final GetAttachmentsInfoCallback callback) { LOG.trace().log("Getting attachments info"); String request = ATTACHMENTS_INFO_URL_BASE + "?attachmentIds="; for (String attacmentId : pendingQueue) { if (!request.endsWith("=")) { request += ","; }// w w w. j a va 2 s. co m request += attacmentId; } final List<String> requestedAttachments = new ArrayList<String>(pendingQueue); pendingQueue.clear(); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, request); requestBuilder.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { LOG.trace().log("Attachments info was received: ", response.getText()); if (response.getStatusCode() != Response.SC_OK) { callback.onFailure(setFailureStatus(requestedAttachments), "Got back status code " + response.getStatusCode()); } else if (!response.getHeader("Content-Type").startsWith("application/json")) { callback.onFailure(setFailureStatus(requestedAttachments), "Search service did not return json"); } else { AttachmentsResponseJsoImpl attachmentsProto; try { attachmentsProto = JsonMessage.parse(response.getText()); } catch (JsonException e) { callback.onFailure(setFailureStatus(requestedAttachments), e.getMessage()); return; } List<Attachment> attachments = initializeAttachments(attachmentsProto); callback.onSuccess(attachments); } } @Override public void onError(Request request, Throwable e) { LOG.error().log("Getting attachments info error: ", e); callback.onFailure(setFailureStatus(requestedAttachments), e.getMessage()); } }); try { requestBuilder.send(); } catch (RequestException e) { callback.onFailure(setFailureStatus(requestedAttachments), e.getMessage()); } }
From source file:pl.touk.wonderfulsecurity.gwt.client.rpc.RpcExecutor.java
License:Apache License
public static void execute(RequestBuilder rb, final boolean displayCommunicationStatus) { final RequestCallback originalCallback = rb.getCallback(); /**//from w w w. jav a2 s.c o m * Using default message */ if (displayCommunicationStatus) { showServerCommunication(message); messageQueue.add(message); } /** * Replacing callback, to be able to get login page location from HTTP header */ rb.setCallback(new RequestCallback() { public void onResponseReceived(Request request, Response response) { String header = response.getHeader("loginPage"); if (header != null && header.length() > 0) { Redirect.redirect(header); } if (displayCommunicationStatus) { refreshUserMessage(); } originalCallback.onResponseReceived(request, response); } public void onError(Request request, Throwable exception) { if (displayCommunicationStatus) { refreshUserMessage(); } if (errorHandler != null) { errorHandler.handleError(request, exception); } originalCallback.onError(request, exception); } }); try { rb.send(); } catch (RequestException ex) { if (errorHandler != null) { errorHandler.handleError(ex); } } }
From source file:ru.prime.client.widgets.NewsPanel.java
public NewsPanel() { newsTitleField = new ListGridField("title", " ?"); setFields(newsTitleField);/*from w w w .ja v a 2 s. c o m*/ RequestBuilder b = new RequestBuilder(RequestBuilder.GET, "/messages/news"); try { b.setCallback(new RequestCallback() { public void onResponseReceived(Request request, Response response) { RecordList ls = new RecordList(); // Window.alert(response.getText()); String t = response.getText(); JSONArray v = JSONParser.parse(t).isArray(); for (int i = 0; i < v.size(); i++) { JSONObject val = v.get(i).isObject(); NewsEntity entry = new NewsEntity(); entry.setTitle(val.get("header").isString().stringValue()); ls.add(entry.toRecord()); } setData(ls); } public void onError(Request request, Throwable exception) { //Window.alert(exception.getMessage()); } }); b.send(); } catch (Exception e) { // Window.alert(e.getMessage()); } }
From source file:stroom.dashboard.client.vis.VisPanel.java
License:Apache License
private void injectScriptsFromString(final List<Script> scripts, final VisFunction function) { if (scripts == null || scripts.size() == 0) { // Set the function status to loaded. This will tell all handlers // that the function is ready for use. if (!LoadStatus.FAILURE.equals(function.getStatus())) { function.setStatus(LoadStatus.LOADED); }//from ww w. j a va 2 s .com } else { // Only load script if we haven't already had a failure. if (!LoadStatus.FAILURE.equals(function.getStatus())) { // Get the next script to load. final Script script = scripts.remove(0); // Make sure we don't inject a script more than once. if (!loadedScripts.contains(script.getId())) { final RequestCallback requestCallback = new RequestCallback() { @Override public void onResponseReceived(final Request request, final Response response) { // Make sure we don't inject a script more than // once. if (!loadedScripts.contains(script.getId())) { try { final String text = response.getText(); if (response.getStatusCode() == 200) { final FromString fromString = fromString(text); fromString.inject(); // Inject the next script in the list. injectScriptsFromString(scripts, function); } else { failure(function, "Failed to inject script '" + script.getName() + "' - Status " + response.getStatusCode()); } } catch (final Exception e) { failure(function, "Failed to inject script '" + script.getName() + "' - " + e.getMessage()); } finally { // Remember that we have loaded or at least // attempted to load this script so we don't // try and fetch it again. loadedScripts.add(script.getId()); } } else { // Inject the next script in the list. injectScriptsFromString(scripts, function); } } @Override public void onError(final Request request, final Throwable e) { failure(function, "Failed to inject script '" + script.getName() + "' - " + e.getMessage()); } }; try { final String url = createURL(script); final RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setCallback(requestCallback); requestBuilder.send(); } catch (final Throwable e) { failure(function, "Failed to inject script '" + script.getName() + "' - " + e.getMessage()); } } else { // Inject the next script in the list. injectScriptsFromString(scripts, function); } } } }
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 w w.ja va2s. 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); } }