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:org.etudes.mneme.tool.EvalNotifView.java

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

    String assessmentId = params[2];

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

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

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

    context.put("notifSample", submissionService.getEvalNotificationSample(assessment));

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

From source file:org.muse.mneme.tool.QuestionEditView.java

/**
 * {@inheritDoc}//from w w w . j  ava  2  s  .  c o  m
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2] pool_sort / [3] pool_id / [4] question_sort / [5] question_page / [6] question_id
    if ((params.length != 7))
        throw new IllegalArgumentException();
    String questionId = params[6];

    // put the extra parameters all together
    String extras = StringUtil.unsplit(params, 2, 4, "/");
    context.put("extras", extras);

    // get the question to work on
    Question question = this.questionService.getQuestion(questionId);
    if (question == null)
        throw new IllegalArgumentException();

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

    // put the question in the context
    context.put("question", question);

    uiService.render(ui, context);
}

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

/**
 * {@inheritDoc}// w ww .  j  a v  a2 s. c o m
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2]grades sort code, [3]aid, [4]qid, |optional ->| [5]sort, [6]page, [7] anchor
    if (params.length < 5)
        throw new IllegalArgumentException();

    // assessment
    Assessment assessment = this.assessmentService.getAssessment(params[3]);
    if (assessment == null) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // check for user permission to access the assessments for grading
    if (!this.submissionService.allowEvaluate(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    final SubmissionService submissionService = this.submissionService;
    PopulatingSet answers = uiService.newPopulatingSet(new Factory() {
        public Object get(String id) {
            Answer answer = submissionService.getAnswer(id);
            return answer;
        }
    }, new Id() {
        public String getId(Object o) {
            return ((Answer) o).getId();
        }
    });
    context.put("answers", answers);

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

    // post-process the answers
    for (Object o : answers.getSet()) {
        Answer a = (Answer) o;
        a.getTypeSpecificAnswer().consolidate(destination);
    }

    // check for remove
    if (destination.startsWith("STAY_REMOVE:")) {
        String[] parts = StringUtil.splitFirst(destination, ":");
        if (parts.length == 2) {
            parts = StringUtil.splitFirst(parts[1], ":");
            if (parts.length == 2) {
                // find the answer, id=parts[0], ref=parts[1]
                for (Object o : answers.getSet()) {
                    Answer answer = (Answer) o;
                    if (answer.getId().equals(parts[0])) {
                        Reference ref = this.attachmentService.getReference(parts[1]);
                        answer.getEvaluation().removeAttachment(ref);
                        this.attachmentService.removeAttachment(ref);
                        break;
                    }
                }
            }
        }
    }

    if (destination.startsWith("STAY_")) {
        String newAnchor = "-";

        String[] parts = StringUtil.splitFirst(destination, ":");
        if (parts.length == 2) {
            String[] anchor = StringUtil.splitFirst(parts[1], ":");
            if (anchor.length > 0) {
                newAnchor = anchor[0];
            }
        }

        // rebuild the current destination with the new anchor
        if (params.length > 7) {
            params[7] = newAnchor;
            destination = StringUtil.unsplit(params, "/");
        } else {
            // sort code
            String sortCode = null;
            if (params.length > 5) {
                sortCode = params[5];
            }
            if (sortCode == null) {
                if (assessment.getAnonymous()) {
                    sortCode = "1D";
                } else {
                    sortCode = "0A";
                }
            }

            // paging parameter
            String pagingParameter = null;
            if (params.length > 6)
                pagingParameter = params[6];
            if (pagingParameter == null) {
                pagingParameter = "1-" + Integer.toString(this.pageSizes.get(0));
            }

            destination = context.getDestination() + "/" + sortCode + "/" + pagingParameter + "/" + newAnchor;
        }
    }

    // save
    try {
        // for single question assessment, we need to save the overall submissions, because mark-evaluated and release are submission level
        // this picks up answer evaluations too.
        if (assessment.getIsSingleQuestion()) {
            for (Object a : answers.getSet()) {
                this.submissionService.evaluateSubmission(((Answer) a).getSubmission());
            }
        }

        // otherwise we can just save the answers
        else {
            this.submissionService.evaluateAnswers(answers.getSet());
        }
    } catch (AssessmentPermissionException e) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unexpected)));
        return;
    }

    // if there was an upload error, send to the upload error
    if ((req.getAttribute("upload.status") != null) && (!req.getAttribute("upload.status").equals("ok"))) {
        res.sendRedirect(res.encodeRedirectURL(
                Web.returnUrl(req, "/error/" + Errors.upload + "/" + req.getAttribute("upload.limit"))));
        return;
    }

    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

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

/**
 * {@inheritDoc}/*from  w  w w.j av  a2s.  c om*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    if (params.length < 5) {
        throw new IllegalArgumentException();
    }

    String sort = params[2];
    String assmtIds = params[3];
    String choiceSettings = params[4];

    // aid and return
    Assessment assessment = (Assessment) assessmentService
            .newEmptyAssessment(this.toolManager.getCurrentPlacement().getContext());
    if (assessment == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

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

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

    String chSets[] = StringUtil.split(choiceSettings, "+");

    String aIds[] = StringUtil.split(assmtIds, "+");
    for (String aId : aIds) {
        Assessment assmt = this.assessmentService.getAssessment(aId);

        // security check
        if (assessmentService.allowEditAssessment(assmt)) {
            for (String chSet : chSets) {
                if (chSet.equals("ao") || chSet.equals("ts")) {
                    assmt.setHasTriesLimit(assessment.getHasTriesLimit());
                    assmt.setTries(assessment.getTries());
                }
                if (chSet.equals("ao") || chSet.equals("tls")) {
                    assmt.setHasTimeLimit(assessment.getHasTimeLimit());
                    assmt.setTimeLimit(assessment.getTimeLimit());
                }
                if (chSet.equals("ao") || chSet.equals("ro")) {
                    assmt.getReview().setTiming(assessment.getReview().getTiming());
                    assmt.getReview().setDate(assessment.getReview().getDate());
                    assmt.getReview().setShowFeedback(assessment.getReview().getShowFeedback());
                    assmt.getReview().setShowSummary(assessment.getReview().getShowSummary());

                    if (assmt.getType() != AssessmentType.survey) {
                        if (assessment.getReview().getShowSummary())
                            assmt.getReview().setShowCorrectAnswer(ReviewShowCorrect.yes);
                        else
                            assmt.getReview()
                                    .setShowCorrectAnswer(assessment.getReview().getShowCorrectAnswer());
                    }

                }
                if (chSet.equals("ao") || chSet.equals("ac")) {
                    if (assmt.getType() != AssessmentType.survey) {
                        assmt.setMinScoreSet(assessment.getMinScoreSet());
                        assmt.setMinScore(assessment.getMinScore());
                    }
                }
                if (chSet.equals("ao") || chSet.equals("rs"))
                    assmt.getGrading().setAutoRelease(assessment.getGrading().getAutoRelease());
                if (chSet.equals("ao") || chSet.equals("ma"))
                    assmt.setShowModelAnswer(assessment.getShowModelAnswer());
                if (chSet.equals("ao") || chSet.equals("sg")) {
                    if (assmt.getHasPoints())
                        assmt.getGrading()
                                .setGradebookIntegration(assessment.getGrading().getGradebookIntegration());
                }
                if (chSet.equals("ao") || chSet.equals("ag")) {
                    if (assmt.getType() != AssessmentType.survey)
                        assmt.getGrading().setAnonymous(assessment.getGrading().getAnonymous());
                }
                if (chSet.equals("ao") || chSet.equals("ae")) {
                    assmt.setResultsEmail(assessment.getResultsEmail());
                }
                if (chSet.equals("ao") || chSet.equals("pw")) {
                    assmt.getPassword().setPassword(assessment.getPassword().getPassword());
                }
                if (chSet.equals("ao") || chSet.equals("hp"))
                    assmt.setRequireHonorPledge(assessment.getRequireHonorPledge());
                if (chSet.equals("ao") || chSet.equals("hns"))
                    assmt.setShowHints(assessment.getShowHints());
                if (chSet.equals("ao") || chSet.equals("sc"))
                    assmt.setShuffleChoicesOverride(assessment.getShuffleChoicesOverride());
                if (chSet.equals("ao") || chSet.equals("navlay")) {
                    if (assmt.getType() != AssessmentType.assignment) {
                        assmt.setRandomAccess(assessment.getRandomAccess());
                        assmt.setQuestionGrouping(assessment.getQuestionGrouping());
                    } else {
                        assmt.setQuestionGrouping(assessment.getQuestionGrouping());
                    }
                }
                if (chSet.equals("ao") || chSet.equals("pn"))
                    assmt.getParts().setContinuousNumbering(assessment.getParts().getContinuousNumbering());
                if (chSet.equals("ao") || chSet.equals("fm"))
                    assmt.getSubmitPresentation().setText(assessment.getSubmitPresentation().getText());
                // commit the save
                try {
                    this.assessmentService.saveAssessment(assmt);
                } catch (AssessmentPermissionException e) {
                    M_log.warn("Multiple assessments saving " + e);
                } catch (AssessmentPolicyException e) {
                    M_log.warn("Multiple assessments saving " + e);
                }
            }
        }
    }

    if ("DONE".equals(destination)) {
        destination = "/assessments/" + sort;
    }

    // if destination became null
    if (destination == null) {
        destination = context.getDestination();
    }

    // if destination is stay here
    else if (destination.startsWith("STAY:")) {
        String[] parts = StringUtil.splitFirst(destination, ":");
        destination = context.getDestination() + "?focus=" + parts[1];
    }
    // redirect to the next destination
    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

From source file:alpha.portal.webapp.controller.ReloadController.java

/**
 * Handle request.//from w  w  w  .  j  a v a  2  s  . c o  m
 * 
 * @param request
 *            the request
 * @param response
 *            the response
 * @return the model and view
 * @throws Exception
 *             the exception
 */
