Example usage for javax.servlet.http HttpServletResponse encodeRedirectUrl

List of usage examples for javax.servlet.http HttpServletResponse encodeRedirectUrl

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse encodeRedirectUrl.

Prototype

@Deprecated
public String encodeRedirectUrl(String url);

Source Link

Usage

From source file:application.controllers.admin.EditEmotion.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String linkImage = uploadNewImage(request, response);

    EmotionBOImpl emotionBoImpl = new EmotionBOImpl();
    //   emotionSelected.description = description;
    // emotionSelected.groupEmotionId = groupEmotionId;
    //        emotionSelected.linkImage = linkImage;
    //        emotionSelected.description = request.getParameter("description");
    //        emotionSelected.linkImage = request.getParameter("imageURL");
    //        emotionSelected.groupEmotionId = Integer.parseInt(request.getParameter("groupEmotion"));

    //edit link image and groupEmotionId
    if (!emotionBoImpl.editEmotion(emotionSelected)) {
        //if error show view error
        View layout = new View("Index.xtm");
        View view = new View("admin", "EditEmotion.xtm");
        view.setVariable("errorExist", "Error when edit emotion");
        String content = view.render();
        layout.setVariable("content", content);
        String mainView = layout.render();
        response.getWriter().write(mainView);
    }/* w  w w.  ja va2 s. c  om*/

    String newURL = response.encodeRedirectURL(
            Registry.get("Host") + "/groupEmotion/emotion?groupId=" + emotionSelected.groupEmotionId);
    response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
    response.setHeader("Location", newURL);
    response.setContentType("text/html");
}

From source file:de.mpg.mpdl.inge.pidcache.web.MainServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    logger.info("PID cache POST request");

    if (req.getParameter("url") == null) {
        resp.sendError(HttpServletResponse.SC_NO_CONTENT, "URL parameter failed.");
    }/* w  w w.  ja  v a  2s  .c o  m*/
    try {

        if (!authenticate(req, resp)) {
            logger.warn("Unauthorized request from " + req.getRemoteHost());
            return;
        }

        PidCacheService cacheService = new PidCacheService();
        String xmlOutput = null;

        if (GwdgPidService.GWDG_PIDSERVICE_CREATE.equals(req.getPathInfo())) {
            xmlOutput = cacheService.create(req.getParameter("url"));
        } else if (GwdgPidService.GWDG_PIDSERVICE_EDIT.equals(req.getPathInfo())) {
            if (req.getParameter("pid") == null) {
                resp.sendError(HttpServletResponse.SC_NO_CONTENT, "PID parameter failed.");
            }
            xmlOutput = cacheService.update(req.getParameter("pid"), req.getParameter("url"));
        } else {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getPathInfo());
        }

        resp.setStatus(cacheService.getStatus());
        resp.encodeRedirectURL(cacheService.getLocation());
        resp.addHeader("Location", cacheService.getLocation());
        resp.getWriter().append(xmlOutput);
    } catch (Exception e) {
        throw new ServletException("Error processing request", e);
    }
}

From source file:org.etudes.mneme.tool.AssessmentEditView.java

