public void sendRedirect(String location, boolean permanent) throws IOException {

        // Ignore any redirects after the first one
        if (isSuspended() && (!location.equals(m_bufferRedirect))) {
            return;
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXRESPONSE_SENDREDIRECT_1, location));
        }
        if (m_cachingRequired && !m_includeMode) {
            m_bufferRedirect = location;
            m_redirectPermanent = permanent;
        }

        if (!m_cachingRequired) {
            // If caching is required a cached entry will be constructed first and redirect will
            // be called after this is completed and stored in the cache
            if (LOG.isDebugEnabled()) {
                LOG.debug(
                    Messages.get().getBundle().key(Messages.LOG_FLEXRESPONSE_TOPRESPONSE_SENDREDIRECT_1, location));
            }
            if (LOG.isWarnEnabled()) {
                if (m_controller.getResponseStackSize() > 2) {
                    // sendRedirect in a stacked response scenario, this may cause issues in some app servers
                    LOG.warn(
                        Messages.get().getBundle().key(
                            Messages.LOG_FLEXRESPONSE_REDIRECTWARNING_3,
                            m_controller.getCmsResource().getRootPath(),
                            m_controller.getCurrentRequest().getElementUri(),
                            location));
                }
            }
            try {
                // Checking for possible illegal characters (for example, XSS exploits) before sending the redirect
                // The constructor is key here. That method will throw an URISyntaxException if the URL
                // format is not according to standards (e.g. contains illegal characters, like spaces, < or >, etc).
                @SuppressWarnings("unused")
                URI validURI = new URI(location);
            } catch (URISyntaxException e) {
                // Deliberately NOT passing the original exception, since the URISyntaxException contains the full path,
                // which may include the XSS attempt
                LOG.error(Messages.get().getBundle().key(Messages.ERR_FLEXRESPONSE_URI_SYNTAX_EXCEPTION_0), e);
                throw new IllegalArgumentException("Illegal or malformed characters found in path");
            }

            // use top response for redirect
            HttpServletResponse topRes = m_controller.getTopResponse();
            // add all headers found to make sure cookies can be set before redirect
            processHeaders(getHeaders(), topRes);
            if (permanent) {
                topRes.setHeader(CmsRequestUtil.HEADER_LOCATION, location);
                topRes.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            } else {
                topRes.sendRedirect(location);
            }
        }
        m_controller.suspendFlexResponse();
    }
public void sendRedirect ( String location , boolean permanent ) throws IOException { if ( isSuspended ( ) && ( ! location . equals ( m_bufferRedirect ) ) ) { return ; } if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( Messages . get ( ) . getBundle ( ) . key ( Messages . LOG_FLEXRESPONSE_SENDREDIRECT_1 , location ) ) ; } if ( m_cachingRequired && ! m_includeMode ) { m_bufferRedirect = location ; m_redirectPermanent = permanent ; } if ( ! m_cachingRequired ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( Messages . get ( ) . getBundle ( ) . key ( Messages . LOG_FLEXRESPONSE_TOPRESPONSE_SENDREDIRECT_1 , location ) ) ; } if ( LOG . isWarnEnabled ( ) ) { if ( m_controller . getResponseStackSize ( ) > 2 ) { LOG . warn ( Messages . get ( ) . getBundle ( ) . key ( Messages . LOG_FLEXRESPONSE_REDIRECTWARNING_3 , m_controller . getCmsResource ( ) . getRootPath ( ) , m_controller . getCurrentRequest ( ) . getElementUri ( ) , location ) ) ; } } try { @ SuppressWarnings ( "unused" ) URI validURI = new URI ( location ) ; } catch ( URISyntaxException e ) { LOG . error ( Messages . get ( ) . getBundle ( ) . key ( Messages . ERR_FLEXRESPONSE_URI_SYNTAX_EXCEPTION_0 ) , e ) ; throw new IllegalArgumentException ( "Illegal or malformed characters found in path" ) ; } HttpServletResponse topRes = m_controller . getTopResponse ( ) ; processHeaders ( getHeaders ( ) , topRes ) ; if ( permanent ) { topRes . setHeader ( CmsRequestUtil . HEADER_LOCATION , location ) ; topRes . setStatus ( HttpServletResponse . SC_MOVED_PERMANENTLY ) ; } else { topRes . sendRedirect ( location ) ; } } m_controller . suspendFlexResponse ( ) ; }
Internal redirect method used to handle both temporary and permanent redirects.<p>

@param location the redirect target
@param permanent true for a permanent redirect, false for a temporary one

@throws IOException if IO operations on the response fail