@RequestMapping
    public void doLogout(HttpServletRequest request, HttpServletResponse response)
            throws IOException {

        String redirect = this.selectRedirectionUrl(request);
        final HttpSession session = request.getSession(false);

        if (session != null) {
            // Record that an authenticated user is requesting to log out
            try {
                final IPerson person = personManager.getPerson(request);
                if (person != null && person.getSecurityContext().isAuthenticated()) {
                    this.portalEventFactory.publishLogoutEvent(request, this, person);
                }
            } catch (final Exception e) {
                logger.error(
                        "Exception recording logout " + "associated with request " + request, e);
            }

            final String originalUid = this.identitySwapperManager.getOriginalUsername(session);
            // Logging out from a swapped user, just redirect to the Login servlet
            if (originalUid != null) {
                redirect = request.getContextPath() + "/Login";
            } else {
                // Clear out the existing session for the user
                try {
                    session.invalidate();
                } catch (final IllegalStateException ise) {
                    // IllegalStateException indicates session was already invalidated.
                    // This is fine.  LogoutController is looking to guarantee the logged out
                    // session is invalid;
                    // it need not insist that it be the one to perform the invalidating.
                    if (logger.isTraceEnabled()) {
                        logger.trace(
                                "LogoutController encountered IllegalStateException invalidating a presumably already-invalidated session.",
                                ise);
                    }
                }
            }
        }

        if (logger.isTraceEnabled()) {
            logger.trace(
                    "Redirecting to " + redirect + " to send the user back to the guest page.");
        }

        final String encodedRedirectURL = response.encodeRedirectURL(redirect);
        response.sendRedirect(encodedRedirectURL);
    }
@ RequestMapping public void doLogout ( HttpServletRequest request , HttpServletResponse response ) throws IOException { String redirect = this . selectRedirectionUrl ( request ) ; final HttpSession session = request . getSession ( false ) ; if ( session != null ) { try { final IPerson person = personManager . getPerson ( request ) ; if ( person != null && person . getSecurityContext ( ) . isAuthenticated ( ) ) { this . portalEventFactory . publishLogoutEvent ( request , this , person ) ; } } catch ( final Exception e ) { logger . error ( "Exception recording logout " + "associated with request " + request , e ) ; } final String originalUid = this . identitySwapperManager . getOriginalUsername ( session ) ; if ( originalUid != null ) { redirect = request . getContextPath ( ) + "/Login" ; } else { try { session . invalidate ( ) ; } catch ( final IllegalStateException ise ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( "LogoutController encountered IllegalStateException invalidating a presumably already-invalidated session." , ise ) ; } } } } if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Redirecting to " + redirect + " to send the user back to the guest page." ) ; } final String encodedRedirectURL = response . encodeRedirectURL ( redirect ) ; response . sendRedirect ( encodedRedirectURL ) ; }
Process the incoming request and response.

@param request HttpServletRequest object
@param response HttpServletResponse object