List of usage examples for com.google.gwt.http.client RequestBuilder sendRequest
public Request sendRequest(String requestData, RequestCallback callback) throws RequestException
From source file:com.kk_electronic.kkportal.core.rpc.Comet.java
License:Open Source License
private void poll() { if (!status.equals(WebSocketStatus.OPEN)) return;/*from www .j a v a 2 s . com*/ RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url + rxUrl); try { builder.sendRequest(null, rxCallback); } catch (RequestException e) { GWT.log("SOCKET-Failed to get responses to portalserver", e); } }
From source file:com.kk_electronic.kkportal.core.rpc.Comet.java
License:Open Source License
/** * The connect call POST an empty request to that and expects to receive a HTTP 201 Created * with the url of where it can receive server frames. * @param url when opening a connection this url is used * @param subprotocol not used yet, mostly here for compatibility with websocket protocol */// w w w . j a v a2 s. c o m @Override public void connect(String url, String subprotocol) { if (status.equals(WebSocketStatus.CLOSED)) { this.url = url; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); try { /* * for now we post not an real empty request but the json variant. * TODO: change the server so it can accept an empty body */ builder.sendRequest("[]", connectCallback); } catch (RequestException e) { GWT.log("SOCKET-Failed to connect to portalserver", e); } this.status = WebSocketStatus.CONNECTING; } }
From source file:com.kk_electronic.kkportal.core.rpc.Comet.java
License:Open Source License
/** * send a frame to the server. should not be called if {@link Comet#isTxBusy()} returns * true, since it this creates too many connections to the server. *//*w w w . j av a 2 s .co m*/ @Override public void send(String s) { if (!status.equals(WebSocketStatus.OPEN)) return; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url + rxUrl); try { builder.sendRequest(s, txCallback); } catch (RequestException e) { GWT.log("SOCKET-Failed to send requests to portalserver", e); } GWT.log("SOCKET-portalserver sending @" + new Date().getTime() + " : " + s); FrameSentEvent.fire(this); }
From source file:com.kk_electronic.kkportal.examples.rpc.PHPDispatcher.java
License:Open Source License
@Override public <T> void execute(final com.kk_electronic.kkportal.core.rpc.Request<T> orequest) { String url = "php/dispatch.php?i=" + orequest.getServerinterface().getName() + "&m=" + orequest.getMethod(); RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); StringBuilder sb = new StringBuilder(); try {/* ww w.ja va 2s.c o m*/ encoder.encode(orequest.getParams(), sb); } catch (UnableToSerialize e) { orequest.onFailure(e); } try { builder.sendRequest(sb.toString(), new RequestCallback() { @Override public void onError(com.google.gwt.http.client.Request request, Throwable exception) { orequest.onFailure(exception); } @Override public void onResponseReceived(Request request, Response response) { JSONValue result; try { result = encoder.decode(response.getText()); } catch (UnableToDeserialize e) { orequest.onFailure(e); return; } T decodedResult = null; try { decodedResult = encoder.validate(result, decodedResult, orequest.getReturnValueType()); } catch (UnableToDeserialize e) { orequest.onFailure(e); return; } orequest.onSuccess(decodedResult); } }); } catch (RequestException e) { orequest.onFailure(e); } }
From source file:com.kludgenics.dcpu16.compiler.client.CompileService.java
License:Apache License
public static void compile(String compiler, String filename, String body, RequestCallback callback) throws RequestException { JSONObject requestData = new JSONObject(); requestData.put("filename", new JSONString(filename)); requestData.put("contents", new JSONString(body)); // Send request to server and catch any errors. RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, COMPILE_URL); builder.sendRequest(requestData.toString(), callback); }
From source file:com.lorepo.icf.utils.XMLLoader.java
License:Open Source License
public void load(String url, ILoadListener l) { final String resolvedURL; listener = l;//from w w w . ja v a 2 s . c o m if (url.contains("://") || url.startsWith("/")) { resolvedURL = url; } else { resolvedURL = GWT.getHostPageBaseURL() + url; } RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, resolvedURL); errorString = null; try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { // Couldn't connect to server (could be timeout, SOP violation, etc.) errorString = "Error" + exception.toString(); } public void onResponseReceived(Request request, Response response) { // StatusCode == 0 when loading from local file try { if (response.getStatusCode() == 200 || response.getStatusCode() == 0) { Document dom = XMLParser.parse(response.getText()); initContentFromDOM(dom, resolvedURL); listener.onFinishedLoading(model); } else { // Handle the error. Can get the status text from response.getStatusText() errorString = "Wrong status: " + response.getText(); listener.onError(errorString); } } catch (Exception e) { listener.onError(e.getMessage()); } } }); } catch (RequestException e) { // Couldn't connect to server errorString = "Can't connect to the server: " + e.toString(); } catch (DOMException e) { errorString = "Could not parse file: " + url; } if (errorString != null) listener.onError(errorString); }
From source file:com.lushprojects.circuitjs1.client.circuitjs1.java
License:Open Source License
void loadLocale() { String url;/*from w ww. j a va 2 s . c o m*/ String lang = language(); GWT.log("got language " + lang); if (lang.startsWith("en")) { // no need to load locale file for English loadSimulator(); return; } if (lang.startsWith("de-")) lang = "de"; url = GWT.getModuleBaseURL() + "locale_" + lang + ".txt"; RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); try { requestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { GWT.log("File Error Response", exception); } public void onResponseReceived(Request request, Response response) { // processing goes here if (response.getStatusCode() == Response.SC_OK) { String text = response.getText(); processLocale(text); // end or processing } else { GWT.log("Bad file server response:" + response.getStatusText()); loadSimulator(); } } }); } catch (RequestException e) { GWT.log("failed file reading", e); } }
From source file:com.lushprojects.circuitjs1.client.CirSim.java
License:Open Source License
void getSetupList(final boolean openDefault) { String url;/* ww w .ja v a 2s.c om*/ url = GWT.getModuleBaseURL() + "setuplist.txt" + "?v=" + random.nextInt(); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); try { requestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { GWT.log("File Error Response", exception); } public void onResponseReceived(Request request, Response response) { // processing goes here if (response.getStatusCode() == Response.SC_OK) { String text = response.getText(); processSetupList(text.getBytes(), text.length(), openDefault); // end or processing } else GWT.log("Bad file server response:" + response.getStatusText()); } }); } catch (RequestException e) { GWT.log("failed file reading", e); } }
From source file:com.lushprojects.circuitjs1.client.CirSim.java
License:Open Source License
void loadFileFromURL(String url, final boolean centre) { RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); try {//from w w w . ja va 2 s . c o m requestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { GWT.log("File Error Response", exception); } public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == Response.SC_OK) { String text = response.getText(); readSetup(text.getBytes(), text.length(), false, centre); } else GWT.log("Bad file server response:" + response.getStatusText()); } }); } catch (RequestException e) { GWT.log("failed file reading", e); } }
From source file:com.lushprojects.circuitjs1.client.element.CirSim.java
License:Open Source License
public void getSetupList(final boolean openDefault) { String url;//from w ww . ja v a2 s .co m url = GWT.getModuleBaseURL() + "setuplist.txt" + "?v=" + random.nextInt(); RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); try { requestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { GWT.log("File Error Response", exception); } public void onResponseReceived(Request request, Response response) { // processing goes here if (response.getStatusCode() == Response.SC_OK) { String text = response.getText(); gui.processSetupList(text.getBytes(), text.length(), openDefault); // end or processing } else GWT.log("Bad file server response:" + response.getStatusText()); } }); } catch (RequestException e) { GWT.log("failed file reading", e); } }