@RequestMapping(method = RequestMethod.GET)
@SuppressWarnings("unchecked")
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception {
    if (this.log.isDebugEnabled()) {
        this.log.debug("Entering 'execute' method");
    }

    StartupListener.setupContext(request.getSession().getServletContext());

    final String referer = request.getHeader("Referer");

    if (referer != null) {
        this.log.info("reload complete, reloading user back to: " + referer);
        List<String> messages = (List) request.getSession().getAttribute(BaseFormController.MESSAGES_KEY);

        if (messages == null) {
            messages = new ArrayList();
        }

        messages.add("Reloading options completed successfully.");
        request.getSession().setAttribute(BaseFormController.MESSAGES_KEY, messages);

        response.sendRedirect(response.encodeRedirectURL(referer));
        return null;
    } else {
        response.setContentType("text/html");

        final PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Context Reloaded</title>");
        out.println("</head>");
        out.println("<body bgcolor=\"white\">");
        out.println("<script type=\"text/javascript\">");
        out.println("alert('Context Reload Succeeded! Click OK to continue.');");
        out.println("history.back();");
        out.println("</script>");
        out.println("</body>");
        out.println("</html>");
    }

    return null;
}

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

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

    String assessmentId = params[2];

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

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

    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;
    }

    context.put("assessment", assessment);

    // format an invalid message
    if (!assessment.getIsValid()) {
        context.put("invalidMsg", AssessmentInvalidView.formatInvalidDisplay(assessment, this.messages));
    }

    if (params.length == 4)
        context.put("testprintformat", params[3]);
    else
        context.put("testprintformat", "testonly");
    // render
    uiService.render(ui, context);
}

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