/**
 * {@inheritDoc}/*from   w w  w  .  j  av  a2 s  . c o  m*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // sort, aid, return
    if (params.length < 3) {
        throw new IllegalArgumentException();
    }
    String assessmentId = params[2];
    String returnDestination = null;

    if (params.length > 3) {
        returnDestination = "/" + StringUtil.unsplit(params, 3, params.length - 3, "/");
    }

    // if not specified, go to the main assessment view
    else {
        returnDestination = "/assessments";
    }

    final Assessment assessment = assessmentService.getAssessment(assessmentId);
    if (assessment == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // security check
    if (!assessmentService.allowEditAssessment(assessment)) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // for editing the points
    PopulatingSet details = uiService.newPopulatingSet(new Factory() {
        public Object get(String id) {
            PartDetail detail = assessment.getParts().getDetailId(id);
            return detail;
        }
    }, new Id() {
        public String getId(Object o) {
            return ((PartDetail) o).getId();
        }
    });
    context.put("details", details);

    // setup the model: the selected assessment
    context.put("assessment", assessment);

    // value holders for the selection check boxes
    Values values = this.uiService.newValues();
    context.put("ids", values);

    // for the upload of attachments
    Upload upload = new Upload(this.toolManager.getCurrentPlacement().getContext(), AttachmentService.DOCS_AREA,
            this.attachmentService);
    context.put("upload", upload);

    // read the form
    String destination = uiService.decode(req, context);

    // save the attachments upload
    if (upload.getUpload() != null) {
        assessment.getPresentation().addAttachment(upload.getUpload());
    }

    // handle an attachments remove
    if (destination.startsWith("REMOVE:")) {
        String[] parts = StringUtil.split(destination, ":");
        if (parts.length != 2) {
            throw new IllegalArgumentException();
        }
        String refString = parts[1];
        Reference ref = this.entityManager.newReference(refString);

        // remove from the assessment, but since the attachment was in the site's mneme docs and generally available, don't remove it
        assessment.getPresentation().removeAttachment(ref);
        // this.attachmentService.removeAttachment(ref);

        // stay here
        destination = context.getDestination();
    }

    try {
        if (destination.equals("ADD")) {
            // use the first part, adding one if needed
            Part part = assessment.getParts().getFirst();
            if (part == null) {
                part = assessment.getParts().addPart();
            }

            // the assessment's pool, saving in case this is the creation of the pool
            Pool pool = assessment.getPool();
            this.assessmentService.saveAssessment(assessment);

            // create a question - mc for test, essay for assignment, likert for survey assessment types
            String type = "mneme:MultipleChoice";
            if (AssessmentType.assignment == assessment.getType()) {
                type = "mneme:Essay";
            } else if (AssessmentType.survey == assessment.getType()) {
                type = "mneme:LikertScale";
            }

            // create the question of the appropriate type (all the way to save)
            Question newQuestion = null;
            try {
                newQuestion = this.questionService.newQuestion(pool, type);
            } catch (AssessmentPermissionException e) {
                // redirect to error
                res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
                return;
            }

            // create URL for add questions
            destination = "/question_edit/" + newQuestion.getId() + "/" + assessmentId + "/" + part.getId()
                    + "/assessment_edit/" + assessmentId + returnDestination;
        }

        else if (destination.equals("DRAW")) {
            // use the first part, adding one if needed
            Part part = assessment.getParts().getFirst();
            if (part == null) {
                part = assessment.getParts().addPart();
            }

            // save
            this.assessmentService.saveAssessment(assessment);

            // create URL for select questions
            destination = "/draw_questions/" + assessmentId + "/" + part.getId() + "/0A/" + "assessment_edit/"
                    + assessmentId + returnDestination;
        }

        else if (destination.equals("SELECT")) {
            // use the first part, adding one if needed
            Part part = assessment.getParts().getFirst();
            if (part == null) {
                part = assessment.getParts().addPart();
            }

            // save
            this.assessmentService.saveAssessment(assessment);

            // create URL for select questions
            destination = "/select_add_mpart_question/" + assessmentId + "/" + part.getId() + "/0A/-/0/0/B/"
                    + "assessment_edit/" + assessmentId + returnDestination;
        }

        else if (destination.equals("REMOVE")) {
            // detail ids selected for removal
            for (String id : values.getValues()) {
                assessment.getParts().removeDetail(id);
            }

            // save
            this.assessmentService.saveAssessment(assessment);

            destination = context.getDestination();
        }

        else if (destination.equals("PARTS")) {
            // save
            this.assessmentService.saveAssessment(assessment);

            destination = "/part_manage/" + assessmentId + "/assessment_edit/" + assessmentId
                    + returnDestination;
        }

        else if (destination.equals("INSTRUCTIONS")) {
            // save
            this.assessmentService.saveAssessment(assessment);

            destination = "/instructions_edit/" + assessmentId + "/assessment_edit/" + assessmentId
                    + returnDestination;
        }

        else if (destination.equals("REORDER") || (destination.equals("SAVE"))) {
            // save
            this.assessmentService.saveAssessment(assessment);

            destination = context.getDestination();
        }

        else if (destination.equals("MOVE")) {
            // save
            this.assessmentService.saveAssessment(assessment);

            // format the selected ids
            StringBuilder buf = new StringBuilder();
            for (String id : values.getValues()) {
                buf.append(id);
                buf.append("+");
            }
            buf.setLength(buf.length() - 1);

            // destination to the detail move view
            destination = "/detail_move/" + assessmentId + "/" + buf.toString() + "/assessment_edit/"
                    + assessmentId + returnDestination;
        }

        else if (destination.equals("SURVEY")) {
            // change to survey
            assessment.setType(AssessmentType.survey);

            // save
            this.assessmentService.saveAssessment(assessment);

            destination = context.getDestination();
        } else if (destination.equals("EVALSEND")) {
            this.assessmentService.saveAssessment(assessment);

            destination = context.getDestination();

            this.assessmentService.sendEvalNotification(assessment);
        } else {
            this.assessmentService.saveAssessment(assessment);
        }
    } catch (AssessmentPermissionException e) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    } catch (AssessmentPolicyException e) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.policy)));
        return;
    }

    // redirect to the next destination
    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

From source file:org.etudes.mneme.tool.QuestionPreviewView.java

/**
 * {@inheritDoc}/*from   w w  w.  j  a  v  a2  s .co m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need a qid, then any number of parameters to form the return destination
    if (params.length < 3) {
        throw new IllegalArgumentException();
    }

    // if there's a * instead of question id, expect multiple ids at the end of the URL
    boolean multiple = "*".equals(params[2]);

    String destination = null;
    if (params.length > 3) {
        int len = params.length - 3;
        if (multiple) {
            len--;
        }
        destination = "/" + StringUtil.unsplit(params, 3, len, "/");
    }

    // if not specified, go to the main pools page
    else {
        destination = "/pools";
    }
    context.put("return", destination);

    if (!multiple) {
        String questionId = params[2];
        Question question = questionService.getQuestion(questionId);
        if (question == null) {
            // redirect to error
            res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
            return;
        }

        // security check
        if (!questionService.allowEditQuestion(question)) {
            // redirect to error
            res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
            return;
        }

        List<Question> questions = new ArrayList<Question>();
        questions.add(question);
        context.put("questions", questions);

        // only if coming from pool_edit, we offer prev/next
        if (destination.startsWith("/pool_edit") || destination.startsWith("/pool_fix")) {
            figurePrevNextForPoolEdit(context, destination, question);
        }
    }

    else {
        List<Question> questions = new ArrayList<Question>();

        // question id's are in the params array at the end
        String qidParam = params[params.length - 1];

        // for entire pool "*pid"
        if (qidParam.startsWith("*")) {
            String pid = qidParam.substring(1);
            Pool pool = this.poolService.getPool(pid);
            if (pool != null) {
                context.put("pool", pool.getTitle());

                List<String> qids = this.questionService.getPoolQuestionIds(pool, null, null);
                for (String qid : qids) {
                    // get the question
                    Question question = this.questionService.getQuestion(qid);
                    if (question != null) {
                        // security check
                        if (!questionService.allowEditQuestion(question)) {
                            // redirect to error
                            res.sendRedirect(
                                    res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
                            return;
                        }

                        questions.add(question);
                    }
                }
            }
        }

        // for list of selected questions "qid+qid+qid"
        else {
            String qids[] = StringUtil.split(qidParam, "+");
            for (String qid : qids) {
                // get the question
                Question question = this.questionService.getQuestion(qid);
                if (question != null) {
                    // security check
                    if (!questionService.allowEditQuestion(question)) {
                        // redirect to error
                        res.sendRedirect(
                                res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
                        return;
                    }

                    questions.add(question);
                }
            }
        }

        context.put("questions", questions);
    }

    // render
    uiService.render(ui, context);
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.GrailsAccessDeniedHandlerImpl.java

/**
 * {@inheritDoc}/* ww w.  j a  v  a 2  s  .  c om*/
 * @see org.springframework.security.ui.AccessDeniedHandler#handle(
 *    javax.servlet.ServletRequest, javax.servlet.ServletResponse,
 *    org.springframework.security.AccessDeniedException)
 */
