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:org.apache.hupa.client.ioc.AppGinModule.java

License:Apache License

@Provides
@Singleton/* w  w w  .j  a va  2s.c  o  m*/
HupaRequestFactory getRequestFactory(final EventBus eventBus) {
    InstrumentationLoggerProvider.get().instrument(
            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x10x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x2_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x10x0");
    InstrumentationLoggerProvider.get()
            .instrument("org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f");
    InstrumentationLoggerProvider.get().instrument(
            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x00x10x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x00x1");
    HupaRequestFactory rf = GWT.create(HupaRequestFactory.class);
    InstrumentationLoggerProvider.get().instrument(
            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1");
    rf.initialize(eventBus, new DefaultRequestTransport() {
        @Override
        protected RequestCallback createRequestCallback(TransportReceiver receiver) {
            InstrumentationLoggerProvider.get().instrument(
                    "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x175546543");
            InstrumentationLoggerProvider.get().instrument(
                    "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x20x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x3_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x2_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x1");
            InstrumentationLoggerProvider.get().instrument(
                    "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x00x20x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x00x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x00x2");
            final RequestCallback superCallback = super.createRequestCallback(receiver);
            InstrumentationLoggerProvider.get().instrument(
                    "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x0");
            return new RequestCallback() {
                @Override
                public void onResponseReceived(Request request, Response response) {
                    InstrumentationLoggerProvider.get().instrument(
                            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f");
                    InstrumentationLoggerProvider.get().instrument(
                            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x2_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x30x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x3_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x20x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x4_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x0");
                    InstrumentationLoggerProvider.get().instrument(
                            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x00x0");
                    if (response.getText().contains(User.NOT_FOUND)) {
                        InstrumentationLoggerProvider.get().instrument(
                                "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x10x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x10x00x00x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x10x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x10x00x00x0");
                        eventBus.fireEvent(new LogoutEvent(null));
                    } else {
                        InstrumentationLoggerProvider.get().instrument(
                                "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x2");
                        InstrumentationLoggerProvider.get().instrument(
                                "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x20x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x1163a3f9f0x40x00x20x0");
                        superCallback.onResponseReceived(request, response);
                    }
                }

                @Override
                public void onError(Request request, Throwable exception) {
                    InstrumentationLoggerProvider.get().instrument(
                            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c13");
                    InstrumentationLoggerProvider.get().instrument(
                            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x30x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x3_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x1_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x2_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x20x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x4");
                    InstrumentationLoggerProvider.get().instrument(
                            "org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x40x00x0_____org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x10x00x00x1755465430x30x10x00x12a6f6c130x40x0");
                    superCallback.onError(request, exception);
                }
            };
        }
    });
    InstrumentationLoggerProvider.get()
            .instrument("org_apache_hupa_client_ioc_AppGinModule_java0x0d734f59aa2505a3f0x20x2");
    return rf;
}

From source file:org.fusesource.restygwt.client.callback.CachingCallbackFilter.java

License:Apache License

/**
 * the real filter method, called independent of the response code
 *
 * TODO method.getResponse() is not equal to response. unfortunately
 *///from w  w  w  . j av a 2 s . c  om
@Override
public RequestCallback filter(final Method method, final Response response, RequestCallback callback) {
    final int code = response.getStatusCode();

    final CacheKey ck = cacheKey(method.builder);
    final List<RequestCallback> removedCallbacks = cache.removeCallbacks(ck);

    if (removedCallbacks != null) {
        callback = new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                if (GWT.isClient() && LogConfiguration.loggingIsEnabled()) {
                    Logger.getLogger(CachingCallbackFilter.class.getName())
                            .finer("call " + removedCallbacks.size() + " more queued callbacks for " + ck);
                }

                // call all callbacks found in cache
                for (RequestCallback cb : removedCallbacks) {
                    cb.onResponseReceived(request, response);
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                if (LogConfiguration.loggingIsEnabled()) {
                    Logger.getLogger(CachingCallbackFilter.class.getName())
                            .severe("cannot call " + (removedCallbacks.size() + 1) + " callbacks for " + ck
                                    + " due to error: " + exception.getMessage());
                }

                if (LogConfiguration.loggingIsEnabled()) {
                    Logger.getLogger(CachingCallbackFilter.class.getName())
                            .finer("call " + removedCallbacks.size() + " more queued callbacks for " + ck);
                }

                // and all the others, found in cache
                for (RequestCallback cb : removedCallbacks) {
                    cb.onError(request, exception);
                }
            }
        };
    } else {
        if (GWT.isClient() && LogConfiguration.loggingIsEnabled()) {
            Logger.getLogger(CachingCallbackFilter.class.getName())
                    .finer("removed one or no " + "callback for cachekey " + ck);
        }
    }

    if (isCachingStatusCode(code)) {
        cacheResult(method, response);
        return callback;
    }

    if (GWT.isClient() && LogConfiguration.loggingIsEnabled()) {
        Logger.getLogger(CachingCallbackFilter.class.getName())
                .info("cannot cache due to invalid response code: " + code);
    }
    return callback;
}

From source file:org.fusesource.restygwt.client.dispatcher.CachingRetryingDispatcher.java

License:Apache License

public Request send(Method method, RequestBuilder builder) throws RequestException {

    RequestCallback outerRequestCallback = builder.getCallback();
    final CacheKey cacheKey = new CacheKey(builder);

    final Response cachedResponse = cacheStorage.getResultOrReturnNull(cacheKey);

    if (cachedResponse != null) {

        outerRequestCallback.onResponseReceived(null, cachedResponse);
        return null;

    } else {//from www .  j ava  2  s  . c  om

        RequestCallback retryingCallback = new CachingRetryingCallback(builder, outerRequestCallback);
        builder.setCallback(retryingCallback);

        GWT.log("Sending http request: " + builder.getHTTPMethod() + " " + builder.getUrl() + " ,timeout:"
                + builder.getTimeoutMillis(), null);

        String content = builder.getRequestData();

        if (content != null && content.length() > 0) {
            GWT.log(content, null);
        }

        return builder.send();
    }

}

From source file:org.jboss.errai.bus.client.framework.transports.HttpPollingHandler.java

License:Apache License

/**
 * Sends the given string oon the outbound communication channel (as a POST
 * request to the server)./*from   w ww. ja v a  2  s .c  o  m*/
 *
 * @param payload
 *     The message to send. It is sent verbatim.
 * @param callback
 *     The callback to receive success or error notification. Note that
 *     this callback IS NOT CALLED if the request is cancelled.
 * @param extraParameters
 *     Extra paramets to include in the HTTP request (key is parameter name;
 *     value is parameter value).
 *
 * @throws com.google.gwt.http.client.RequestException
 *     if the request cannot be sent at all.
 */
public Request sendPollingRequest(final String payload, final Map<String, String> extraParameters,
        final RequestCallback callback) throws RequestException {

    // LogUtil.log("[bus] sendPollingRequest(" + payload + ")");

    final String serviceEntryPoint;
    final Map<String, String> parmsMap;
    final boolean waitChannel;
    boolean activeWaitChannel = false;

    final Iterator<RxInfo> iterator = pendingRequests.iterator();
    while (iterator.hasNext()) {
        final RxInfo pendingRx = iterator.next();
        if (pendingRx.getRequest().isPending() && pendingRx.isWaiting()) {
            //  LogUtil.log("[bus] ABORT SEND: " + pendingRx + " is waiting" );
            // return null;
            activeWaitChannel = true;
        }

        if (!pendingRx.getRequest().isPending()) {
            iterator.remove();
        }
    }

    if (!activeWaitChannel && receiveCommCallback.canWait() && !rxActive) {
        parmsMap = new HashMap<String, String>(extraParameters);
        parmsMap.put("wait", "1");
        serviceEntryPoint = messageBus.getInServiceEntryPoint();
        waitChannel = true;
    } else {
        parmsMap = extraParameters;
        serviceEntryPoint = messageBus.getOutServiceEntryPoint();
        waitChannel = false;
    }

    rxActive = true;

    final StringBuilder extraParmsString = new StringBuilder();
    for (final Map.Entry<String, String> entry : parmsMap.entrySet()) {
        extraParmsString.append("&").append(URL.encodePathSegment(entry.getKey())).append("=")
                .append(URL.encodePathSegment(entry.getValue()));
    }

    final long latencyTime = System.currentTimeMillis();

    final RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
            URL.encode(messageBus.getApplicationLocation(serviceEntryPoint)) + "?z=" + getNextRequestNumber()
                    + "&clientId=" + URL.encodePathSegment(messageBus.getClientId())
                    + extraParmsString.toString());
    builder.setHeader("Content-Type", "application/json; charset=utf-8");

    final RxInfo rxInfo = new RxInfo(System.currentTimeMillis(), waitChannel);

    try {
        // LogUtil.log("[bus] TX: " + payload);
        final Request request = builder.sendRequest(payload, new RequestCallback() {
            @Override
            public void onResponseReceived(final Request request, final Response response) {
                if (!waitChannel) {
                    measuredLatency = (int) (System.currentTimeMillis() - latencyTime);
                }

                pendingRequests.remove(rxInfo);
                callback.onResponseReceived(request, response);
                rxNumber++;
                rxActive = false;
            }

            @Override
            public void onError(final Request request, final Throwable exception) {
                pendingRequests.remove(rxInfo);
                callback.onError(request, exception);
                rxActive = false;
            }
        });

        rxInfo.setRequest(request);
        pendingRequests.add(rxInfo);

        return request;
    } catch (RequestException e) {
        throw e;
    }
}

From source file:org.opencms.ugc.client.CmsRpcCallHelper.java

License:Open Source License

/**
 * Executes the RPC call.<p>/*from w  w w . ja v a2 s  .c o m*/
 *
 * @param requestBuilder the request builder returned by the service interface
 */
@SuppressWarnings("synthetic-access")
public void executeRpc(RequestBuilder requestBuilder) {

    final RequestCallback callback = requestBuilder.getCallback();
    RequestCallback callbackWrapper = new RequestCallback() {

        public void onError(com.google.gwt.http.client.Request request, Throwable exception) {

            m_requestCounter.decrement();
            callback.onError(request, exception);
        }

        public void onResponseReceived(com.google.gwt.http.client.Request request,
                com.google.gwt.http.client.Response response) {

            m_requestCounter.decrement();
            callback.onResponseReceived(request, response);
        }
    };
    requestBuilder.setCallback(callbackWrapper);
    m_requestCounter.increment();
    try {
        requestBuilder.send();
    } catch (Exception e) {
        m_requestCounter.decrement();
    }
}

From source file:org.plantview.client.request.PlantViewRequestTransport.java

License:Apache License

@Override
protected RequestCallback createRequestCallback(final TransportReceiver delegate) {

    final RequestCallback superCallback = super.createRequestCallback(delegate);
    doBeforeCallback();/*from   w  w  w.  j  av a2s . co m*/
    return new RequestCallback() {
        public void onResponseReceived(Request request, Response response) {
            doOnResponseReceived();
            /*
             * 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.
                     */
                    delegate.onTransportFailure(
                            new ServerFailure("Unauthenticated user", null, null, false /* not fatal */));
                    eventBus.fireEvent(new AuthenticationFailureEvent(loginUrl));
                    return;
                }
            } else if (Response.SC_BAD_REQUEST == response.getStatusCode()) {
                String unsupportedUrl = response.getHeader("unsupported");
                if (unsupportedUrl != null) {
                    /*
                     * Hand the receiver a non-fatal callback, so that
                     * com.google.web.bindery.requestfactory.shared.Receiver will not post a
                     * runtime exception.
                     */
                    delegate.onTransportFailure(new ServerFailure("Unsupported user agent user", null, null,
                            false /* not fatal */));
                    eventBus.fireEvent(new AuthenticationFailureEvent(unsupportedUrl));
                    return;
                }
            }
            superCallback.onResponseReceived(request, response);
        }

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

From source file:org.qipki.clients.web.client.ui.widgets.ExternalResourcePanel.java

License:Open Source License

public void load(final String url, final RequestCallback callback) {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
    rb.setCallback(new RequestCallback() {

        @Override//from w w w  .  j  av  a  2  s. c  o m
        public void onResponseReceived(final Request request, final Response response) {
            new Timer() {

                @Override
                public void run() {
                    panel.clear();
                    panel.add(new HTMLPanel(response.getText()));
                    ExternalResourcePanel.this.url = url;
                    callback.onResponseReceived(request, response);
                }

            }.schedule(2000);
        }

        @Override
        public void onError(Request request, Throwable exception) {
            panel.clear();
            panel.add(new Label("Request ERROR: " + exception.getMessage()));
            callback.onError(request, exception);
        }

    });
    panel.clear();
    if (loadingPanel != null) {
        panel.setWidget(loadingPanel);
    }
    try {
        rb.send();
    } catch (RequestException ex) {
        panel.add(new Label("Request EXCEPTION: " + ex.getMessage()));
    }
}

From source file:pl.touk.wonderfulsecurity.gwt.client.rpc.RpcExecutor.java

License:Apache License

public static void execute(RequestBuilder rb, final boolean displayCommunicationStatus) {
    final RequestCallback originalCallback = rb.getCallback();

    /**/* w ww.j  av  a2s  .  co m*/
     * Using default message
     */
    if (displayCommunicationStatus) {

        showServerCommunication(message);
        messageQueue.add(message);
    }

    /**
     * Replacing callback, to be able to get login page location from HTTP header
     */
    rb.setCallback(new RequestCallback() {

        public void onResponseReceived(Request request, Response response) {
            String header = response.getHeader("loginPage");
            if (header != null && header.length() > 0) {
                Redirect.redirect(header);
            }

            if (displayCommunicationStatus) {
                refreshUserMessage();
            }

            originalCallback.onResponseReceived(request, response);
        }

        public void onError(Request request, Throwable exception) {

            if (displayCommunicationStatus) {

                refreshUserMessage();
            }

            if (errorHandler != null) {
                errorHandler.handleError(request, exception);
            }
            originalCallback.onError(request, exception);
        }
    });

    try {
        rb.send();
    } catch (RequestException ex) {
        if (errorHandler != null) {
            errorHandler.handleError(ex);
        }
    }

}