/**
 * {@inheritDoc}// ww w  .j ava 2  s .c om
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2]sid, [3] paging, [4] anchor, [5]next/prev sort (optional- leave out to disable next/prev), optionally followed by a return destination
    if (params.length < 5)
        throw new IllegalArgumentException();

    final Submission submission = this.submissionService.getSubmission(params[2]);
    if (submission == null) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // check for user permission to access the submission for grading
    if (!this.submissionService.allowEvaluate(submission)) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    context.put("submission", submission);

    // so we can deal with the answers by id
    PopulatingSet answers = uiService.newPopulatingSet(new Factory() {
        public Object get(String id) {
            Answer answer = submission.getAnswer(id);
            return answer;
        }
    }, new Id() {
        public String getId(Object o) {
            return ((Answer) o).getId();
        }
    });
    context.put("answers", answers);

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

    // post-process the answers
    for (Object o : answers.getSet()) {
        Answer a = (Answer) o;
        a.getTypeSpecificAnswer().consolidate(destination);
    }

    // check for remove
    if (destination.startsWith("STAY_REMOVE:")) {
        String[] parts = StringUtil.splitFirst(destination, ":");
        if (parts.length == 2) {
            parts = StringUtil.splitFirst(parts[1], ":");
            if (parts.length == 2) {
                Reference ref = this.attachmentService.getReference(parts[1]);
                this.attachmentService.removeAttachment(ref);

                // if this is for the overall evaluation
                if (parts[0].equals("SUBMISSION")) {
                    submission.getEvaluation().removeAttachment(ref);
                } else {
                    // find the answer, id=parts[0], ref=parts[1]
                    Answer answer = submission.getAnswer(parts[0]);
                    if (answer != null) {
                        answer.getEvaluation().removeAttachment(ref);
                    }
                }
            }
        }
    }

    if (destination.startsWith("STAY_")) {
        String newAnchor = "-";

        String[] parts = StringUtil.splitFirst(destination, ":");
        if (parts.length == 2) {
            String[] anchor = StringUtil.splitFirst(parts[1], ":");
            if (anchor.length > 0) {
                newAnchor = anchor[0];
            }
        }

        // rebuild the current destination with the new anchor
        params[4] = newAnchor;
        destination = StringUtil.unsplit(params, "/");
    }

    else if (destination.equals("SAVE")) {
        destination = context.getDestination();
    }

    // save graded submission
    try {
        this.submissionService.evaluateSubmission(submission);
    } catch (AssessmentPermissionException e) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // if there was an upload error, send to the upload error
    if ((req.getAttribute("upload.status") != null) && (!req.getAttribute("upload.status").equals("ok"))) {
        res.sendRedirect(res.encodeRedirectURL(
                Web.returnUrl(req, "/error/" + Errors.upload + "/" + req.getAttribute("upload.limit"))));
        return;
    }

    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

From source file:org.muse.mneme.tool.GradeQuestionView.java

/**
 * {@inheritDoc}// ww  w.j  a va 2  s .co m
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2]grades sort code, [3]aid, [4]qid, |optional ->| [5]sort, [6]page, [7] anchor
    if (params.length < 5)
        throw new IllegalArgumentException();

    // check for user permission to access the assessments for grading
    if (!this.submissionService.allowEvaluate(toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // the sort for the grades view
    context.put("sort_grades", params[2]);

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

    // question
    Question question = assessment.getParts().getQuestion(params[4]);
    if (question == null) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }
    context.put("question", question);

    // sort code
    String sortCode = null;
    if (params.length > 5) {
        sortCode = params[5];
    }
    if (sortCode == null) {
        if (assessment.getAnonymous()) {
            sortCode = "1A";
        } else {
            sortCode = "0A";
        }
    }

    // parse into a sort
    SubmissionService.FindAssessmentSubmissionsSort sort = null;
    if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'A')) {
        sort = SubmissionService.FindAssessmentSubmissionsSort.userName_a;
    } else if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'D')) {
        sort = SubmissionService.FindAssessmentSubmissionsSort.userName_d;
    } else if ((sortCode.charAt(0) == '1') && (sortCode.charAt(1) == 'A')) {
        sort = SubmissionService.FindAssessmentSubmissionsSort.final_a;
    } else if ((sortCode.charAt(0) == '1') && (sortCode.charAt(1) == 'D')) {
        sort = SubmissionService.FindAssessmentSubmissionsSort.final_d;
    }
    if (sort == null) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }
    context.put("sort_column", sortCode.charAt(0));
    context.put("sort_direction", sortCode.charAt(1));

    // get the size - from all submissions
    Integer maxAnswers = this.submissionService.countSubmissionAnswers(assessment, question);

    // paging parameter
    String pagingParameter = null;
    if (params.length > 6)
        pagingParameter = params[6];
    if (pagingParameter == null) {
        pagingParameter = "1-" + Integer.toString(this.pageSizes.get(0));
    }
    Paging paging = uiService.newPaging();
    paging.setMaxItems(maxAnswers);
    paging.setCurrentAndSize(pagingParameter);
    context.put("paging", paging);

    // get the answers - from all submissions
    List<Answer> answers = this.submissionService.findSubmissionAnswers(assessment, question, sort,
            paging.getSize() == 0 ? null : paging.getCurrent(),
            paging.getSize() == 0 ? null : paging.getSize());
    context.put("answers", answers);

    // so we know we are grading
    context.put("grading", Boolean.TRUE);

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

    if (params.length > 7) {
        String anchor = params[7];
        if (!anchor.equals("-")) {
            context.put("anchor", anchor);
        }
    }

    uiService.render(ui, context);
}

From source file:org.mycore.iview2.frontend.MCRTileCombineServlet.java

/**
 * prepares render process and gets IView2 file and combines tiles.
 * The image dimensions and path are determined from {@link HttpServletRequest#getPathInfo()}:
 * <code>/{zoomAlias}/{derivateID}/{absoluteImagePath}</code>
 * where <code>zoomAlias</code> is mapped like this:
 * <table>//from   w w w .  j  av a  2 s. c  o  m
 * <caption>Mapping of zoomAlias to actual zoom level</caption>
 * <tr><th>zoomAlias</th><th>zoom level</th></tr>
 * <tr><td>'MIN'</td><td>1</td></tr>
 * <tr><td>'MID'</td><td>2</td></tr>
 * <tr><td>'MAX'</td><td>3</td></tr>
 * <tr><td>default and all others</td><td>0</td></tr>
 * </table>
 * 
 * See {@link #init()} how to attach a footer to every generated image.
 */
