List of usage examples for javax.servlet.http HttpServletResponse encodeRedirectUrl
@Deprecated
public String encodeRedirectUrl(String url);
From source file:org.muse.mneme.tool.QuestionsCopyMoveView.java
/** * {@inheritDoc}//from w w w .j a va2 s . com */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [2] pool_sort / [3] pool_id / [4] question_sort / [5] question_page / [6] question_ids / [7] sort if ((params.length != 7) && (params.length != 8)) { throw new IllegalArgumentException(); } // check security if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } String questionIds = params[6]; // put the extra parameters all together String extras = StringUtil.unsplit(params, 2, 4, "/"); context.put("extras", extras); // for the selected pool Value value = this.uiService.newValue(); context.put("selectedPoolId", value); // read form String destination = this.uiService.decode(req, context); if (destination.equals("DOIT")) { String selectedPoolId = value.getValue(); if (selectedPoolId != null) { Pool pool = this.poolService.getPool(selectedPoolId); try { // question id's are in the params array at the index 7 String qids[] = StringUtil.split(questionIds, "+"); for (String qid : qids) { // get the question Question question = this.questionService.getQuestion(qid); if (question != null) { // which function to perform if (path.startsWith("question_copy")) { this.questionService.copyQuestion(question, pool); } else if (path.startsWith("question_move")) { this.questionService.moveQuestion(question, pool); } } } // back to the pool destination = "/pool_edit/" + extras; } 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.jahia.bin.errors.ErrorServlet.java
protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (response.isCommitted()) { logger.warn("Response is already committed. Skipping error processing."); return;/*w ww .j a v a2 s.co m*/ } int errorCode = getErrorCode(request); if (errorCode == HttpServletResponse.SC_UNAUTHORIZED) { String redirectUrl = LoginConfig.getInstance().getCustomLoginUrl(request); if (redirectUrl != null) { response.sendRedirect(response.encodeRedirectURL(redirectUrl)); return; } } response.setStatus(errorCode); response.setContentType("text/html; charset=" + SettingsBean.getInstance().getCharacterEncoding()); response.resetBuffer(); String errorPagePath = getErrorPagePath(request, response); forwardToErrorPage(errorPagePath, request, response); }
From source file:org.muse.mneme.tool.QuestionsCopyMoveView.java
/** * {@inheritDoc}//ww w . j a v a 2 s. co 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_ids / [7] sort if ((params.length != 7) && (params.length != 8)) { throw new IllegalArgumentException(); } // check security if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } String questionIds = params[6]; // put the extra parameters all together String extras = StringUtil.unsplit(params, 2, 4, "/"); context.put("extras", extras); // for sort, this destination without the sort String here = "/" + params[1] + "/" + extras + "/" + questionIds; context.put("here", here); // header and icon dependent on which function if (path.startsWith("question_copy")) { context.put("headerText", messages.get("copy-header-text")); context.put("headerIcon", "/icons/copy.png"); } else if (path.startsWith("question_move")) { context.put("headerText", messages.get("move-header-text")); context.put("headerIcon", "/icons/page_go.png"); } // sort String sortCode = "0A"; if (params.length > 7) sortCode = params[7]; if ((sortCode == null) || (sortCode.length() != 2)) { throw new IllegalArgumentException(); } context.put("sort_column", sortCode.charAt(0)); context.put("sort_direction", sortCode.charAt(1)); PoolService.FindPoolsSort sort = null; // 0 is title if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'A')) { sort = PoolService.FindPoolsSort.title_a; } else if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'D')) { sort = PoolService.FindPoolsSort.title_d; } else { throw new IllegalArgumentException(); } // pools - all but the one we came from String pid = params[3]; Pool pool = this.poolService.getPool(pid); if (pool == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } List<Pool> pools = this.poolService.findPools(toolManager.getCurrentPlacement().getContext(), sort, null); pools.remove(pool); context.put("pools", pools); // render uiService.render(ui, context); }
From source file:org.etudes.mneme.tool.AssessmentSpecialView.java
/** * {@inheritDoc}// www. ja va2 s .co m */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { if (params.length != 4) { throw new IllegalArgumentException(); } // sort parameter for return view String sort = params[2]; // assessment id parameter String aid = params[3]; Assessment assessment = assessmentService.getAssessment(aid); 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; } // not for formal course evaluation if (assessment.getFormalCourseEval()) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // for the ids selected for delete Values values = this.uiService.newValues(); context.put("ids", values); // read form String destination = this.uiService.decode(req, context); if ("DEL".equals(destination)) { // delete the selected ids String[] ids = values.getValues(); if (ids != null && (ids.length > 0)) { for (String id : ids) { AssessmentAccess access = assessment.getSpecialAccess().getAccess(id); if (access != null) { assessment.getSpecialAccess().removeAccess(access); } } } // make sure any undefined user ids or users without permissions are removed assessment.getSpecialAccess().assureValidUsers(); // 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; } destination = context.getDestination(); } // deal with add else if ("ADD".equals(destination)) { AssessmentAccess access = assessment.getSpecialAccess().addAccess(); // 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; } // go edit it destination = "/assessment_access/" + sort + "/" + aid + "/" + access.getId(); } res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.etudes.mneme.tool.ImportMnemeSiteView.java
/** * {@inheritDoc}//from w w w . j a v a2s .co m */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { String returnDestination = null; if (params.length > 2) { returnDestination = "/" + StringUtil.unsplit(params, 2, params.length - 2, "/"); } // if not specified, go to the main assessments page else { returnDestination = "/assessments"; } // TODO: change to assessment service ... if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } Value selectedSite = this.uiService.newValue(); context.put("selectedSite", selectedSite); // read the form String destination = uiService.decode(req, context); // import the pools if ("IMPORT".equals(destination)) { String siteId = selectedSite.getValue(); destination = "/import_mneme/" + siteId + "/" + returnDestination; } res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.etudes.mneme.tool.QuestionsCopyMoveView.java
/** * {@inheritDoc}/*w w w. j av a 2 s . co m*/ */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [, question_move, pool_edit, 21(pool id), 2A, 1-30, pools, 0A, 56, -] - second to last parameter is the list of question ids, last is sort if (params.length < 4) { throw new IllegalArgumentException(); } // check security if (!this.poolService.allowManagePools(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } String questionIds = params[params.length - 2]; // if canceled, a place to return to String returnDest = "/" + StringUtil.unsplit(params, 2, params.length - 4, "/"); context.put("return", returnDest); // for sort, this destination without the sort String here = "/" + params[1] + returnDest + "/" + questionIds; context.put("here", here); // header and icon dependent on which function if (path.startsWith("question_copy")) { context.put("headerText", messages.get("copy-header-text")); context.put("headerIcon", "/icons/copy.png"); } else if (path.startsWith("question_move")) { context.put("headerText", messages.get("move-header-text")); context.put("headerIcon", "/icons/page_go.png"); } // sort String sortCode = "0A"; if (!"-".equals(params[params.length - 1])) sortCode = params[params.length - 1]; if ((sortCode == null) || (sortCode.length() != 2)) { throw new IllegalArgumentException(); } context.put("sort_column", sortCode.charAt(0)); context.put("sort_direction", sortCode.charAt(1)); PoolService.FindPoolsSort sort = null; // 0 is title if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'A')) { sort = PoolService.FindPoolsSort.title_a; } else if ((sortCode.charAt(0) == '0') && (sortCode.charAt(1) == 'D')) { sort = PoolService.FindPoolsSort.title_d; } else { throw new IllegalArgumentException(); } // pools - all but the one we came from String pid = params[3]; Pool pool = this.poolService.getPool(pid); if (pool == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } List<Pool> pools = this.poolService.findPools(toolManager.getCurrentPlacement().getContext(), sort, null); pools.remove(pool); context.put("pools", pools); // render uiService.render(ui, context); }
From source file:org.silverpeas.core.web.util.servlet.GoTo.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String id = getObjectId(req); try {//w w w .ja va 2s .c om String redirect = getDestination(id, req, res); if (!StringUtil.isDefined(redirect)) { objectNotFound(req, res); } else { if (!res.isCommitted()) { // The response was not previously sent if (redirect == null || !redirect.startsWith("http")) { redirect = URLUtil.getApplicationURL() + "/autoRedirect.jsp?" + redirect; } res.sendRedirect(res.encodeRedirectURL(redirect)); } } } catch (AccessForbiddenException afe) { accessForbidden(req, res); } catch (Exception e) { objectNotFound(req, res); } }
From source file:org.muse.mneme.tool.EnterView.java
/** * Send the user into the submission.//w ww .j a v a 2 s . c o m * * @param req * Servlet request. * @param res * Servlet response. * @param submission * The submission set for the user to the assessment so far. * @throws IOException */ protected void enterSubmission(HttpServletRequest req, HttpServletResponse res, Submission submission) throws IOException { Submission enterSubmission = null; try { enterSubmission = submissionService.enterSubmission(submission); } catch (AssessmentClosedException e) { } catch (AssessmentCompletedException e) { } catch (AssessmentPermissionException e) { } if (enterSubmission == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } redirectToQuestion(req, res, enterSubmission, false, true); }
From source file:org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.java
/** * Sends a redirect to the requested url using {@link HttpServletResponse#sendRedirect(String)}.Called to actually * perform flow execution redirects, flow definition redirects, and external redirects. Subclasses may override to * customize general Web Flow system redirect behavior. * @param url the url to redirect to//w ww. j av a 2 s .c o m * @param request the current request * @param response the current response * @throws IOException an exception occurred */ protected void sendRedirect(String url, HttpServletRequest request, HttpServletResponse response) throws IOException { if (ajaxHandler.isAjaxRequest(request, response)) { ajaxHandler.sendAjaxRedirect(url, request, response, false); } else { if (redirectHttp10Compatible) { // Always send status code 302. response.sendRedirect(response.encodeRedirectURL(url)); } else { // Correct HTTP status code is 303, in particular for POST requests. response.setStatus(303); response.setHeader("Location", response.encodeRedirectURL(url)); } } }
From source file:org.etudes.mneme.tool.AssmtSettingsChoiceView.java
/** * {@inheritDoc}/* www . j ava2 s . c o m*/ */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { if (params.length < 4) { throw new IllegalArgumentException(); } String sort = params[2]; String assmtIds = params[3]; Settings settings = (Settings) assessmentService.newEmptySettings(); if (settings == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } // setup the model: the selected assessment context.put("settings", settings); // read the form String destination = uiService.decode(req, context); settings = (Settings) context.get("settings"); boolean optionSet = false; StringBuilder buf = new StringBuilder(); if (settings.getAllOptionsSetting()) { buf.append("ao"); optionSet = true; } else { if (settings.getAnonGradingSetting()) { buf.append("ag"); buf.append("+"); optionSet = true; } if (settings.getAutoEmailSetting()) { buf.append("ae"); buf.append("+"); optionSet = true; } if (settings.getFinalMessageSetting()) { buf.append("fm"); buf.append("+"); optionSet = true; } if (settings.getHintsSetting()) { buf.append("hns"); buf.append("+"); optionSet = true; } if (settings.getHonorPledgeSetting()) { buf.append("hp"); buf.append("+"); optionSet = true; } if (settings.getModelAnswerSetting()) { buf.append("ma"); buf.append("+"); optionSet = true; } if (settings.getNavlaySetting()) { buf.append("navlay"); buf.append("+"); optionSet = true; } if (settings.getPartNumberSetting()) { buf.append("pn"); buf.append("+"); optionSet = true; } if (settings.getPasswordSetting()) { buf.append("pw"); buf.append("+"); optionSet = true; } if (settings.getReleaseSubSetting()) { buf.append("rs"); buf.append("+"); optionSet = true; } if (settings.getAwardCertSetting()) { buf.append("ac"); buf.append("+"); optionSet = true; } if (settings.getReviewOptionsSetting()) { buf.append("ro"); buf.append("+"); optionSet = true; } if (settings.getSendGBSetting()) { buf.append("sg"); buf.append("+"); optionSet = true; } if (settings.getShuffleChoicesSetting()) { buf.append("sc"); buf.append("+"); optionSet = true; } if (settings.getTimeLimitSetting()) { buf.append("tls"); buf.append("+"); optionSet = true; } if (settings.getTriesSetting()) { buf.append("ts"); buf.append("+"); optionSet = true; } } if (optionSet) { if (buf.toString().endsWith("+")) buf.deleteCharAt(buf.length() - 1); } if ("CONTINUE".equals(destination)) { if (optionSet) destination = "/multi_assmt_settings/" + sort + "/" + assmtIds + "/" + buf.toString(); else destination = "/assessments/" + sort; } // if destination became null if (destination == null) { destination = context.getDestination(); } // redirect to the next destination res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }