Example usage for com.google.gwt.http.client RequestCallback onResponseReceived

List of usage examples for com.google.gwt.http.client RequestCallback onResponseReceived

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestCallback onResponseReceived.

Prototype

void onResponseReceived(Request request, Response response);

Source Link

Document

Called when a pending com.google.gwt.http.client.Request completes normally.

Usage

From source file:com.agnie.gwt.common.client.rpc.LoaderRequestTransport.java

License:Open Source License

protected RequestCallback createRequestCallback(final TransportReceiver receiver) {
    final RequestCallback callback = super.createRequestCallback(receiver);
    RequestCallback newCallback = new RequestCallback() {

        @Override//from w w w .  jav  a2 s.  c o  m
        public void onResponseReceived(Request request, Response response) {
            if (Response.SC_UNAUTHORIZED == response.getStatusCode()) {
                GWT.log("User session timed out or user logged out");
                Window.Location.assign(urlGenerator.getClientSideLoginURL(urlInfo, appDomain,
                        urlInfo.getParameter(QueryString.GWT_DEV_MODE.getKey())));
            } else {
                callback.onResponseReceived(request, response);
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
            callback.onError(request, exception);

        }
    };
    return newCallback;
}

From source file:com.google.gwt.sample.authrequest.client.SampleAuthRequestTransport.java

License:Apache License

@Override
protected RequestCallback createRequestCallback(final TransportReceiver receiver) {
    final RequestCallback superCallback = super.createRequestCallback(receiver);

    return new RequestCallback() {
        @Override//from   w w  w  .  j a  v  a2 s  .  com
        public void onError(Request request, Throwable exception) {
            superCallback.onError(request, exception);
        }

        @Override
        public void onResponseReceived(Request request, Response response) {
            /*
             * The GaeAuthFailure filter responds with Response.SC_UNAUTHORIZED and
             * adds a "login" url header if the user is not logged in. When we
             * receive that combo, post an event so that the app can handle things
             * as it sees fit.
             */
            if (Response.SC_UNAUTHORIZED == response.getStatusCode()) {
                String loginUrl = response.getHeader("login");
                if (loginUrl != null) {
                    /*
                     * Hand the receiver a non-fatal callback, so that
                     * com.google.web.bindery.requestfactory.shared.Receiver will not
                     * post a runtime exception.
                     */
                    receiver.onTransportFailure(new ServerFailure("Unauthenticated user", null, null, false));
                    eventBus.fireEvent(new SampleAuthenticationFailureEvent(loginUrl));
                    return;
                }
            }
            superCallback.onResponseReceived(request, response);
        }
    };
}

From source file:com.google.gwt.sample.gaerequest.client.GaeAuthRequestTransport.java

License:Apache License

@Override
protected RequestCallback createRequestCallback(final TransportReceiver receiver) {
    final RequestCallback superCallback = super.createRequestCallback(receiver);

    return new RequestCallback() {
        @Override//w  w w.ja  va  2 s  .  co m
        public void onError(Request request, Throwable exception) {
            superCallback.onError(request, exception);
        }

        @Override
        public void onResponseReceived(Request request, Response response) {
            /*
             * The GaeAuthFailure filter responds with Response.SC_UNAUTHORIZED and
             * adds a "login" url header if the user is not logged in. When we
             * receive that combo, post an event so that the app can handle things
             * as it sees fit.
             */
            if (Response.SC_UNAUTHORIZED == response.getStatusCode()) {
                String loginUrl = response.getHeader("login");
                if (loginUrl != null) {
                    /*
                     * Hand the receiver a non-fatal callback, so that
                     * com.google.web.bindery.requestfactory.shared.Receiver will not
                     * post a runtime exception.
                     */
                    receiver.onTransportFailure(new ServerFailure("Unauthenticated user", null, null, false));
                    eventBus.fireEvent(new GaeAuthenticationFailureEvent(loginUrl));
                    return;
                }
            }
            superCallback.onResponseReceived(request, response);
        }
    };
}

From source file:com.hiramchirino.restygwt.client.Method.java

License:Apache License

public void send(final RequestCallback callback) throws RequestException {
    builder.setCallback(new RequestCallback() {
        public void onResponseReceived(Request request, Response response) {
            callback.onResponseReceived(request, response);
        }//from   w w w  .  j  a va  2s  .  co  m

        public void onError(Request request, Throwable exception) {
            callback.onResponseReceived(request, response);
        }
    });
    GWT.log("Sending http request: " + builder.getHTTPMethod() + " " + builder.getUrl(), null);
    String content = builder.getRequestData();
    if (content != null && content.length() > 0) {
        GWT.log(content, null);
    }
    request = builder.send();
}

From source file:com.nanosim.client.ContentWidget.java

License:Apache License

/**
 * Load the contents of a remote file into the specified widget.
 * //from   ww w .  ja va2 s  .c  o  m
 * @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\">";
    }
    DOM.setStyleAttribute(target.getElement(), "textAlign", "left");
    target.setHTML("&nbsp;&nbsp;" + 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:com.totsp.gwittir.rest.client.transports.HTTPTransport.java

License:Open Source License

/** Executes a request and handles the pre and post hooks
 *
 * @param builder the initial builder/*w  w w.java2  s.  com*/
 * @param callback the request callback to pass to the final builder
 * @return a RequestControl implementation to return back out.
 */
protected XHRRequestControl doRequest(RequestBuilder builder, final RequestCallback callback) {
    doPreHook(builder);

    RequestCallback innerCallback = new RequestCallback() {
        public void onResponseReceived(Request request, Response response) {
            response = doPostHook(response);
            callback.onResponseReceived(request, response);
        }

        public void onError(Request request, Throwable exception) {
            callback.onError(request, exception);
        }
    };

    builder.setCallback(innerCallback);

    try {
        return new XHRRequestControl(builder.send());
    } catch (RequestException e) {
        callback.onError(null, e);

        return new XHRRequestControl(null);
    }
}

From source file:es.deusto.weblab.client.comm.FakeWebLabRequestBuilder.java

License:Open Source License

@Override
public Request sendRequest(String header, RequestCallback callback) throws RequestException {
    if (this.nextAnswer) {
        callback.onResponseReceived(null, this.getResponseToSend());
    } else if (this.nextThrow) {
        throw this.toThrow;
    } else if (this.nextError) {
        callback.onError(null, this.toError);
    }// www.  jav a2s  .  c om
    return null;
}

From source file:fi.jasoft.uidlcompressor.client.ui.UIDLCompressorApplicationConnection.java

License:Apache License

@Override
protected void doAsyncUIDLRequest(String uri, String payload, final RequestCallback requestCallback)
        throws RequestException {

    // Wrap the request callback
    RequestCallback wrappedCallback = new RequestCallback() {
        public void onResponseReceived(Request request, final Response response) {

            Response jsonResponse = new Response() {

                /*/*from   w w  w  .j a va  2 s .  co  m*/
                 * Caching the decoded json string in case getText() is
                 * called several times
                 */
                private String decodedJson;

                @Override
                public String getText() {
                    String base64 = response.getText();
                    if (base64.startsWith("for(")) {
                        // Server is sending json, digress
                        return base64;
                    }

                    if (decodedJson == null) {
                        long start = new Date().getTime();
                        decodedJson = decompressBase64Gzip(base64);
                        long end = new Date().getTime();
                        VConsole.log("Decoding JSON took " + (end - start) + "ms");
                    }

                    return decodedJson;
                }

                @Override
                public String getStatusText() {
                    return response.getStatusText();
                }

                @Override
                public int getStatusCode() {
                    return response.getStatusCode();
                }

                @Override
                public String getHeadersAsString() {
                    return response.getHeadersAsString();
                }

                @Override
                public Header[] getHeaders() {
                    return response.getHeaders();
                }

                @Override
                public String getHeader(String header) {
                    return response.getHeader(header);
                }
            };

            requestCallback.onResponseReceived(request, jsonResponse);
        }

        public void onError(Request request, Throwable exception) {
            requestCallback.onError(request, exception);
        }
    };

    // TODO Add payload compression here
    super.doAsyncUIDLRequest(uri, payload, wrappedCallback);
}

From source file:n3phele.client.presenter.helpers.RequestWithProgressDialog.java

License:Open Source License

public Request sendRequest(final String requestData, final RequestCallback callback) throws RequestException {
    request = rb.sendRequest(requestData, new RequestCallback() {
        @Override/*from   w ww. ja v a  2  s  .co  m*/
        public void onResponseReceived(Request request, Response response) {
            hideLoadingMessage();
            callback.onResponseReceived(request, response);

        }

        @Override
        public void onError(Request request, Throwable exception) {
            GWT.log(exception.toString(), exception);
            if (retries-- <= 0) {
                alert("Failure " + exception.toString());
                callback.onError(request, exception);
            } else {
                try {
                    alert("Failure " + exception.toString() + " retrying..");
                    request = sendRequest(requestData, callback);
                } catch (RequestException e) {
                    this.onError(request, e);
                }
            }
        }
    });
    if (request != null)
        createLoadingMessage();
    return request;
}

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.
 * /* w ww .  j  av a2  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("&nbsp;&nbsp;" + 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);
    }
}