Refine search
public void onResponseReceived(Request request, Response response) { if (response.getStatusCode() == 0) { Utils.handleNetworkConnectionError(); } else { String error = response.getHeader("Error"); String errorType = response.getHeader("ErrorType"); if (!isEmpty(errorType) && "TempCredentials".equals(errorType)) { //change password ChangePasswordDialog.Listener listener = new ChangePasswordDialog.Listener() { @Override public void onChangePassword() { view.clearMessages(); } @Override public void onCancel() { } }; ChangePasswordDialog.showChangePasswordDialog(listener, userName, Utils.messages.tempCredentials()); } else if (!isEmpty(error)) { view.setErrorMessage(error); } else { view.clearMessages(); redirectToModule("kaaAdmin"); } } } });
@Override public String getResultAsString () { return response.getText(); }
@Override public Map<String, List<String>> getHeaders () { Map<String, List<String>> headers = new HashMap<String, List<String>>(); Header[] responseHeaders = response.getHeaders(); for (int i = 0; i < responseHeaders.length; i++) { Header header = responseHeaders[i]; if (header != null) { String headerName = responseHeaders[i].getName(); List<String> headerValues = headers.get(headerName); if (headerValues == null) { headerValues = new ArrayList<String>(); headers.put(headerName, headerValues); } headerValues.add(responseHeaders[i].getValue()); } } return headers; }
@Override public void onResponseReceived(final Request request, final Response response) { validateContentType(response); final int statusCode = response.getStatusCode(); if (statusCode != 200) { switch (statusCode) { case 300: case 301: case 302: case 303: case 304: case 305: case 307: break; default: onError(request, new TransportIOException("unexpected response code: " + statusCode, statusCode, response .getStatusText()), statusCode); return; } } notifyConnected(); BusToolsCli.decodeToCallback(response.getText(), messageBus); if (pendingRequests.isEmpty()) { schedule(); } }
public void onResponseReceived(Request request, Response response) { wireLogger.finest("Response received"); if (Response.SC_OK == response.getStatusCode()) { String text = response.getText(); receiver.onTransportSuccess(text); } else { String message = SERVER_ERROR + " " + response.getStatusCode() + " " + response.getText(); wireLogger.severe(message); receiver.onTransportFailure(new ServerFailure(message)); } } };
public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode() || 201 == response.getStatusCode()) { String content = response.getText(); if (!redirectHack(content)) { eventBus.fireEvent(new StoreContentAdapter.StoreContentEvent(identifier, content, callback, false)); } } else if (Response.SC_UNAUTHORIZED == response.getStatusCode()) { handleUnauthorised(response); } else if (203 == response.getStatusCode()) { String content = response.getHeader("X-Application-Error-Code"); eventBus.fireEvent(new StoreContentAdapter.StoreContentEvent(identifier, content, callback, true)); } else { eventBus.fireEvent(new StoreContentAdapter.StoreContentEvent(identifier, response.getStatusText(), callback, true)); } } });
String url = "http://www.myserver.com/getData?type=3"; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try { Request request = builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { // Couldn't connect to server (could be timeout, SOP violation, etc.) } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { // Process the response in response.getText() } else { // Handle the error. Can get the status text from response.getStatusText() } } }); } catch (RequestException e) { // Couldn't connect to server }
// Send request to server and catch any errors. RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url); try { Request request = builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable exception) { displayError("Couldn't retrieve JSON"); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { updateTable(JsonUtils.safeEval(response.getText())); } else { displayError("Couldn't retrieve JSON (" + response.getStatusText() + ")"); } } }); } catch (RequestException e) { displayError("Couldn't retrieve JSON"); }
public FailedResponseException(Response response) { super(response.getStatusText(), response.getStatusCode()); this.response = response; }
RequestBuilder requestBuilder = new RequestBuilder( RequestBuilder.GET, "yourfile.txt" ); try { requestBuilder.sendRequest( null, new RequestCallback(){ public void onError(Request request, Throwable exception) { GWT.log( "failed file reading", exception ); } public void onResponseReceived(Request request, Response response) { String result=response.getText(); }} ); } catch (RequestException e) { GWT.log( "failed file reading", e ); }
private static void validateContentType(final Response response) { int statusCode = response.getStatusCode(); // in case the response is OK (200), then the content type always has to be 'application/json' if (statusCode == 200) { String contentType = response.getHeader("Content-Type"); if (!contentType.contains("application/json")) { String content = response.getText(); throw new InvalidBusContentException(contentType, content); } } }
public static void httpGetFile(final String url, final AsyncCallback<String> callback) { final RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url); rb.setCallback(new RequestCallback() { public void onResponseReceived(Request request, Response response) { try { final int responseCode = response.getStatusCode() / 100; if (url.startsWith("file:/") || (responseCode == 2)) { callback.onSuccess(response.getText()); } else { callback.onFailure(new IllegalStateException("HttpError#" + response.getStatusCode() + " - " + response.getStatusText())); } } catch (Throwable e) { callback.onFailure(e); } } public void onError(Request request, Throwable exception) { callback.onFailure(exception); } }); try { rb.send(); } catch (RequestException e) { callback.onFailure(e); } }
public void getMessageXml(String requestData, final AsyncCallback<String> callback) { try { // Modify for your application. RequestBuilder rb = new RequestBuilder(Method.GET, "http://www.mycompany.com/getMessageXml"); rb.sendRequest(requestData, new RequestCallback() { @Override public void onError(Request request, Throwable caught) { callback.onFailure(caught); } @Override public void onResponseReceived(Request request, Response response) { if (Response.SC_OK == response.getStatusCode()) { callback.onSuccess(response.getText()); } else { // Use a correctly typed exception here. callback.onFailure(...); } } }); } catch (RequestException rex) { callback.onFailure(rex); } }
@Override public final void doError(Request request, Response response) { int code = response.getStatusCode(); /** * retry only on GET requests that are no redirects (301, 302, 303) */ if (code != 301 && code != 302 && code != 303 && code != 404 && (method.builder == null // jsonp method do not have a builder !! || method.builder.getHTTPMethod().equalsIgnoreCase("get"))) { handleErrorGracefully(request, response, requestCallback); } else { if (LogConfiguration.loggingIsEnabled()) { Logger.getLogger(RetryingFilterawareRequestCallback.class.getName()).severe( "ERROR with non-GET method: " + method.builder.getHTTPMethod() + " " + method.builder.getUrl() + ", " + response.getStatusText()); } /** * RuntimeException token from * com.google.gwt.http.client.Request#fireOnResponseReceived() */ requestCallback .onError(request, new FailedStatusCodeException(response.getStatusText(), response.getStatusCode())); } }
public void onResponseReceived(com.google.gwt.http.client.Request gwtRequest, com.google.gwt.http.client.Response gwtResponse) { final String responseType = xhr.getResponseType(); final Payload payload = responseType.isEmpty() || responseType.equalsIgnoreCase("text") ? new Payload(xhr.getResponseText()) : new Payload(xhr.getResponse()); final SerializedResponseImpl response = new SerializedResponseImpl(gwtResponse.getStatusText(), gwtResponse.getStatusCode(), new Headers(gwtResponse.getHeaders()), ResponseType.of(responseType), payload); evalResponse(request, deferred, resolveType, parametrizedType, response); }
@Override public void onResponseReceived(final Request request, final Response response) { callback.onResponse(new NRestingResponse(response.getStatusCode(), response.getText(), new NRestingHeaders(response.getHeaders()).setOptions(head), type, new NRestingRequest(builder.getUrl(), head, type, cntr, time, request), System.currentTimeMillis() - time)); }
@Override protected void cacheResult(Method method, Response response) { CacheKey cacheKey; if (response.getStatusCode() == Response.SC_CREATED && response.getHeader("Location") != null) { String uri; if (response.getHeader("Location").startsWith("http")) { uri = response.getHeader("Location"); } else { // TODO very fragile way of getting the URL uri = method.builder.getUrl().replaceFirst("/[^/]*$", "") + response.getHeader("Location"); } cacheKey = new UrlCacheKey(uri); } else { cacheKey = cacheKey(method.builder); } if (RequestBuilder.DELETE.toString().equalsIgnoreCase(method.builder.getHTTPMethod()) || // in case of a conflict the next GET request needs to // go remote !! response.getStatusCode() == Response.SC_CONFLICT) { cache.remove(cacheKey); } else if (method.builder.getUrl().matches(".*/[0-9]+$")) { // if url has an ID at the end then treat it as single entity // otherwise assume a collection which are not cached. cache.putResult(cacheKey, response); } } }
private void getHtml(String url) { RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url); rb.setCallback(new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { HTMLPanel html = new HTMLPanel(response.getText()); // Now you have a widget with the requested page // thus you may do whatever you want with it. } @Override public void onError(Request request, Throwable exception) { Log.error("error " + exception); } }); try { rb.send(); } catch (RequestException e) { Log.error("error " + e); } }
@Override public void onResponseReceived( final Request request, final Response response ) { final int statusCode = response.getStatusCode(); if ( Response.SC_OK == statusCode ) { final boolean messageComplete = "1".equals( response.getHeader( SharedConstants.REQUEST_COMPLETE_HEADER ) ); _r.onSuccess( messageComplete, () -> _callback.onResponseReceived( request, response ) ); } else { final InvalidHttpResponseException error = new InvalidHttpResponseException( statusCode, response.getStatusText() ); _r.onFailure( () -> _callback.onError( request, error ) ); } }
if(response.getStatusCode() == 409) { //wrong client version Navigator.closeEveryPopUp(); Navigator.showUncloseablePopUp("Login again!", rb.setCallback(new RequestCallbackWrapper(rb.getCallback()));