List of usage examples for com.google.gwt.http.client RequestBuilder send
public Request send() throws RequestException
From source file:org.vectomatic.svg.edu.client.Main.java
License:Open Source License
public void readPicture(final boolean readDots) { RequestBuilder pictureBuilder = new RequestBuilder(RequestBuilder.GET, getPictureUrl()); pictureBuilder.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { svgContainer.setHTML("Cannot find resource"); }/* w w w .jav a 2s. com*/ /** * Parse the SVG artwork and launch the parse of the dot structure */ private void onSuccess(Request request, Response response) { // Parse the document OMSVGSVGElement svg = OMSVGParser.parse(response.getText()); // Position the filter pictureAlpha2.setValue(0f); svg.getStyle().setSVGProperty(SVGConstants.SVG_FILTER_ATTRIBUTE, DOMHelper.toUrl(ID_TRANSITION_FILTER)); // Insert the SVG root element into the HTML UI rootSvg.replaceChild(svg, pictureSvg); pictureSvg = svg; // Send the dots request if (readDots) { readDots(); } else { transition(null); } } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { onSuccess(request, response); } else { onError(request, null); } } }); // Send the picture request try { pictureBuilder.send(); } catch (RequestException e) { GWT.log("Cannot fetch " + getPictureUrl(), e); } }
From source file:org.vectomatic.svg.edu.client.Main.java
License:Open Source License
public void readDots() { // Add a bogus query to bypass the browser cache as advised by: // https://developer.mozilla.org/En/Using_XMLHttpRequest#Bypassing_the_cache String url = getDotsUrl();/* ww w. j av a 2 s.c o m*/ url += (url.indexOf("?") == -1) ? ("?ts=" + System.currentTimeMillis()) : ("&ts=" + +System.currentTimeMillis()); final RequestBuilder dotsBuilder = new RequestBuilder(RequestBuilder.GET, getDotsUrl()); dotsBuilder.setCallback(new RequestCallback() { /** * Create a blank dots structure */ public void onError(Request request, Throwable exception) { if (mode == Mode.GAME) { mode = Mode.DESIGN; readPicture(true); return; } OMSVGSVGElement svg = doc.createSVGSVGElement(); svg.setAttribute(SVGConstants.XMLNS_PREFIX, SVGConstants.SVG_NAMESPACE_URI); svg.setAttribute(SVGConstants.XMLNS_PREFIX + ":" + SVGConstants.XLINK_PREFIX, SVGConstants.XLINK_NAMESPACE_URI); rootSvg.replaceChild(svg, dotSvg); dotSvg = svg; // Synchronize the the dot coordinates with the picture coordinates if (mode == Mode.DESIGN) { dotSvg.setViewBox(pictureSvg.getViewBox().getBaseVal()); } // Reset the polyline lineGroup = doc.createSVGGElement(); dotSvg.appendChild(lineGroup); polyline = doc.createSVGPolylineElement(); polyline.setClassNameBaseVal(STYLE_LINE2); points = polyline.getPoints(); lineGroup.appendChild(polyline); // Reset the dots dotGroup = doc.createSVGGElement(); dotSvg.appendChild(dotGroup); } /** * Create a dots structure populated by the SVG data */ private void onSuccess(Request request, Response response) { OMSVGSVGElement svg = OMSVGParser.parse(response.getText()); rootSvg.replaceChild(svg, dotSvg); dotSvg = svg; // Synchronize the the dot coordinates with the picture coordinates if (mode == Mode.DESIGN) { dotSvg.setViewBox(pictureSvg.getViewBox().getBaseVal()); } dotGroup = (OMSVGGElement) dotSvg.getFirstChild(); // Reset the polyline lineGroup = doc.createSVGGElement(); dotSvg.appendChild(lineGroup); polyline = doc.createSVGPolylineElement(); polyline.setClassNameBaseVal(STYLE_LINE2); points = polyline.getPoints(); lineGroup.appendChild(polyline); // Parse the dots to recreate the polyline OMNodeList childNodes = dotGroup.getChildNodes(); for (int i = 0, size = childNodes.getLength(); i < size; i++) { OMSVGGElement g1 = (OMSVGGElement) childNodes.getItem(i); g1.addMouseDownHandler(Main.this); if (mode == Mode.DESIGN) { g1.addMouseMoveHandler(Main.this); g1.addMouseUpHandler(Main.this); } g1.addMouseOverHandler(Main.this); g1.addMouseOutHandler(Main.this); dots.add(g1); dotList.addItem(toDotName(i)); if (mode == Mode.DESIGN) { OMSVGMatrix m = g1.getTransform().getBaseVal().getItem(0).getMatrix(); points.appendItem(dotSvg.createSVGPoint(m.getE(), m.getF())); } } } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { onSuccess(request, response); } else { if (mode == Mode.GAME) { mode = Mode.DESIGN; readPicture(true); return; } onError(request, null); } if (mode == Mode.DESIGN) { pictureSvg.getStyle().setSVGProperty(SVGConstants.SVG_FILTER_ATTRIBUTE, DOMHelper.toUrl(ID_ALPHA1_FILTER)); setPictureAlpha(1f); showLineCheck.setValue(false); pictureAlphaSlider.setCurrentValue(1); } else { pictureSvg.getStyle().setVisibility(Visibility.HIDDEN); polyline.setClassNameBaseVal(STYLE_LINE1); } dotAlpha.setValue(1f); dotSvg.getStyle().setSVGProperty(SVGConstants.SVG_FILTER_ATTRIBUTE, DOMHelper.toUrl(ID_ALPHA2_FILTER)); designPanel.setVisible(mode == Mode.DESIGN); // Resize to the size of the window updatePictureSize(); updateUI(); } }); // Send the dots request try { dotsBuilder.send(); } catch (RequestException e) { GWT.log("Cannot fetch " + dotsBuilder.getUrl(), e); } }
From source file:org.vectomatic.svg.samples.client.SampleBase.java
License:Open Source License
/** * Load the sample HTML source code//from w w w . ja v a 2 s. c o m */ protected void requestCodeContents(String partialPath, final HTML html) { // Request the contents of the file // Add a bogus query to bypass the browser cache as advised by: // https://developer.mozilla.org/En/Using_XMLHttpRequest#Bypassing_the_cache RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getModuleBaseURL() + partialPath + "?ts=" + System.currentTimeMillis()); builder.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { html.setHTML("Cannot find resource"); } public void onResponseReceived(Request request, Response response) { html.setHTML(response.getText()); } }); // Send the request try { builder.send(); } catch (RequestException e) { GWT.log("Cannot fetch HTML source for " + partialPath, e); } }
From source file:org.waveprotocol.box.webclient.client.RemoteLocaleService.java
License:Apache License
@Override public void storeLocale(String locale) { RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, LOCALE_URL_BASE + "/?locale=" + locale); LOG.trace().log("Store locale"); requestBuilder.setCallback(new RequestCallback() { @Override//from w ww .jav a2 s . c o m public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() != Response.SC_OK) { LOG.error().log("Got back status code " + response.getStatusCode()); } else { LOG.error().log("Locale was stored"); } } @Override public void onError(Request request, Throwable exception) { LOG.error().log("Storing locale error: ", exception); } }); try { requestBuilder.send(); } catch (RequestException e) { LOG.error().log(e.getMessage()); } }
From source file:org.waveprotocol.box.webclient.client.SnapshotFetcher.java
License:Apache License
/** * Fetches a wave view snapshot from the static fetch servlet. * * @param waveId The wave to fetch/*from www . j a v a 2 s . com*/ * @param callback A callback through which the fetched wave will be returned. */ public static void fetchWave(WaveId waveId, final SimpleCallback<WaveViewData, Throwable> callback, final DocumentFactory<?> docFactory) { String url = getUrl(WaveRef.of(waveId)); LOG.trace().log("Fetching wavelet ", waveId.toString(), " at ", url); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { LOG.trace().log("Snapshot response recieved: ", response.getText()); // Pull the snapshot out of the response object and return it using // the provided callback function. if (response.getStatusCode() != Response.SC_OK) { callback.onFailure(new RequestException("Got back status code " + response.getStatusCode())); } else if (!response.getHeader("Content-Type").startsWith("application/json")) { callback.onFailure(new RuntimeException("Fetch service did not return json")); } else { WaveViewData waveView; try { WaveViewSnapshotJsoImpl snapshot = JsonMessage.parse(response.getText()); waveView = SnapshotSerializer.deserializeWave(snapshot, docFactory); } catch (OperationException e) { callback.onFailure(e); return; } catch (InvalidParticipantAddress e) { callback.onFailure(e); return; } catch (InvalidIdException e) { callback.onFailure(e); return; } catch (JsonException e) { callback.onFailure(e); return; } callback.onSuccess(waveView); } } @Override public void onError(Request request, Throwable exception) { LOG.error().log("Snapshot error: ", exception); callback.onFailure(exception); } }); try { requestBuilder.send(); } catch (RequestException e) { callback.onFailure(e); } }
From source file:org.waveprotocol.box.webclient.contact.FetchContactsBuilder.java
License:Apache License
public void fetchContacts(final Callback callback) { String url = getUrl(contactRequest); LOG.trace().log("Fetching contacts, timestamp " + contactRequest.getTimestamp()); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setCallback(new RequestCallback() { @Override// w ww . ja va2 s .c o m public void onResponseReceived(Request request, Response response) { LOG.trace().log("Contact response 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("Contact service did not return json"); } else { ContactResponseJsoImpl contactResponse; try { contactResponse = JsonMessage.parse(response.getText()); } catch (JsonException e) { callback.onFailure(e.getMessage()); return; } callback.onSuccess(contactResponse); } } @Override public void onError(Request request, Throwable e) { callback.onFailure(e.getMessage()); } }); try { requestBuilder.send(); } catch (RequestException e) { LOG.error().log(e.getMessage()); } }
From source file:org.waveprotocol.box.webclient.folder.FolderOperationServiceImpl.java
License:Apache License
@Override public void execute(String url, final Callback callback) { LOG.trace().log("Performing a folder operation: ", url); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setCallback(new RequestCallback() { @Override//from w ww .j a v a2s . c om public void onResponseReceived(Request request, Response response) { LOG.trace().log("Folder operation response received: ", response.getText()); if (response.getStatusCode() != Response.SC_OK) { callback.onFailure("Got back status code " + response.getStatusCode()); } else { callback.onSuccess(); } } @Override public void onError(Request request, Throwable exception) { LOG.error().log("Folder operation error: ", exception); callback.onFailure(exception.getMessage()); } }); try { requestBuilder.send(); } catch (RequestException e) { callback.onFailure(e.getMessage()); } }
From source file:org.waveprotocol.box.webclient.profile.FetchProfilesBuilder.java
License:Apache License
public void fetchProfiles(final Callback callback) { Preconditions.checkState(profileRequest != null); Preconditions.checkState(profileRequest.getAddresses() != null); String url = getUrl(profileRequest); LOG.trace().log("Fetching profiles for: [" + Joiner.on(",").join(profileRequest.getAddresses()) + "]"); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setCallback(new RequestCallback() { @Override/*w ww .j a v a 2 s. c o m*/ public void onResponseReceived(Request request, Response response) { LOG.trace().log("Profile response 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("Profile service did not return json"); } else { ProfileResponseJsoImpl profileResponse; try { profileResponse = JsonMessage.parse(response.getText()); } catch (JsonException e) { callback.onFailure(e.getMessage()); return; } callback.onSuccess(profileResponse); } } @Override public void onError(Request request, Throwable e) { callback.onFailure(e.getMessage()); } }); try { requestBuilder.send(); } catch (RequestException e) { LOG.error().log(e.getMessage()); } }
From source file:org.waveprotocol.box.webclient.search.JsoSearchBuilderImpl.java
License:Apache License
@Override public Request search(final Callback callback) { Preconditions.checkArgument(searchRequest != null, "call SearchBuilder.newSearch method to construct a new query"); Preconditions.checkArgument(searchRequest.getQuery() != null, "new query should be set"); String url = getUrl(searchRequest); LOG.trace().log("Performing a search query: [Query: ", searchRequest.getQuery(), ", Index: ", searchRequest.getIndex(), ", NumResults: ", searchRequest.getNumResults(), "]"); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setCallback(new RequestCallback() { @Override//from w ww . j av a 2 s . c o m public void onResponseReceived(Request request, Response response) { LOG.trace().log("Search response 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 { SearchResponseJsoImpl searchResponse; try { searchResponse = JsonMessage.parse(response.getText()); } catch (JsonException e) { callback.onFailure(e.getMessage()); return; } List<DigestSnapshot> digestSnapshots = SearchBuilderUtils .deserializeSearchResponse(searchResponse); callback.onSuccess(searchResponse.getTotalResults(), digestSnapshots); } } @Override public void onError(Request request, Throwable exception) { LOG.error().log("Search error: ", exception); callback.onFailure(exception.getMessage()); } }); try { return requestBuilder.send(); } catch (RequestException e) { callback.onFailure(e.getMessage()); return null; } }
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 . j a va2 s. 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()); } }