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.muse.mneme.tool.AssessmentsView.java

/**
 * {@inheritDoc}//from  w w  w.  j  a  v a  2 s. co m
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // sort (optional)
    if ((params.length != 2) && (params.length != 3)) {
        throw new IllegalArgumentException();
    }

    // security check
    if (!assessmentService.allowManageAssessments(this.toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // default is due date, ascending
    String sort = (params.length > 2) ? params[2] : "0A";

    // for the selected select
    Values values = this.uiService.newValues();
    context.put("ids", values);

    // for the dates
    final AssessmentService assessmentService = this.assessmentService;
    PopulatingSet assessments = uiService.newPopulatingSet(new Factory() {
        public Object get(String id) {
            // add a draw to the part
            Assessment assessment = assessmentService.getAssessment(id);
            return assessment;
        }
    }, new Id() {
        public String getId(Object o) {
            return ((Assessment) o).getId();
        }
    });
    context.put("assessments", assessments);

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

    // save the dates
    for (Iterator i = assessments.getSet().iterator(); i.hasNext();) {
        Assessment assessment = (Assessment) i.next();
        try {
            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;
        }
    }

    // for an add
    if (destination.equals("ADD")) {
        try {
            Assessment assessment = this.assessmentService
                    .newAssessment(this.toolManager.getCurrentPlacement().getContext());
            destination = "/assessment_edit/" + sort + "/" + assessment.getId();
        } catch (AssessmentPermissionException e) {
            // redirect to error
            res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
            return;
        }
    }

    else if (destination.equals("ARCHIVE")) {
        for (String id : values.getValues()) {
            Assessment assessment = this.assessmentService.getAssessment(id);
            if (assessment != null) {
                assessment.setArchived(Boolean.TRUE);
                try {
                    this.assessmentService.saveAssessment(assessment);
                    destination = context.getDestination();
                } 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;
                }
            }
        }
    }

    else if (destination.equals("UNPUBLISH")) {
        for (String id : values.getValues()) {
            Assessment assessment = this.assessmentService.getAssessment(id);
            if (assessment != null) {
                try {
                    assessment.setPublished(Boolean.FALSE);
                    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;
                }
            }
        }

        destination = context.getDestination();
    }

    else if (destination.equals("DELETE")) {
        for (String id : values.getValues()) {
            Assessment assessment = this.assessmentService.getAssessment(id);
            if (assessment != null) {
                try {
                    if (this.assessmentService.allowRemoveAssessment(assessment)) {
                        this.assessmentService.removeAssessment(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;
                }
            }
        }

        destination = context.getDestination();
    }

    else if (destination.startsWith("DUPLICATE:")) {
        String[] parts = StringUtil.split(destination, ":");
        if (parts.length != 2) {
            throw new IllegalArgumentException();
        }
        String aid = parts[1];
        try {
            Assessment assessment = this.assessmentService.getAssessment(aid);
            if (assessment == null) {
                throw new IllegalArgumentException();
            }
            this.assessmentService.copyAssessment(toolManager.getCurrentPlacement().getContext(), assessment);
            destination = context.getDestination();
        } catch (AssessmentPermissionException e) {
            // redirect to error
            res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
            return;
        }
    }

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

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

/**
 * {@inheritDoc}//from  w  w  w  .ja v a 2 s  . c om
 */
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();
    }

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

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

    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;
    }
    context.put("question", question);

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

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

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

