List of usage examples for javax.servlet.http HttpServletResponse encodeRedirectUrl
@Deprecated
public String encodeRedirectUrl(String url);
From source file:org.muse.mneme.tool.PartEditView.java
/** * {@inheritDoc}/*from ww w. ja va 2 s . c om*/ */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [2]sort for /assessment, [3]aid |[4] pid |optional->| [5]our sort if (params.length < 5 || params.length > 6) throw new IllegalArgumentException(); String assessmentId = params[3]; String partId = params[4]; 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); Values values = null; // based on the part type... PopulatingSet draws = null; if (part instanceof DrawPart) { final DrawPart dpart = (DrawPart) part; final PoolService pservice = this.poolService; 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 = dpart.getVirtualDraw(pservice.getPool(id)); return draw; } }, new Id() { public String getId(Object o) { return ((PoolDraw) o).getPool().getId(); } }); context.put("draws", draws); } // for mpart, we need to collect the checkbox ids else { values = uiService.newValues(); context.put("questionIds", values); } // read the form String destination = uiService.decode(req, context); // filter out draw part draws that are no questions if (part instanceof DrawPart) { // apply the draws to the part DrawPart dpart = (DrawPart) part; dpart.updateDraws(new ArrayList<PoolDraw>(draws.getSet())); } // process the ids into the destination for a redirect to the remove confirm view... else { if (destination.equals("DELETEQ")) { // get the ids String[] removeQuesIds = values.getValues(); if (removeQuesIds != null && removeQuesIds.length != 0) { // remove questions from part for (String removeQuesId : removeQuesIds) { if (removeQuesId != null) { // remove question from part Question question = part.getQuestion(removeQuesId); ((ManualPart) part).removeQuestion(question); } } } destination = context.getDestination(); } } // 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.josso.agent.http.HttpSSOAgent.java
public String buildPostAuthUrl(HttpServletResponse hres, String requestURI, String postAuthURI) { // TODO : Is there a better way to do this ? String encURL = requestURI.replaceAll("&", "%26").replaceAll("\\?", "%3F"); return hres.encodeRedirectURL(postAuthURI + "?josso_original_resource=" + hres.encodeURL(encURL)); }
From source file:com.netspective.sparx.form.DialogContext.java
public void performDefaultRedirect(Writer writer, String redirect) throws IOException { if (!redirectAfterExecute) return;/*from w w w. jav a 2s.c om*/ ServletRequest request = getRequest(); String redirectToUrl = redirect != null ? redirect : request.getParameter(DEFAULT_REDIRECT_PARAM_NAME); if (redirectToUrl == null) { redirectToUrl = request.getParameter(dialog.getPostExecuteRedirectUrlParamName()); if (redirectToUrl == null) redirectToUrl = getNextActionUrl(state.getReferer()); } if (redirectDisabled || redirectToUrl == null) { writer.write("<p><b>Redirect is disabled</b>."); writer.write("<br><code>redirect</code> method parameter is <code>" + redirect + "</code>"); writer.write("<br><code>redirect</code> URL parameter is <code>" + request.getParameter(DEFAULT_REDIRECT_PARAM_NAME) + "</code>"); writer.write("<br><code>redirect</code> form field is <code>" + request.getParameter(dialog.getPostExecuteRedirectUrlParamName()) + "</code>"); writer.write("<br><code>getNextActionUrl</code> method result is <code>" + getNextActionUrl(null) + "</code>"); writer.write("<br><code>original referer</code> url is <code>" + state.getReferer() + "</code>"); writer.write("<p><font color=red>Would have redirected to <code>" + redirectToUrl + "</code>.</font>"); return; } HttpServletResponse response = (HttpServletResponse) getResponse(); if (response.isCommitted()) skin.renderRedirectHtml(writer, this, response.encodeRedirectURL(redirectToUrl)); else sendRedirect(redirectToUrl); }
From source file:org.muse.mneme.tool.SelectAddPartQuestionsView.java
/** * {@inheritDoc}/*from ww w .j av a2 s. co m*/ */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [2]sort for /assessment, [3]aid |[4] pid |optional->| [5]our sort, [6]our page, [7] our type filter, // [8] our pool filter [9] our survey filter if (params.length < 5 || params.length > 10) throw new IllegalArgumentException(); String assessmentId = params[3]; 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; } String partId = params[4]; ManualPart part = (ManualPart) assessment.getParts().getPart(partId); if (part == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } Values values = this.uiService.newValues(); context.put("questionids", values); // read form String destination = this.uiService.decode(req, context); for (String id : values.getValues()) { Question question = this.questionService.getQuestion(id); if (question != null) { part.addQuestion(question); } } // 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; } res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:de.betterform.agent.web.servlet.ViewServlet.java
/** * This method is only called when non-scripted mode is used to update the UI. This basically exists to support * the PFG (POST/FORWARD/GET) pattern that allows to use the browser back button without POSTDATA warning from the browser * and to re-initialize the preceding form (if any). * <p/>/*ww w. j a va2 s .c o m*/ * To make sure that an update is requested from the XFormsSession and not by the user clicking the reload button the * XFormsSession holds a property XFormsSession.UPDATE_REQUEST when coming from XFormsSession. If this property exists, * the UI is refreshed otherwise the form is re-inited with a GET. * * @param request servlet request * @param response servlet response * @throws javax.servlet.ServletException * @throws java.io.IOException */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { XFormsProcessor webAdapter = null; HttpSession session = request.getSession(true); request.setCharacterEncoding("UTF-8"); WebUtil.nonCachingResponse(response); String referer = request.getParameter("referer"); WebProcessor webProcessor = WebUtil.getWebProcessor(request, response, session); try { if (webProcessor == null || webProcessor.getContextParam("update") == null) { LOGGER.info("session does not exist: creating new one"); //todo: this has to be moved out in config or determined from request somehow - this won't work with the XFormsFilter // response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/XFormsServlet?" + referer)); response.sendRedirect(response.encodeRedirectURL(referer)); } else { //todo: check here if we got called by the WebProcessor or directly e.g. through a reload //todo: if not send back to XFormsServlet webProcessor.removeContextParam("update"); response.setContentType(WebUtil.HTML_CONTENT_TYPE); UIGenerator uiGenerator = (UIGenerator) webProcessor.getContextParam(WebProcessor.UIGENERATOR); uiGenerator.setInput(webAdapter.getXForms()); uiGenerator.setOutput(response.getOutputStream()); uiGenerator.generate(); response.getOutputStream().close(); } } catch (Exception e) { webProcessor.close(e); } }
From source file:org.etudes.mneme.tool.GradeQuestionView.java
/** * {@inheritDoc}// ww w.ja v a 2s. c o 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; } // 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); // 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 = "1D"; } 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.sdate_a; } else if ((sortCode.charAt(0) == '1') && (sortCode.charAt(1) == 'D')) { sort = SubmissionService.FindAssessmentSubmissionsSort.sdate_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); } } new CKSetup().setCKCollectionAttrib(getDocsPath(), toolManager.getCurrentPlacement().getContext()); uiService.render(ui, context); }
From source file:org.muse.mneme.tool.HomeView.java
/** * {@inheritDoc}/*from ww w. j a v a 2 s .c o m*/ */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { if (!context.getPostExpected()) { throw new IllegalArgumentException(); } // no parameters expected if (params.length != 2) { throw new IllegalArgumentException(); } // read form Value installValue = this.uiService.newValue(); context.put("installValue", installValue); Value installBulkValue = this.uiService.newValue(); context.put("installBulkValue", installBulkValue); String destination = uiService.decode(req, context); if ("INSTALL".equals(destination)) { if (installValue.getValue() != null) { // add the specs destination = "/install/" + installValue.getValue(); res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); return; } } else if ("INSTALL_BULK".equals(destination)) { if (installBulkValue.getValue() != null) { // add the specs destination = "/install_bulk/" + installBulkValue.getValue(); res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); return; } } else if ("QUESTION_CLEANUP".equals(destination)) { destination = "/question_cleanup"; res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); return; } else if ("INSTALL_TEMPLATES".equals(destination)) { destination = "/install_templates"; res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); return; } destination = "/home"; res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.etudes.mneme.tool.DetailMoveView.java
/** * {@inheritDoc}/*from w w w. ja va 2 s. co m*/ */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // we need a aid[2], detail ids[3], then any number of parameters to form the return destination if (params.length < 4) { throw new IllegalArgumentException(); } String destination = null; if (params.length > 4) { destination = "/" + StringUtil.unsplit(params, 4, params.length - 4, "/"); } // if not specified, go to the main pools page else { destination = "/pools"; } 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; } // security check if (!assessmentService.allowEditAssessment(assessment)) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } // parts List<Part> parts = assessment.getParts().getParts(); context.put("parts", parts); // render uiService.render(ui, context); }
From source file:org.etudes.mneme.tool.ImportMnemeView.java
/** * {@inheritDoc}/*from w w w. ja v a 2 s.c o m*/ */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [2] source context - rest the return destination if (params.length < 3) { throw new IllegalArgumentException(); } String sourceContext = params[2]; String destination = null; if (params.length > 3) { destination = "/" + StringUtil.unsplit(params, 3, params.length - 3, "/"); } // if not specified, go to the main assessments page else { destination = "/assessments"; } context.put("return", destination); // 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; } // the list of assessments for this site List<Ent> assessments = this.importService.getAssessments(sourceContext, toolManager.getCurrentPlacement().getContext()); context.put("assessments", assessments); // render uiService.render(ui, context); }
From source file:eu.hydrologis.stage.geopaparazzi.servlets.ProjectDownloadServiceHandler.java
@Override public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String authHeader = req.getHeader("Authorization"); String[] userPwd = StageUtils.getUserPwdWithBasicAuthentication(authHeader); if (userPwd == null || !LoginChecker.isLoginOk(userPwd[0], userPwd[1])) { throw new ServletException("No permission!"); }/* ww w .ja v a 2 s.c o m*/ // userPwd = new String[]{"testuser"}; Object projectIdObj = req.getParameter("id"); if (projectIdObj != null) { String projectId = (String) projectIdObj; File geopaparazziFolder = StageWorkspace.getInstance().getGeopaparazziFolder(userPwd[0]); File newGeopaparazziFile = new File(geopaparazziFolder, projectId); byte[] data = IOUtils.toByteArray(new FileInputStream(newGeopaparazziFile)); DownloadService service = new DownloadService(data, newGeopaparazziFile.getName()); service.register(); resp.sendRedirect(resp.encodeRedirectURL(service.getURL())); } else { throw new ServletException("No project id provided."); } }