Example usage for com.google.gwt.http.client Request cancel

List of usage examples for com.google.gwt.http.client Request cancel

Introduction

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

Prototype

public void cancel() 

Source Link

Document

Cancels a pending request.

Usage

From source file:com.badlogic.gdx.backends.gwt.GwtNet.java

License:Apache License

@Override
public void cancelHttpRequest(HttpRequest httpRequest) {
    HttpResponseListener httpResponseListener = listeners.get(httpRequest);
    Request request = requests.get(httpRequest);

    if (httpResponseListener != null && request != null) {
        request.cancel();
        httpResponseListener.cancelled();
        requests.remove(httpRequest);//from  w  ww.  j  av  a2 s .c o m
        listeners.remove(httpRequest);
    }
}

From source file:io.reinert.requestor.RequestDispatcherImpl.java

License:Apache License

private HttpConnection getConnection(final com.google.gwt.http.client.Request gwtRequest) {
    return new HttpConnection() {
        public void cancel() {
            gwtRequest.cancel();
        }/*from  ww w  . j  a  v  a2 s .c o  m*/

        public boolean isPending() {
            return gwtRequest.isPending();
        }
    };
}

From source file:org.jboss.bpm.console.client.common.AbstractRESTAction.java

License:Open Source License

public void execute(final Controller controller, final Object object) {
    final String url = getUrl(object);
    RequestBuilder builder = new RequestBuilder(getRequestMethod(), URL.encode(url));

    ConsoleLog.debug(getRequestMethod() + ": " + url);

    try {//from w w w .  j  av  a 2  s. c o m
        //controller.handleEvent( LoadingStatusAction.ON );
        if (getDataDriven(controller) != null) {
            getDataDriven(controller).setLoading(true);
        }

        final 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.)
                handleError(url, exception);
                controller.handleEvent(LoadingStatusAction.OFF);
            }

            public void onResponseReceived(Request request, Response response) {
                try {
                    if (response.getText().indexOf("HTTP 401") != -1) // HACK
                    {
                        appContext.getAuthentication().handleSessionTimeout();
                    } else if (200 == response.getStatusCode()) {
                        handleSuccessfulResponse(controller, object, response);
                    } else {
                        final String msg = response.getText().equals("") ? "Unknown error" : response.getText();
                        handleError(url, new RequestException("HTTP " + response.getStatusCode() + ": " + msg));
                    }
                } finally {
                    //controller.handleEvent( LoadingStatusAction.OFF );
                    if (getDataDriven(controller) != null) {
                        getDataDriven(controller).setLoading(false);
                    }
                }
            }
        });

        // Timer to handle pending request
        Timer t = new Timer() {

            public void run() {
                if (request.isPending()) {
                    request.cancel();
                    handleError(url, new IOException("Request timeout"));
                }

            }
        };
        t.schedule(20000);

    } catch (RequestException e) {
        // Couldn't connect to server
        handleError(url, e);
        //controller.handleEvent( LoadingStatusAction.OFF );

        if (getDataDriven(controller) != null) {
            getDataDriven(controller).setLoading(false);
        }
    }
}

From source file:org.jboss.bpm.console.client.report.RenderReportAction.java

License:Open Source License

public void execute(final Controller controller, Object object) {
    final RenderDispatchEvent event = (RenderDispatchEvent) object;

    final String url = event.getDispatchUrl();
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);

    ConsoleLog.debug(RequestBuilder.POST + ": " + url);
    final ReportLaunchPadView view = (ReportLaunchPadView) controller.getView(ReportLaunchPadView.ID);

    view.reset();/*www .j a va2  s . c om*/
    view.setLoading(true);

    try {
        controller.handleEvent(LoadingStatusAction.ON);
        //view.setLoading(true);

        String parameters = event.getParameters();
        final Request request = builder.sendRequest(parameters, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                // Couldn't connect to server (could be timeout, SOP violation, etc.)
                handleError(controller, url, exception);
                controller.handleEvent(LoadingStatusAction.OFF);
            }

            public void onResponseReceived(Request request, Response response) {
                try {
                    if (response.getText().indexOf("HTTP 401") != -1) // HACK
                    {
                        appContext.getAuthentication().handleSessionTimeout();
                    } else if (200 == response.getStatusCode()) {
                        // update view
                        view.displayReport(event.getTitle(), event.getDispatchUrl());
                    } else {
                        final String msg = response.getText().equals("") ? "Unknown error" : response.getText();
                        handleError(controller, url,
                                new RequestException("HTTP " + response.getStatusCode() + ": " + msg));
                    }
                } finally {
                    controller.handleEvent(LoadingStatusAction.OFF);
                    view.setLoading(false);
                }
            }
        });

        // Timer to handle pending request
        Timer t = new Timer() {

            public void run() {
                if (request.isPending()) {
                    request.cancel();
                    handleError(controller, url, new IOException("Request timeout"));
                }

            }
        };
        t.schedule(20000);

    } catch (Throwable e) {
        // Couldn't connect to server
        controller.handleEvent(LoadingStatusAction.OFF);
        handleError(controller, url, e);
        view.setLoading(false);
    }
}

From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.controller.OutputController.java

License:Open Source License

public void cancelCurrentRequests() {
    if (this.model.isLive()) {
        this.stopLiveOutput();
    } else {/*from   w w w. j  ava 2 s  .c o m*/
        for (Request req : this.taskOutputRequests.values()) {
            req.cancel();
        }
        this.taskOutputRequests.clear();
    }
}

From source file:rpc.client.HTTPClient.java

License:Open Source License

@Override
public void cancel(ClientRequest<?> clientRequest) {
    Request request = pendingByClientRequest.get(clientRequest);

    if (request != null) {
        request.cancel();

        pendingByClientRequest.remove(clientRequest);
        pendingByRequest.remove(request);
    }//  ww  w  .  j av a  2  s .  c om
}