/**
 * {@inheritDoc}//from w  ww.  j  a va  2  s  . c  om
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2] assessment id, [3] part id, [4] sort, return address in the rest
    if (params.length < 5)
        throw new IllegalArgumentException();

    String assessmentId = params[2];
    String partId = params[3];

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

    Part part = assessment.getParts().getPart(partId);
    if (part == 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;
    }

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

    final Assessment asmnt = assessment;
    final PoolService pservice = this.poolService;
    PopulatingSet draws = uiService.newPopulatingSet(new Factory() {
        public Object get(String id) {
            // add a virtual draw to the part, matching one from the DrawPart if there is one, else a new 0 count one.
            PoolDraw draw = asmnt.getParts().getVirtualDraw(pservice.getPool(id));
            return draw;
        }
    }, new Id() {
        public String getId(Object o) {
            return ((PoolDraw) o).getPool().getId();
        }
    });
    context.put("draws", draws);

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

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

    // get the new part id
    String newPartId = value.getValue();
    if (!part.getId().equals(newPartId)) {
        // create a new part?
        if ("0".equals(newPartId)) {
            try {
                Part created = assessment.getParts().addPart();
                this.assessmentService.saveAssessment(assessment);
                newPartId = created.getId();
            } 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;
            }
        }

        Part newPart = assessment.getParts().getPart(newPartId);
        if (newPart != null) {
            part = newPart;

            // adjust the destination to use this part, if the destination is back to me
            String[] destParts = StringUtil.split(destination, "/");
            if (destParts[1].equals("draw_questions")) {
                destParts[3] = part.getId();
                destination = StringUtil.unsplit(destParts, 0, destParts.length, "/");
            }
        }
    }

    // update the draws in the assessment parts
    assessment.getParts().updateDraws(new ArrayList<PoolDraw>(draws.getSet()), part);

    // commit the save
    try {
        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.FinalReviewView.java

/**
 * {@inheritDoc}/*  w  w  w .  j a  v  a2 s .  c  o  m*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // sid and return
    if (params.length < 3) {
        throw new IllegalArgumentException();
    }

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

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

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

    // if other than the /submitted destination, just go there
    if (!destination.startsWith("/submitted")) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
        return;
    }

    String submissionId = params[2];

    // this post is from the timer, or the "submit" button, and completes the submission
    TocView.submissionCompletePost(req, res, context, submissionId, this.uiService, this.submissionService,
            returnDestination);
}

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

/**
 * {@inheritDoc}/*w w w . j  a  v a  2s  .  co  m*/
 */
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, "/");
    }

    // 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.josso.gateway.signon.LoginAction.java

/**
 * @param e           is the <AuthenticationFailureException> Exception to br handled
 * @param request     is the <HttpServletRequest> context
 * @param response    is the <HttpServletResponse> context
 * @param credentials contains the <Crdential> used to perform de authentication
 * @return false will execute the default mapping.findForward otherwise no action will be taken
 */// ww  w. ja v a  2s. c o m
protected boolean onLoginAuthenticationException(AuthenticationFailureException e, HttpServletRequest request,
        HttpServletResponse response, Credential[] credentials) throws IOException {

    String cmd = getSSOCmd(request);
    if (cmd != null && cmd.equals("login_optional")) {

        // Go back to agent ...
        String back_to = getBackTo(request);

        // We're going back to the partner app.
        if (logger.isDebugEnabled())
            logger.debug("[login()], Login Optional failed, redirecting user to : " + back_to);

        response.sendRedirect(response.encodeRedirectURL(back_to));
        return true; // We handled the redirect
    }

    String on_error = (String) request.getSession(true).getAttribute(KEY_JOSSO_ON_ERROR);

    if (on_error == null) {
        // Check for a configured custom login url
        try {
            SSOWebConfiguration cfg = Lookup.getInstance().lookupSSOWebConfiguration();
            if (cfg.isBasicAuthenticationEnabled()) {
                on_error = cfg.getCustomLoginURL();
            }
        } catch (Exception ex) {
            logger.error(e.getMessage(), e);
        }
    }

    if (on_error != null) {

        // TODO : Improve error information handling, this could be managed with an outbound mechanism, like assertions.

        // Add error type and received username to ERROR URL.
        SSOGateway g = getSSOGateway();
        on_error += (on_error.indexOf("?") >= 0 ? "&" : "?") + "josso_error_type=" + e.getErrorType();
        try {
            SSOContext ctx = SSOContext.getCurrent();
            on_error += "&josso_username=" + g.getPrincipalName(ctx.getScheme(), credentials);
        } catch (Exception ex) {
            if (logger.isDebugEnabled())
                logger.error("  [onLoginAuthenticationException()] cant find PrincipalName");
        }

        response.sendRedirect(response.encodeRedirectURL(on_error));
        if (logger.isDebugEnabled())
            logger.debug("[login()], authentication failure. Redirecting user to : " + on_error);

        return true;
    }

    return false;
}

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