public void handle(final ServletRequest req, final ServletResponse res, final AccessDeniedException e)
        throws IOException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    if (errorPage != null || (ajaxErrorPage != null && request.getHeader(ajaxHeader) != null)) {
        boolean includePort = true;
        String scheme = request.getScheme();
        String serverName = request.getServerName();
        int serverPort = portResolver.getServerPort(request);
        String contextPath = request.getContextPath();
        boolean inHttp = "http".equals(scheme.toLowerCase());
        boolean inHttps = "https".equals(scheme.toLowerCase());

        if (inHttp && (serverPort == 80)) {
            includePort = false;
        } else if (inHttps && (serverPort == 443)) {
            includePort = false;
        }

        String commonRedirectUrl = scheme + "://" + serverName + ((includePort) ? (":" + serverPort) : "")
                + contextPath;
        String redirectUrl = commonRedirectUrl;
        if (ajaxErrorPage != null && request.getHeader(ajaxHeader) != null) {
            redirectUrl += ajaxErrorPage;
        } else if (errorPage != null) {
            redirectUrl += errorPage;
        } else {
            response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());
        }

        response.sendRedirect(response.encodeRedirectURL(redirectUrl));
    }

    if (!response.isCommitted()) {
        // Send 403 (we do this after response has been written)
        response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());
    }
}

