Example usage for com.google.gwt.http.client Response SC_FORBIDDEN

List of usage examples for com.google.gwt.http.client Response SC_FORBIDDEN

Introduction

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

Prototype

int SC_FORBIDDEN

To view the source code for com.google.gwt.http.client Response SC_FORBIDDEN.

Click Source Link

Usage

From source file:com.ait.tooling.nativetools.client.rpc.JSONCommandRequest.java

License:Open Source License

protected void onBadStatusCode(final RequestBuilder builder, final String command, final long counter,
        final long reqtime, final AsyncCallback<NObject> callback, final int code) {
    if (Response.SC_NOT_FOUND == code) {
        doFailure(command, callback, counter, reqtime,
                new Exception("Code [" + code + "]: Command [" + command + "] not found "));
    } else if (Response.SC_FORBIDDEN == code) {
        doFailure(command, callback, counter, reqtime,
                new Exception("Code [" + code + "]: No permission or Session expired"));
    } else if (Response.SC_BAD_GATEWAY == code) {
        doFailure(command, callback, counter, reqtime,
                new Exception("Code [" + code + "]: Misconfigured Gateway"));
    } else if ((0 == code) || (Response.SC_SERVICE_UNAVAILABLE == code)) {
        doFailure(command, callback, counter, reqtime,
                new Exception("Code [" + code + "]: Server appears to be down"));
    } else {//from  ww w . j  av a  2s. co  m
        doFailure(command, callback, counter, reqtime,
                new Exception("Bad status code ]" + code + "] for command [" + command + "]"));
    }
}

From source file:com.arcbees.bourseje.client.application.confirmvote.ConfirmVotePresenter.java

License:Apache License

@Override
public void onConfirmClicked() {
    VoteItem voteItem = new VoteItem(Long.valueOf(id));
    dispatch.execute(voteService.vote(voteItem), new RestCallbackImpl<Void>() {
        @Override//from   w  w w.j a  v a 2s  .  co  m
        public void onError(Response response) {
            super.onError(response);

            if (response.getStatusCode() == Response.SC_FORBIDDEN) {
                revealPlace(NameTokens.ALREADY_VOTED);
            } else {
                revealPlace(NameTokens.VOTE_FINISHED);
            }
        }

        @Override
        public void onSuccess(Void aVoid) {
            revealPlace(NameTokens.THANKS);
        }
    });
}

From source file:com.google.appinventor.client.Ode.java

License:Open Source License

/**
 * Main entry point for Ode. Setting up the UI and the web service
 * connections.//w  w  w . j a va  2s  .c  o m
 */
@Override
public void onModuleLoad() {
    Tracking.trackPageview();

    // Handler for any otherwise unhandled exceptions
    GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
        @Override
        public void onUncaughtException(Throwable e) {
            OdeLog.xlog(e);

            if (AppInventorFeatures.sendBugReports()) {
                if (Window.confirm(MESSAGES.internalErrorReportBug())) {
                    Window.open(BugReport.getBugReportLink(e), "_blank", "");
                }
            } else {
                // Display a confirm dialog with error msg and if 'ok' open the debugging view
                if (Window.confirm(MESSAGES.internalErrorClickOkDebuggingView())) {
                    Ode.getInstance().switchToDebuggingView();
                }
            }
        }
    });

    // Define bridge methods to Javascript
    JsonpConnection.defineBridgeMethod();

    // Initialize global Ode instance
    instance = this;

    // Let's see if we were started with a repo= parameter which points to a template
    templatePath = Window.Location.getParameter("repo");
    if (templatePath != null) {
        OdeLog.wlog("Got a template path of " + templatePath);
        templateLoadingFlag = true;
    }

    // Let's see if we were started with a galleryId= parameter which points to a template
    galleryId = Window.Location.getParameter("galleryId");
    if (galleryId != null) {
        OdeLog.wlog("Got a galleryId of " + galleryId);
        galleryIdLoadingFlag = true;
    }

    // Get user information.
    OdeAsyncCallback<Config> callback = new OdeAsyncCallback<Config>(
            // failure message
            MESSAGES.serverUnavailable()) {

        @Override
        public void onSuccess(Config result) {
            config = result;
            user = result.getUser();
            isReadOnly = user.isReadOnly();

            // If user hasn't accepted terms of service, ask them to.
            if (!user.getUserTosAccepted() && !isReadOnly) {
                // We expect that the redirect to the TOS page should be handled
                // by the onFailure method below. The server should return a
                // "forbidden" error if the TOS wasn't accepted.
                ErrorReporter.reportError(MESSAGES.serverUnavailable());
                return;
            }

            splashConfig = result.getSplashConfig();

            if (result.getRendezvousServer() != null) {
                setRendezvousServer(result.getRendezvousServer());
            } else {
                setRendezvousServer(YaVersion.RENDEZVOUS_SERVER);
            }

            userSettings = new UserSettings(user);

            // Gallery settings
            gallerySettings = new GallerySettings();
            //gallerySettings.loadGallerySettings();
            loadGallerySettings();

            // Initialize project and editor managers
            // The project manager loads the user's projects asynchronously
            projectManager = new ProjectManager();
            projectManager.addProjectManagerEventListener(new ProjectManagerEventAdapter() {
                @Override
                public void onProjectsLoaded() {
                    projectManager.removeProjectManagerEventListener(this);

                    // This handles any built-in templates stored in /war
                    // Retrieve template data stored in war/templates folder and
                    // and save it for later use in TemplateUploadWizard
                    OdeAsyncCallback<String> templateCallback = new OdeAsyncCallback<String>(
                            // failure message
                            MESSAGES.createProjectError()) {
                        @Override
                        public void onSuccess(String json) {
                            // Save the templateData
                            TemplateUploadWizard.initializeBuiltInTemplates(json);
                            // Here we call userSettings.loadSettings, but the settings are actually loaded
                            // asynchronously, so this loadSettings call will return before they are loaded.
                            // After the user settings have been loaded, openPreviousProject will be called.
                            // We have to call this after the builtin templates have been loaded otherwise
                            // we will get a NPF.
                            userSettings.loadSettings();
                        }
                    };
                    Ode.getInstance().getProjectService().retrieveTemplateData(
                            TemplateUploadWizard.TEMPLATES_ROOT_DIRECTORY, templateCallback);
                }
            });
            editorManager = new EditorManager();

            // Initialize UI
            initializeUi();

            topPanel.showUserEmail(user.getUserEmail());
        }

        @Override
        public void onFailure(Throwable caught) {
            if (caught instanceof StatusCodeException) {
                StatusCodeException e = (StatusCodeException) caught;
                int statusCode = e.getStatusCode();
                switch (statusCode) {
                case Response.SC_UNAUTHORIZED:
                    // unauthorized => not on whitelist
                    // getEncodedResponse() gives us the message that we wrote in
                    // OdeAuthFilter.writeWhitelistErrorMessage().
                    Window.alert(e.getEncodedResponse());
                    return;
                case Response.SC_FORBIDDEN:
                    // forbidden => need tos accept
                    Window.open("/" + ServerLayout.YA_TOS_FORM, "_self", null);
                    return;
                case Response.SC_PRECONDITION_FAILED:
                    String locale = Window.Location.getParameter("locale");
                    if (locale == null || locale.equals("")) {
                        Window.Location.replace("/login/");
                    } else {
                        Window.Location.replace("/login/?locale=" + locale);
                    }
                    return; // likely not reached
                }
            }
            super.onFailure(caught);
        }
    };

    // The call below begins an asynchronous read of the user's settings
    // When the settings are finished reading, various settings parsers
    // will be called on the returned JSON object. They will call various
    // other functions in this module, including openPreviousProject (the
    // previous project ID is stored in the settings) as well as the splash
    // screen displaying functions below.
    //
    // TODO(user): ODE makes too many RPC requests at startup time. Currently
    // we do 3 RPCs + 1 per project + 1 per open file. We should bundle some of
    // those with each other or with the initial HTML transfer.
    //
    // This call also stores our sessionId in the backend. This will be checked
    // when we go to save a file and if different file saving will be disabled
    // Newer sessions invalidate older sessions.

    userInfoService.getSystemConfig(sessionId, callback);

    History.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            openProject(event.getValue());
        }
    });

    // load project based on current url
    // TODO(sharon): Seems like a possible race condition here if the onValueChange
    // handler defined above gets called before the getSystemConfig call sets
    // userSettings.
    // The following line causes problems with GWT debugging, and commenting
    // it out doesn't seem to break things.
    //History.fireCurrentHistoryState();
}

From source file:com.google.gerrit.client.rpc.RestApi.java

License:Apache License

/** True if err is describing a user that is currently anonymous. */
public static boolean isNotSignedIn(Throwable err) {
    if (err instanceof StatusCodeException) {
        StatusCodeException sce = (StatusCodeException) err;
        if (sce.getStatusCode() == Response.SC_UNAUTHORIZED) {
            return true;
        }/*from  www.j a  va  2 s  .c  om*/
        return sce.getStatusCode() == Response.SC_FORBIDDEN
                && (sce.getEncodedResponse().equals("Authentication required")
                        || sce.getEncodedResponse().startsWith("Must be signed-in"));
    }
    return false;
}

From source file:nl.sense_os.commonsense.login.client.login.LoginActivity.java

License:Open Source License

private void onLoginResponse(Response response) {
    LOG.finest("POST login response received: " + response.getStatusText());
    final int statusCode = response.getStatusCode();
    if (Response.SC_OK == statusCode) {
        onLoginSuccess(response.getText());
    } else if (Response.SC_FORBIDDEN == statusCode) {
        onAuthenticationFailure();//from  ww  w  .  j a  v  a2 s.c  om
    } else {
        LOG.warning("POST login returned incorrect status: " + statusCode);
        onLoginFailure(statusCode, new Exception("Incorrect response status: " + statusCode));
    }
}

From source file:nl.sense_os.commonsense.login.client.openidconnect.OpenIdConnectActivity.java

License:Open Source License

private void onLoginResponse(Response response) {
    final int statusCode = response.getStatusCode();
    if (Response.SC_OK == statusCode) {
        onLoginSuccess(response.getText());
    } else if (Response.SC_FORBIDDEN == statusCode) {
        onAuthenticationFailure();// w w w  .  j a  v  a  2s .com
    } else {
        onLoginError(statusCode, new Throwable(response.getStatusText()));
    }
}

From source file:org.obiba.opal.web.gwt.app.client.administration.r.list.RSessionsPresenter.java

License:Open Source License

@Override
public void onRefresh() {
    ResourceRequestBuilderFactory.<JsArray<RSessionDto>>newBuilder().forResource("/service/r/sessions").get()
            .withCallback(new ResourceCallback<JsArray<RSessionDto>>() {
                @Override//from  w w  w.ja va2s . co  m
                public void onResource(Response response, JsArray<RSessionDto> resource) {
                    getView().renderRows(resource);
                }

            }).withCallback(new ResponseCodeCallback() {
                @Override
                public void onResponseCode(Request request, Response response) {
                    // ignore
                }
            }, Response.SC_FORBIDDEN).send();
}

From source file:org.obiba.opal.web.gwt.app.client.fs.presenter.CreateFolderModalPresenter.java

License:Open Source License

private void createRemoteFolder(String destination, String folder) {

    ResourceCallback<FileDto> createdCallback = new ResourceCallback<FileDto>() {

        @Override// ww w .  j a  v  a2  s  . co m
        public void onResource(Response response, FileDto resource) {
            fireEvent(new FolderCreatedEvent(resource));
            getView().hideDialog();
        }
    };

    ResponseCodeCallback error = new ResponseCodeCallback() {

        @Override
        public void onResponseCode(Request request, Response response) {
            fireEvent(NotificationEvent.newBuilder().error(response.getText()).build());
        }
    };

    ResourceRequestBuilderFactory.<FileDto>newBuilder().forResource("/files" + destination).post()
            .withBody("text/plain", folder).withCallback(createdCallback)
            .withCallback(Response.SC_FORBIDDEN, error).withCallback(Response.SC_INTERNAL_SERVER_ERROR, error)
            .send();
}

From source file:org.obiba.opal.web.gwt.app.client.fs.presenter.FileExplorerPresenter.java

License:Open Source License

@Override
public void onDelete() {
    if (!hasCheckedFiles())
        return;/*from  ww w. j a v a2s  .  c o  m*/

    // We are either deleting a file or a folder
    actionRequiringConfirmation = new Runnable() {
        @Override
        public void run() {
            for (FileDto fileToDelete : checkedFiles) {
                deleteFile(fileToDelete);
            }
        }

        private void deleteFile(final FileDto file) {
            ResponseCodeCallback callbackHandler = new ResponseCodeCallback() {

                @Override
                public void onResponseCode(Request request, Response response) {
                    if (response.getStatusCode() == Response.SC_OK) {
                        getEventBus().fireEvent(new FileDeletedEvent(file));
                    } else {
                        getEventBus()
                                .fireEvent(NotificationEvent.newBuilder().error(response.getText()).build());
                    }
                }
            };

            ResourceRequestBuilderFactory.newBuilder().forResource("/files" + file.getPath()).delete()
                    .withCallback(Response.SC_OK, callbackHandler)
                    .withCallback(Response.SC_FORBIDDEN, callbackHandler)
                    .withCallback(Response.SC_INTERNAL_SERVER_ERROR, callbackHandler)
                    .withCallback(Response.SC_NOT_FOUND, callbackHandler).send();
        }
    };

    getEventBus().fireEvent(ConfirmationRequiredEvent.createWithMessages(actionRequiringConfirmation,
            translationMessages.removeFile(), translationMessages.confirmDeleteFile()));
}

From source file:org.obiba.opal.web.gwt.app.client.fs.presenter.FileSelectorPresenter.java

License:Open Source License

private void createFolder(String destination, String folder) {

    ResourceCallback<FileDto> createdCallback = new ResourceCallback<FileDto>() {

        @Override/*from w ww. j  a  v  a  2  s . c o m*/
        public void onResource(Response response, FileDto resource) {
            fireEvent(new FolderCreatedEvent(resource));
            getView().clearNewFolderName();
        }
    };

    ResponseCodeCallback callbackHandler = new ResponseCodeCallback() {

        @Override
        public void onResponseCode(Request request, Response response) {
            fireEvent(NotificationEvent.newBuilder().error(response.getText()).build());
        }
    };

    ResourceRequestBuilderFactory.<FileDto>newBuilder().forResource("/files" + destination).post()
            .withBody("text/plain", folder).withCallback(createdCallback)
            .withCallback(Response.SC_FORBIDDEN, callbackHandler)
            .withCallback(Response.SC_INTERNAL_SERVER_ERROR, callbackHandler).send();
}