/**
 * {@inheritDoc}//from w w w  .j  av  a  2 s  .  c om
 */
public void get(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();

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

    // next and prev, based on the sort
    String sortCode = "userName_a";
    SubmissionService.FindAssessmentSubmissionsSort sort = null;
    int destinationStartsAt = 6;
    if (params.length > 4)
        sortCode = params[5];
    try {
        sort = SubmissionService.FindAssessmentSubmissionsSort.valueOf(sortCode);
    } catch (IllegalArgumentException e) {
        // no sort, so it must be part of destination
        destinationStartsAt = 5;
        sortCode = "userName_a";
    }
    if (sort != null) {
        // one submission per user (i.e. 'official' only), except for survey, where we consider them all
        Boolean official = Boolean.valueOf(submission.getAssessment().getType() != AssessmentType.survey);

        String[] nextPrev = submissionService.findPrevNextSubmissionIds(submission, sort, official);
        if (nextPrev[0] != null)
            context.put("prev", nextPrev[0]);
        if (nextPrev[1] != null)
            context.put("next", nextPrev[1]);
    }
    context.put("sort", sortCode);

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

    // if not specified, go to the main grade_assessment page for this assessment
    else {
        destination = "/grade_assessment/0A/" + submission.getAssessment().getId();
    }
    context.put("return", destination);

    // paging parameter
    String pagingParameter = null;
    if (params.length > 3)
        pagingParameter = params[3];
    if ((pagingParameter == null) || (pagingParameter.length() == 0) || (pagingParameter.equals("-"))) {
        pagingParameter = "1-" + Integer.toString(this.defaultPageSize);
    }

    // paging
    Paging paging = uiService.newPaging();
    paging.setMaxItems(submission.getAnswers().size());
    paging.setCurrentAndSize(pagingParameter);
    context.put("paging", paging);

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

    // pick the page of answers
    List<Answer> answers = submission.getAnswersOrdered();
    if (paging.getSize() != 0) {
        // start at ((pageNum-1)*pageSize)
        int start = ((paging.getCurrent().intValue() - 1) * paging.getSize().intValue());
        if (start < 0)
            start = 0;
        if (start > answers.size())
            start = answers.size() - 1;

        // end at ((pageNum)*pageSize)-1, or max-1, (note: subList is not inclusive for the end position)
        int end = paging.getCurrent().intValue() * paging.getSize().intValue();
        if (end < 0)
            end = 0;
        if (end > answers.size())
            end = answers.size();

        answers = answers.subList(start, end);
    }
    context.put("answers", answers);

    String anchor = params[4];
    if (!anchor.equals("-"))
        context.put("anchor", anchor);

    // needed by some of the delegates to show the score
    context.put("grading", Boolean.TRUE);

    uiService.render(ui, context);
}

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

/**
 * {@inheritDoc}// ww  w . ja va 2 s. com
 */
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);
    context.put("return", destination);

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

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

/**
 * {@inheritDoc}//from w ww .ja v a2s . co 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 guest page
    else {
        destination = "/guest_view";
    }

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

    // security check
    if (!this.assessmentService.allowGuest(this.toolManager.getCurrentPlacement().getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    context.put("assessment", assessment);
    context.put("return", destination);

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

From source file:org.kuali.mobility.sakai.controllers.SakaiController.java

@RequestMapping(value = "/{siteId}/attachment", method = RequestMethod.GET)
public String getAnnouncementAttachment(HttpServletRequest request, HttpServletResponse response,
        @PathVariable("siteId") String siteId, @RequestParam(value = "attachmentId") String attachmentId,
        @RequestParam(value = "type") String type, Model uiModel) {
    User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY);

    byte[] fileData = sakaiSiteService.findAnnouncementAttachment(siteId, attachmentId, user.getUserId());

    try {/*from w ww. ja  v  a 2s.co  m*/
        if (type.equals(Constants.URL_MIME_TYPE)) {
            String url = new String(fileData);
            response.sendRedirect(response.encodeRedirectURL(url));
        } else {
            response.setContentType(type);
            response.setContentLength(fileData.length);
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + getFileName(attachmentId) + "\"");
            response.getOutputStream().write(fileData, 0, fileData.length);
            return null;
        }
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
    return null;
}