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.AssessmentPreviewView.java

/**
 * {@inheritDoc}// w ww . j  a  v  a2  s .co  m
 */
public void post(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 < 2) {
        throw new IllegalArgumentException();
    }

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

    // go there!
    res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination)));
}

From source file:org.apache.cocoon.servlet.RequestUtil.java

public static String getCompleteUri(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    // Start with servlet path
    String uri = request.getServletPath();
    // uri should never be null, but we check it anyway
    if (uri == null) {
        uri = "";
    }/*from w ww  .j a  va2s. c  om*/

    String pathInfo = request.getPathInfo();
    if (pathInfo != null) {
        // VG: WebLogic fix: Both uri and pathInfo starts with '/'
        // This problem exists only in WL6.1sp2, not in WL6.0sp2 or WL7.0b.
        // Comment: The servletPath always starts with '/', so it seems
        //          that the above mentioned bug is only occuring if the servlet path
        //          is just a "/".
        if (uri.length() > 0 && uri.charAt(0) == '/') {
            uri = uri.substring(1);
        }
        uri += pathInfo;
    }

    if (uri.length() == 0) {
        /*
         * Empty relative URI. Issue HTTP redirect from '/block' to '/block/' to
         * avoid breaking relative URIs in the response generated by the sitemap
         * which expects to be mounted at '.../'.
         */
        String serverAbsoluteUri = request.getRequestURI();
        if (serverAbsoluteUri == null) {
            serverAbsoluteUri = "/";
        } else {
            serverAbsoluteUri += "/";
        }

        response.sendRedirect(response.encodeRedirectURL(serverAbsoluteUri));
        return null;
    }

    if (uri.charAt(0) == '/') {
        uri = uri.substring(1);
    }
    return uri;
}

From source file:org.brutusin.rpc.http.RpcServlet.java

/**
 *
 * @param req/*from www .ja v  a  2 s .c om*/
 * @param resp
 * @throws IOException
 */
private static void addContentLocation(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    StringBuffer requestURL = req.getRequestURL();
    Map<String, String[]> parameterMap = getParameterMap(req);
    boolean first = true;
    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
        String name = entry.getKey();
        String[] value = entry.getValue();
        for (int i = 0; i < value.length; i++) {
            if (first) {
                first = false;
                requestURL.append("?");
            } else {
                requestURL.append("&");
            }
            try {
                requestURL.append(name).append("=")
                        .append(URLEncoder.encode(value[i], resp.getCharacterEncoding()));
            } catch (UnsupportedEncodingException ex) {
                throw new AssertionError();
            }
        }
    }
    resp.addHeader("Content-Location", resp.encodeRedirectURL(requestURL.toString()));
}

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

/**
 * {@inheritDoc}//from   w  w  w .  j a  va 2 s  .co m
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // pools sort, pool id
    if (params.length != 4) {
        throw new IllegalArgumentException();
    }

    String poolsSort = params[2];
    String pid = params[3];

    // get the pool
    Pool pool = this.poolService.getPool(pid);
    if (pool == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // check that the user can manage this pool
    if (!this.poolService.allowManagePools(pool.getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    context.put("poolsSortCode", poolsSort);
    context.put("pool", pool);

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

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

/**
 * {@inheritDoc}/* w w w .  j  a  v  a  2  s .c  o m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need a single parameter (sid)
    if (params.length != 3) {
        throw new IllegalArgumentException();
    }

    String submissionId = params[2];

    Submission submission = submissionService.getSubmission(submissionId);
    if (submission == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // make sure this is a completed submission
    if (!submission.getIsComplete()) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // if we have no authored submitted presentation, skip right to ...
    if (submission.getAssessment().getSubmitPresentation() == null) {
        // if the assessment review is allowed, go to review, else to list
        String dest = "/list";
        if (submission.getMayReview()) {
            dest = "/review/" + submission.getId();
        }

        // redirect
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, dest)));
        return;
    }

    context.put("submission", submission);

    // for the tool navigation
    if (this.assessmentService.allowManageAssessments(toolManager.getCurrentPlacement().getContext())) {
        context.put("maintainer", Boolean.TRUE);
    }

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

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

/**
 * {@inheritDoc}/*from ww w .j a  v  a 2s.  c o m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // [2] grades view sort, [3] aid
    if (params.length != 4)
        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;
    }

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

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

    // check that the assessment is not a formal course evaluation
    if (assessment.getFormalCourseEval()) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // nor a survey
    if (assessment.getType() == AssessmentType.survey) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // validity check
    if (!assessment.getIsValid()) {
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    context.put("assessment", assessment);

    uiService.render(ui, context);
}

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

/**
 * {@inheritDoc}/*from   w  w  w . jav a 2s .co  m*/
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // pools sort, pool id
    if (params.length != 4) {
        throw new IllegalArgumentException();
    }

    String poolsSort = params[2];
    String pid = params[3];

    // get the pool
    Pool pool = this.poolService.getPool(pid);
    if (pool == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // check that the user can manage this pool
    if (!this.poolService.allowManagePools(pool.getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    context.put("poolsSortCode", poolsSort);
    context.put("pool", pool);
    new CKSetup().setCKCollectionAttrib(getDocsPath(), toolManager.getCurrentPlacement().getContext());

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

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

/**
 * {@inheritDoc}/*from   w  w w  . j a  v  a 2 s . c  o  m*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // pools sort, pool id
    if (params.length != 4)
        throw new IllegalArgumentException();
    String poolsSort = params[2];
    String pid = params[3];

    // get the pool
    Pool pool = this.poolService.getPool(pid);
    if (pool == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }

    // if we start out, we are coming from an add
    boolean mint = pool.getMint();

    // check that the user can manage this pool
    if (!this.poolService.allowManagePools(pool.getContext())) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

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

    try {
        this.poolService.savePool(pool);
    } catch (AssessmentPermissionException e) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized)));
        return;
    }

    // change destination to edit if this is new
    if (mint) {
        // make sure we were not deleted
        pool = this.poolService.getPool(pid);
        if (pool != null) {
            // send them to edit pool
            destination = "/pool_edit/" + poolsSort + "/" + pool.getId();
        }
    }

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

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

/**
 * {@inheritDoc}//from   w  w  w. j av a2  s .com
 */
public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    if (params.length < 4) {
        throw new IllegalArgumentException();
    }

    Settings settings = (Settings) assessmentService.newEmptySettings();
    if (settings == null) {
        // redirect to error
        res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid)));
        return;
    }
    // collect information: the selected assessment
    context.put("settings", settings);

    // we carry a sort for the /tests mode
    String sort = "";
    if (params.length == 4) {
        sort = params[2];
    }
    context.put("sort", sort);

    // if we have a focus parameter
    String focus = req.getParameter("focus");
    if (focus != null)
        context.addFocusId(focus);

    // check if we have gradebook
    context.put("gradebookAvailable",
            this.gradesService.available(toolManager.getCurrentPlacement().getContext()));

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

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

/**
 * {@inheritDoc}/*from w  ww  . j  a  va2s .  com*/
 */
public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params)
        throws IOException {
    // we need two parameters (sid/quesiton selector)
    if (params.length != 3) {
        throw new IllegalArgumentException();
    }

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