List of usage examples for com.google.gwt.http.client RequestBuilder GET
Method GET
To view the source code for com.google.gwt.http.client RequestBuilder GET.
Click Source Link
From source file:net.autosauler.ballance.client.gui.ChangeLogPanel.java
License:Apache License
/** * Instantiates a new change log panel./* w w w. ja va 2s. c om*/ */ private ChangeLogPanel() { MainPanel.setCommInfo(true); try { new RequestBuilder(RequestBuilder.GET, "CHANGELOG").sendRequest("", new RequestCallback() { @Override public void onError(Request res, Throwable throwable) { MainPanel.setCommInfo(false); Log.error(throwable.getMessage()); } @Override public void onResponseReceived(Request request, Response response) { MainPanel.setCommInfo(false); String text = response.getText(); HTML w = new HTML("<p>" + text + "</p>"); d.setWidget(w); } }); } catch (RequestException e) { MainPanel.setCommInfo(false); Log.error(e.getMessage()); } d = new DecoratorPanel(); d.setWidth("100%"); initWidget(d); }
From source file:net.dancioi.jcsphotogallery.client.model.ReadXMLGeneric.java
License:Open Source License
/** * Gets the XML file from http server.//w w w . j ava2s. c om */ public void readXmlFile(final String file, final int flag) { RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, file); try { requestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { showException("Error sending request"); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { parseXMLString(response.getText(), flag); // careful here, this is an asynchronous callback. } else if (404 == response.getStatusCode()) { showException("File " + file + " not found on server. Wrong name or missing."); } else { showException("Other exception on GET the " + file + " file"); } } }); } catch (RequestException ex) { new ReadException("Error sending request"); } }
From source file:net.opentsdb.tsd.client.QueryUi.java
License:Open Source License
private void asyncGetJson(final String url, final GotJsonCallback callback) { final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); try {/* w ww. j a va 2s .c o m*/ builder.sendRequest(null, new RequestCallback() { public void onError(final Request request, final Throwable e) { displayError("Failed to get " + url + ": " + e.getMessage()); // Since we don't call the callback we've been given, reset this // bit of state as we're not going to retry anything right now. pending_requests = 0; } public void onResponseReceived(final Request request, final Response response) { final int code = response.getStatusCode(); if (code == Response.SC_OK) { clearError(); callback.got(JSONParser.parse(response.getText())); return; } else if (code >= Response.SC_BAD_REQUEST) { // 400+ => Oops. // Since we don't call the callback we've been given, reset this // bit of state as we're not going to retry anything right now. pending_requests = 0; String err = response.getText(); // If the response looks like a JSON object, it probably contains // an error message. if (!err.isEmpty() && err.charAt(0) == '{') { final JSONValue json = JSONParser.parse(err); final JSONObject result = json == null ? null : json.isObject(); final JSONValue jerr = result == null ? null : result.get("err"); final JSONString serr = jerr == null ? null : jerr.isString(); err = serr.stringValue(); // If the error message has multiple lines (which is common if // it contains a stack trace), show only the first line and // hide the rest in a panel users can expand. final int newline = err.indexOf('\n', 1); final String msg = "Request failed: " + response.getStatusText(); if (newline < 0) { displayError(msg + ": " + err); } else { displayError(msg); final DisclosurePanel dp = new DisclosurePanel(err.substring(0, newline)); RootPanel.get("queryuimain").add(dp); // Attach the widget. final InlineLabel content = new InlineLabel(err.substring(newline, err.length())); content.addStyleName("fwf"); // For readable stack traces. dp.setContent(content); current_error.getElement().appendChild(dp.getElement()); } } else { displayError("Request failed while getting " + url + ": " + response.getStatusText()); // Since we don't call the callback we've been given, reset this // bit of state as we're not going to retry anything right now. pending_requests = 0; } graphstatus.setText(""); } } }); } catch (RequestException e) { displayError("Failed to get " + url + ": " + e.getMessage()); } }
From source file:net.opentsdb.tsd.client.RemoteOracle.java
License:Open Source License
@Override public void requestSuggestions(final Request request, final Callback callback) { if (current != null) { pending_req = request;// w w w . ja v a2 s.c o m pending_cb = callback; return; } current = callback; { final String this_query = request.getQuery(); // Check if we can serve this from our local cache, without even talking // to the server. This is possible if either of those is true: // 1. We've already seen this query recently. // 2. This new query precedes another one and the user basically just // typed another letter, so if the new query is "less than" the last // result we got from the server, we know we already cached the full // range of results covering the new request. if ((last_query != null && last_query.compareTo(this_query) <= 0 && this_query.compareTo(last_suggestion) < 0) || queries_seen.check(this_query)) { current = null; cache.requestSuggestions(request, callback); return; } last_query = this_query; } final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, SUGGEST_URL + type + "&q=" + last_query); try { builder.sendRequest(null, new RequestCallback() { public void onError(final com.google.gwt.http.client.Request r, final Throwable e) { current = null; // Something bad happened, drop the current request. if (pending_req != null) { // But if we have another waiting... requestSuggestions(pending_req, pending_cb); // ... try it now. } } // Need to use fully-qualified names as this class inherits already // from a pair of inner classes called Request / Response :-/ public void onResponseReceived(final com.google.gwt.http.client.Request r, final com.google.gwt.http.client.Response response) { if (response.getStatusCode() == com.google.gwt.http.client.Response.SC_OK // Is this response still relevant to what the requester wants? && requester.getText().startsWith(last_query)) { final JSONValue json = JSONParser.parse(response.getText()); // In case this request returned nothing, we pretend the last // suggestion ended with the largest character possible, so we // won't send more requests to the server if the user keeps // adding extra characters. last_suggestion = last_query + "\377"; if (json != null && json.isArray() != null) { final JSONArray results = json.isArray(); final int n = Math.min(request.getLimit(), results.size()); for (int i = 0; i < n; i++) { final JSONValue suggestion = results.get(i); if (suggestion == null || suggestion.isString() == null) { continue; } final String suggestionstr = suggestion.isString().stringValue(); last_suggestion = suggestionstr; cache.add(suggestionstr); } cache.requestSuggestions(request, callback); pending_req = null; pending_cb = null; } } current = null; // Regardless of what happened above, this is done. if (pending_req != null) { final Request req = pending_req; final Callback cb = pending_cb; pending_req = null; pending_cb = null; requestSuggestions(req, cb); } } }); } catch (RequestException ignore) { } }
From source file:net.s17fabu.vip.gwt.showcase.client.ContentWidget.java
License:Apache License
/** * Load the contents of a remote file into the specified widget. * /* ww w.ja va 2 s.c om*/ * @param url a partial path relative to the module base URL * @param target the target Widget to place the contents * @param callback the callback when the call completes */ protected void requestSourceContents(String url, final HTML target, final RequestCallback callback) { // Show the loading image if (loadingImage == null) { loadingImage = "<img src=\"" + GWT.getModuleBaseURL() + "images/loading.gif\">"; } target.setDirection(HasDirection.Direction.LTR); DOM.setStyleAttribute(target.getElement(), "textAlign", "left"); target.setHTML(" " + loadingImage); // Request the contents of the file RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, GWT.getModuleBaseURL() + url); RequestCallback realCallback = new RequestCallback() { public void onError(Request request, Throwable exception) { target.setHTML("Cannot find resource"); if (callback != null) { callback.onError(request, exception); } } public void onResponseReceived(Request request, Response response) { target.setHTML(response.getText()); if (callback != null) { callback.onResponseReceived(request, response); } } }; builder.setCallback(realCallback); // Send the request Request request = null; try { request = builder.send(); } catch (RequestException e) { realCallback.onError(request, e); } }
From source file:net.skyesoft.nhs.dka.client.Audit.java
License:Apache License
public void loadPreviousData(String studyNo) { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, Defines.FORM_HANDLER + "?mode=loaddata&StudyNo=" + studyNo + "&TableName=" + PAGE_ID + "&" + Utils.DATE_PARAM + "=" + Utils.getDate()); builder.setUser(Defines.USERNAME);/*from ww w.ja v a2 s . co m*/ builder.setPassword(Defines.PASSWORD); builder.setTimeoutMillis(Defines.TIMEOUT); try { builder.sendRequest(null, new PreviousDataLoader()); } catch (RequestException re) { Window.alert("Failed to load the data for Audit : " + re.getMessage()); } }
From source file:next.celebs.api.API.java
License:Apache License
public void getYahooImages(final Response<ArrayList<YahooPhoto>> response) { // JsonArrayReader<YahooPhoto, JsArray<? extends JavaScriptObject>> reader = new JsonArrayReader<YahooPhoto, // JsArray<? extends JavaScriptObject>>() { // @Override/*from w ww.j a va 2 s . c o m*/ // public void read(ArrayList<YahooPhoto> data, String jsonData) { // response.read(data); // response.afterRead(jsonData); // } // }; String url = "http://search.yahooapis.com/ImageSearchService/V1/imageSearch?query=victoria%2Bsecret&appid=rV3eqIDV34GjBZBX2fRuLJ5qkmKe2qyRXcN_ZtBJv0Eo6Uh7b9OUPx.MbRXI8C6u0xo-&results=5&output=json&"; // String url = // "/yapi/ImageSearchService/V1/imageSearch?query=victoria%2Bsecret&appid=rV3eqIDV34GjBZBX2fRuLJ5qkmKe2qyRXcN_ZtBJv0Eo6Uh7b9OUPx.MbRXI8C6u0xo-&results=5&output=json&"; // HTTP.doGet(url, null, reader); // String url = "http://127.0.0.1:8888/"; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); JsonArrayReader<YahooPhoto, JsArray<? extends JavaScriptObject>> reader = new JsonArrayReader<YahooPhoto, JsArray<? extends JavaScriptObject>>() { @Override public void read(ArrayList<YahooPhoto> data, String jsonData) { response.read(data); response.afterRead(jsonData); } }; try { class ResponseReader2 extends ResponseReader { @Override public String getName() { return "ResponseReader2"; } @Override public void onSuccess(com.google.gwt.http.client.Response resp) { Window.alert("succss: " + resp.getText()); } } Window.alert("before GET '" + url + "'"); builder.sendRequest(null, new Callback_(reader)); } catch (RequestException e) { Window.alert("doGet:exc " + e.getMessage()); Log.error("RequestException: " + e.getMessage()); // responseReader.onError(null, e); } }
From source file:next.celebs.api.HTTP.java
License:Apache License
public static void doGet(String url, ResponseReader responseReader) { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try {//from w ww .j a va 2 s .c o m builder.sendRequest(null, new Callback_(responseReader)); } catch (RequestException e) { Window.alert("doGet:exc " + e.getMessage()); Log.error("RequestException: " + e.getMessage()); responseReader.onError(null, e); } }
From source file:next.celebs.api.HTTP.java
License:Apache License
public static void doGetRelaxed(String url, ResponseReader responseReader) { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try {/*from w w w. j av a 2 s. c o m*/ builder.sendRequest(null, new RelaxedCallback_(responseReader)); } catch (RequestException e) { responseReader.onError(null, e); } }
From source file:next.celebs.dao.WikipediaDao.java
License:Apache License
public static void getWiki(String url, ResponseReader responseReader) { RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try {//ww w . j ava 2 s . c o m builder.sendRequest(null, new Callback_(responseReader)); } catch (RequestException e) { Log.error("RequestException: " + e.getMessage()); responseReader.onError(null, e); } }