@Override
protected void think(final MCRServletJob job) throws IOException, JDOMException {
    final HttpServletRequest request = job.getRequest();
    try {
        String pathInfo = request.getPathInfo();
        if (pathInfo.startsWith("/")) {
            pathInfo = pathInfo.substring(1);
        }
        String zoomAlias = pathInfo.substring(0, pathInfo.indexOf('/'));
        pathInfo = pathInfo.substring(zoomAlias.length() + 1);
        final String derivate = pathInfo.substring(0, pathInfo.indexOf('/'));
        String imagePath = pathInfo.substring(derivate.length());
        LOGGER.info("Zoom-Level: " + zoomAlias + ", derivate: " + derivate + ", image: " + imagePath);
        final Path iviewFile = MCRImage.getTiledFile(MCRIView2Tools.getTileDir(), derivate, imagePath);
        try (FileSystem fs = MCRIView2Tools.getFileSystem(iviewFile)) {
            Path iviewFileRoot = fs.getRootDirectories().iterator().next();
            final MCRTiledPictureProps pictureProps = MCRTiledPictureProps
                    .getInstanceFromDirectory(iviewFileRoot);
            final int maxZoomLevel = pictureProps.getZoomlevel();
            request.setAttribute(THUMBNAIL_KEY, iviewFile);
            LOGGER.info("IView2 file: " + iviewFile);
            int zoomLevel = 0;
            switch (zoomAlias) {
            case "MIN":
                zoomLevel = 1;
                break;
            case "MID":
                zoomLevel = 2;
                break;
            case "MAX":
                zoomLevel = 3;
                break;
            }
            HttpServletResponse response = job.getResponse();
            if (zoomLevel > maxZoomLevel) {
                switch (maxZoomLevel) {
                case 2:
                    zoomAlias = "MID";
                    break;
                case 1:
                    zoomAlias = "MIN";
                    break;
                default:
                    zoomAlias = "THUMB";
                    break;
                }
                if (!imagePath.startsWith("/"))
                    imagePath = "/" + imagePath;
                String redirectURL = response.encodeRedirectURL(MessageFormat.format("{0}{1}/{2}/{3}{4}",
                        request.getContextPath(), request.getServletPath(), zoomAlias, derivate, imagePath));
                response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                response.setHeader("Location", redirectURL);
                response.flushBuffer();
                return;
            }
            if (zoomLevel == 0 && footerImpl == null) {
                //we're done, sendThumbnail is called in render phase
                return;
            }
            ImageReader reader = MCRIView2Tools.getTileImageReader();
            try {
                BufferedImage combinedImage = MCRIView2Tools.getZoomLevel(iviewFileRoot, pictureProps, reader,
                        zoomLevel);
                if (combinedImage != null) {
                    if (footerImpl != null) {
                        BufferedImage footer = footerImpl.getFooter(combinedImage.getWidth(), derivate,
                                imagePath);
                        combinedImage = attachFooter(combinedImage, footer);
                    }
                    request.setAttribute(IMAGE_KEY, combinedImage);
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    return;
                }
            } finally {
                reader.dispose();
            }
        }

    } finally {
        LOGGER.info("Finished sending " + request.getPathInfo());
    }
}