From source file:org.etudes.mneme.tool.SelectAddPartQuestionsView.java

/**
 * {@inheritDoc}//w  w  w  . j a va  2 s .c o  m
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2] assessment id, [3] part id
    // [4] sort, [5] page, [6] type filter [7] pool filter [8] survey filter
    // return address in the rest
    if (params.length < 9)
        throw new IllegalArgumentException();

    String destination = null;
    if (params.length > 9) {
        destination = "/" + StringUtil.unsplit(params, 9, params.length - 9, "/");
    }
    // if not specified, go to the main list page
    else {
        destination = "/assessments";
    }
    context.put("return", destination);

    String assessmentId = params[2];
    Assessment assessment = assessmentService.getAssessment(assessmentId);
    if (assessment == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }
    context.put("assessment", assessment);

    // security check
    if (!assessmentService.allowEditAssessment(assessment)) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // part
    String partId = params[3];
    Part part = assessment.getParts().getPart(partId);
    if (part == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }
    context.put("part", part);

    // sort
    String sortCode = params[4];
    context.put("sort_column", sortCode.charAt(0));
    context.put("sort_direction", sortCode.charAt(1));
    QuestionService.FindQuestionsSort sort = findQuestionSortCode(sortCode);

    String typeFilter = params[6];
    context.put("typeFilter", typeFilter);

    // the question types
    List<QuestionPlugin> questionTypes = this.mnemeService.getQuestionPlugins();
    context.put("questionTypes", questionTypes);

    String poolFilter = params[7];
    context.put("poolFilter", poolFilter);
    Pool pool = poolFilter.equals("0") ? null : this.poolService.getPool(poolFilter);

    String surveyFilter = params[8];
    context.put("surveyFilter", surveyFilter);
    Boolean surveyFilterValue = null;
    if ("A".equals(surveyFilter)) {
        surveyFilterValue = Boolean.FALSE;
    } else if ("S".equals(surveyFilter)) {
        surveyFilterValue = Boolean.TRUE;
    }

    // the pools
    List<Pool> pools = this.poolService.findPools(toolManager.getCurrentPlacement().getContext(),
            FindPoolsSort.title_a, null);

    context.put("pools", pools);

    // paging
    Integer maxQuestions = null;
    if (pool == null) {
        maxQuestions = this.questionService.countQuestions(this.toolManager.getCurrentPlacement().getContext(),
                null, (typeFilter.equals("0") ? null : typeFilter), surveyFilterValue, Boolean.TRUE);
    } else {
        maxQuestions = this.questionService.countQuestions(pool, null,
                (typeFilter.equals("0") ? null : typeFilter), surveyFilterValue, Boolean.TRUE);
    }
    String pagingParameter = params[5];
    if ("-".equals(pagingParameter)) {
        pagingParameter = "1-" + Integer.toString(this.pageSizes.get(0));
    }
    Paging paging = uiService.newPaging();
    paging.setMaxItems(maxQuestions);
    paging.setCurrentAndSize(pagingParameter);
    context.put("paging", paging);

    // get questions - even invalids
    List<Question> questions = null;

    if (pool == null) {
        questions = questionService.findQuestions(this.toolManager.getCurrentPlacement().getContext(), sort,
                null, (typeFilter.equals("0") ? null : typeFilter),
                paging.getSize() == 0 ? null : paging.getCurrent(),
                paging.getSize() == 0 ? null : paging.getSize(), surveyFilterValue, null);
    } else {
        questions = questionService.findQuestions(pool, sort, null,
                (typeFilter.equals("0") ? null : typeFilter),
                paging.getSize() == 0 ? null : paging.getCurrent(),
                paging.getSize() == 0 ? null : paging.getSize(), surveyFilterValue, null);
    }
    context.put("questions", questions);

    // compute the current destination, except for being at page one
    // this will match "current" in the filter drop-down values, which are all set to send to page one.
    String newDestination = "/" + params[1] + "/" + params[2] + "/" + params[3] + "/" + sortCode + "/" + "1"
            + "-" + paging.getSize().toString() + "/" + typeFilter + "/" + poolFilter + "/" + surveyFilter
            + destination;

    // for the selected question type
    Value value = this.uiService.newValue();
    value.setValue(newDestination);
    context.put("selectedQuestionType", value);

    // for the selected pool
    value = this.uiService.newValue();
    value.setValue(newDestination);
    context.put("selectedPool", value);

    // for the survey filter
    value = this.uiService.newValue();
    value.setValue(newDestination);
    context.put("selectedQuestionSurvey", value);

    // pages sizes
    if (this.pageSizes.size() > 1) {
        context.put("pageSizes", this.pageSizes);
    }

    // for the selected "for" part
    value = this.uiService.newValue();
    value.setValue(part.getId());
    context.put("partId", value);

    // render
    uiService.render(ui, context);
}

From source file:org.sakaiproject.portal.util.ErrorReporter.java

/**
 * Accept the user feedback post./*from w  ww  . ja  v  a 2 s  .c o m*/
 * 
 * @param req
 *        The request.
 * @param res
 *        The response.
 */
