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

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

Introduction

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

Prototype

public boolean isPending() 

Source Link

Document

Returns true if this request is waiting for a response.

Usage

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();/* w w w . j ava2 s . com*/
        }

        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 {//w ww  . jav  a  2 s .co  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();/*  w w w  . j  ava  2s . c  o  m*/
    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.wyona.security.gwt.accesspolicyeditor.client.AccessPolicyEditor.java

License:Apache License

/**
 * Get identities and rights/*from  w ww.  j  av  a  2  s  .  c om*/
 * @param url URL to request identities (users and groups) as XML (also see src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyManagerResource.java, identities-url)
 */
private void getIdentitiesAndRights(String url) {
    if (allRights == null) {
        //Window.alert("Load users and groups as XML: " + url);
        url = GWT.getHostPageBaseURL() + url.replaceAll("&", "&");
        //Window.alert("Load IdentitiesAndRights: "+ url);
        final AsynchronousIdentitiesAndRightsGetter ag = new AsynchronousIdentitiesAndRightsGetter(url);

        try {
            final com.google.gwt.http.client.Request request = ag.execute();

            // Start new thread
            Timer t = new Timer() {
                public void run() {
                    if (request.isPending()) {
                        rightsIdentitiesRetrievalCompleted = false;
                        identitiesLBW.displayLoadingMessage();
                        scheduleRepeating(10);
                    } else {
                        rightsIdentitiesRetrievalCompleted = true;

                        allRights = ag.getRights();
                        String[] identitiesAllUsers = ag.getUsers();
                        String[] identitiesAllGroups = ag.getGroups();
                        this.cancel();
                        // NOTE: Please note that the server might not provide any groups and hence the OR instead the AND!
                        if (allRights.length > 0
                                && (identitiesAllUsers.length > 0 || identitiesAllGroups.length > 0)) {
                            policyLBW.set(allRights);
                            identitiesLBW.setUsersAndGroups(identitiesAllUsers, identitiesAllGroups);
                            //Window.alert("Rights and identities have been loaded!" + allRights.length + " " + identitiesAllUsers.length + " " + identitiesAllGroups.length);
                        } else {
                            Window.alert("Rights and identities have not been loaded yet!");
                        }
                    }
                }
            };
            t.schedule(1);

        } catch (Exception e) {
            //if (!com.google.gwt.core.client.GWT.isScript()) {
            e.printStackTrace();
            //}
        }
    } else {
        Window.alert("Rights are already set!");
    }
}

From source file:org.wyona.security.gwt.accesspolicyeditor.client.AccessPolicyEditor.java

License:Apache License

/**
 * Get policy//  w  w  w  .  j ava 2s . co m
 * @param url URL to request policy as XML
 */
private void getPolicy(String url) {
    url = GWT.getHostPageBaseURL() + url.replaceAll("&", "&");
    //Window.alert("Load policy as XML: " + url);
    final AsynchronousPolicyGetter apg = new AsynchronousPolicyGetter(url);
    try {
        final com.google.gwt.http.client.Request request = apg.execute();

        // Start new thread
        Timer t = new Timer() {
            public void run() {
                if (request.isPending() || !rightsIdentitiesRetrievalCompleted) {
                    policyLBW.displayLoading(visibleItemCount);
                    policyRetrievalCompleted = false;
                    scheduleRepeating(10);
                } else {
                    policyRetrievalCompleted = true;

                    policyUsers = apg.getUsers();
                    policyGroups = apg.getGroups();

                    // "Redraw" Listbox
                    policyLBW.setIdentities(visibleItemCount, policyUsers, policyGroups);

                    useInheritedPolicies = apg.getUseInheritedPolicies();
                    policyLBW.setInheritRightsFlag(useInheritedPolicies);

                    this.cancel();

                    // Remove/Subtract policy-users/groups from "Identities"

                    // Remove all users from identities list, which already exist within the policy
                    for (int i = 0; i < policyUsers.length; i++) {
                        identitiesLBW.removeUser(policyUsers[i].getId());
                    }

                    // Remove all groups from identities list, which already exist within the policy
                    for (int i = 0; i < policyGroups.length; i++) {
                        identitiesLBW.removeGroup(policyGroups[i].getId());
                    }

                    identitiesLBW.listAll(); // TODO: Update display inside removeUser() and removeGroup()

                    //Window.alert("Policy has been loaded!");
                }
            }
        };
        t.schedule(1);

    } catch (Exception e) {
        Window.alert("Exception: " + e.getMessage());
        //if (!com.google.gwt.core.client.GWT.isScript()) {
        e.printStackTrace();
        //}
    }
}