From source file:org.wso2.carbon.identity.authenticator.office365.Office365Authenticator.java

/**
 * initiate the authentication request/*from   ww  w . j  ava 2  s .co m*/
 */
@Override
protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response,
        AuthenticationContext context) throws AuthenticationFailedException {
    Map<String, String> authenticatorProperties = context.getAuthenticatorProperties();
    String clientId = authenticatorProperties.get(OIDCAuthenticatorConstants.CLIENT_ID);
    String redirectUri = authenticatorProperties.get(Office365AuthenticatorConstants.CALLBACK_URL);
    String loginPage = getAuthorizationServerEndpoint(context.getAuthenticatorProperties());
    String queryParams = Office365AuthenticatorConstants.STATE + "=" + context.getContextIdentifier();
    try {
        response.sendRedirect(response.encodeRedirectURL(
                loginPage + "?" + queryParams + "&" + Office365AuthenticatorConstants.CLIENT_ID + "=" + clientId
                        + "&" + Office365AuthenticatorConstants.RESPONSE_TYPE + "="
                        + OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE + "&"
                        + Office365AuthenticatorConstants.REDIRECT_URI + "=" + redirectUri + "&"
                        + Office365AuthenticatorConstants.Resource + "="
                        + Office365AuthenticatorConstants.OFFICE365_RESOURCE));
    } catch (IOException e) {
        throw new AuthenticationFailedException("Error while redirecting", e);
    }
}