public void postResponse(HttpServletRequest req, HttpServletResponse res) {
    String bugId = req.getParameter("bugid");
    String session = req.getParameter("session");
    String user = req.getParameter("user");
    String time = req.getParameter("time");
    String comment = req.getParameter("comment");
    String problem = req.getParameter("problem");
    String problemdigest = req.getParameter("problemdigest");
    String problemRequest = req.getParameter("problemRequest");
    String problemPlacement = req.getParameter("problemPlacement");

    // log and send the followup email
    logAndMail(bugId, session, user, time, problem, problemdigest, null, problemRequest, problemPlacement,
            comment);

    // always redirect from a post
    try {
        res.sendRedirect(res.encodeRedirectURL(ServerConfigurationService.getPortalUrl() + "/error-reported"));
    } catch (IOException e) {
        M_log.warn(rbDefault.getString("bugreport.troubleredirecting"), e);
    }
}

From source file:ams.fwk.channel.web.AmsRequestView.java

public void render(IRequestContext requestCtx, IResponseContext responseCtx) throws RenderException {

    super.render(requestCtx, responseCtx);

    HttpServletRequest request = (HttpServletRequest) responseCtx.getReadProtocol();

    HttpServletResponse response = (HttpServletResponse) responseCtx.getWriteProtocol();

    /*//from   w w  w  .j  a  v  a  2s.  c om
     * nc_target target ,   ?    url? .
     *  ?  properties? ? path   ? 
     */
    String target = null;
    if (request.getParameter(Constants.TARGET) != null) {
        target = BaseUtils.getConfiguration(request.getParameter(Constants.TARGET));
        if (StringUtils.isEmpty(target)) {
            target = (String) request.getParameter(Constants.TARGET);
        }
    } else {
        target = this.target;
    }

    /*
     * forward/redirect .
     */
    boolean isForwarding = true;
    if (target.startsWith(FORWARD_KEY)) {
        target = target.substring(FORWARD_KEY.length());
    } else if (target.startsWith(REDIRECT_KEY)) {
        isForwarding = false;
        target = target.substring(REDIRECT_KEY.length());
    }

    try {
        if (isForwarding) {
            request.getRequestDispatcher(target).forward(request, response);
        } else {
            String redirectPage = target.startsWith("/") ? request.getContextPath() + target : target;
            response.sendRedirect(response.encodeRedirectURL(redirectPage));
        }
    } catch (Exception e) {
        if (logger.isErrorEnabled()) {
            logger.error("Exception occurred while forward jsp to " + target, e);
        }
        e.printStackTrace();

        // ?  
        // -. ServletException
        // -. IOException
        throw new RenderException("SKFS1010", new String[] { target, e.getLocalizedMessage() }, e);
    }
}

From source file:de.hybris.platform.ytelcoacceleratorstorefront.filters.cms.CMSSiteFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse,
        final FilterChain filterChain) throws ServletException, IOException {
    final String requestURL = httpRequest.getRequestURL().toString();

    final CmsPageRequestContextData cmsPageRequestContextData = getCmsPageContextService()
            .initialiseCmsPageContextForRequest(httpRequest);

    //check whether exits valid preview data
    if (cmsPageRequestContextData.getPreviewData() == null) {
        //process normal request (i.e. normal browser non-cmscockpit request)
        if (processNormalRequest(httpRequest, httpResponse)) {
            //proceed filters
            filterChain.doFilter(httpRequest, httpResponse);
        }//from  w w  w .  j ava 2s. com
    } else if (StringUtils.contains(requestURL, PREVIEW_TOKEN)) {
        final String redirectURL = processPreviewRequest(httpRequest, cmsPageRequestContextData);

        //redirect to computed URL
        if (redirectURL.charAt(0) == '/') {
            final String contextPath = httpRequest.getContextPath();
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(contextPath + redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        } else {
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        }

        //next filter in chain won't be invoked!!!
    } else {
        //proceed filters
        filterChain.doFilter(httpRequest, httpResponse);
    }
}

From source file:com.acc.storefront.filters.cms.CMSSiteFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse,
        final FilterChain filterChain) throws ServletException, IOException {
    final String requestURL = httpRequest.getRequestURL().toString();

    final CmsPageRequestContextData cmsPageRequestContextData = getCmsPageContextService()
            .initialiseCmsPageContextForRequest(httpRequest);

    // check whether exits valid preview data
    if (cmsPageRequestContextData.getPreviewData() == null) {
        // process normal request (i.e. normal browser non-cmscockpit request)
        if (processNormalRequest(httpRequest, httpResponse)) {
            // proceed filters
            filterChain.doFilter(httpRequest, httpResponse);
        }/* ww w . j  ava  2 s .  c om*/
    } else if (StringUtils.contains(requestURL, PREVIEW_TOKEN)) {
        final String redirectURL = processPreviewRequest(httpRequest, cmsPageRequestContextData);

        // redirect to computed URL
        if (redirectURL.charAt(0) == '/') {
            final String contextPath = httpRequest.getContextPath();
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(contextPath + redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        } else {
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        }

        // next filter in chain won't be invoked!!!
    } else {
        // proceed filters
        filterChain.doFilter(httpRequest, httpResponse);
    }
}