List of usage examples for javax.servlet.http HttpServletResponse encodeRedirectUrl
@Deprecated
public String encodeRedirectUrl(String url);
From source file:org.xwoot.iwoot.web.servlet.Bootstrap.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from www .j a v a 2 s .co m*/ if (IWootWebApp.getInstance().isStarted()) { System.out.println("Site: " + IWootWebApp.getInstance().getIWootEngine().getId() + " Bootstrap - instance already started"); response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/mainboard.do")); return; } String errors = ""; String iwootPropertiesFile = request.getSession().getServletContext() .getRealPath(IWootWebApp.IWOOT_PROPERTIES_FILENAME); if (request.getParameter("update") != null) { errors = IWootWebApp.getInstance().updatePropertiesFiles(request, iwootPropertiesFile); // Start IWoot if the properties were correctly // saved. if (StringUtils.isBlank(errors)) { Properties p = IWootWebApp.getInstance().getProperties(iwootPropertiesFile); IWootWebApp.getInstance().init(p.getProperty(IWootWebApp.IWOOT_XWOOT_URL_PROPERTY_KEY), p.getProperty(IWootWebApp.IWOOT_WCM_TYPE_PROPERTY_KEY), p.getProperty(IWootWebApp.IWOOT_XWOOT_TYPE_PROPERTY_KEY), p.getProperty(IWootWebApp.IWOOT_REAL_WCM_URL_PROPERTY_KEY), p.getProperty(IWootWebApp.IWOOT_REAL_WCM_LOGIN_PROPERTY_KEY), p.getProperty(IWootWebApp.IWOOT_REAL_WCM_PWD_PROPERTY_KEY), new Integer(RandomUtils.nextInt(1000000) + 1000000)); System.out.println("Site :" + IWootWebApp.getInstance().getIWootEngine().getId() + " Bootstrap - starting instance -"); RestApplication appli = (RestApplication) getServletContext() .getAttribute("com.noelios.restlet.ext.servlet.ServerServlet.application"); if (appli != null) { appli.setIwoot(IWootWebApp.getInstance().getIWootEngine()); } response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/rest")); return; } // There are errors, display the bootstrap page again. errors = errors.replaceAll("\n", "<br/>"); request.setAttribute("errors", errors); } if (!StringUtils.isBlank(iwootPropertiesFile)) { Properties p = IWootWebApp.getInstance().updatePropertiesFromRequest(request, iwootPropertiesFile); request.setAttribute("properties", p); } request.getRequestDispatcher("/pages/Bootstrap.jsp").forward(request, response); return; } catch (Exception e) { System.out.println("EXCEPTION catched !!"); e.printStackTrace(); request.setAttribute("error", e.getMessage()); request.getRequestDispatcher("/pages/Bootstrap.jsp").forward(request, response); return; } }
From source file:com.gs.config.CustomFilterLogin.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Assert.isInstanceOf(HttpServletRequest.class, request, "Can only process HttpServletRequest"); Assert.isInstanceOf(HttpServletResponse.class, response, "Can only process HttpServletResponse"); HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; // System.out.println("ESTOY EN CUSTOMFILTERLOGIN: "+httpRequest.getServletPath()); String path = httpRequest.getServletPath(); HttpSession session = httpRequest.getSession(false); if (session == null && !httpRequest.isRequestedSessionIdValid()) { String targetUrl = httpRequest.getContextPath() + "/login"; httpResponse.sendRedirect(httpResponse.encodeRedirectURL(targetUrl)); return;//from w w w . ja va2s .c o m } chain.doFilter(request, response); }
From source file:org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { if (!(req instanceof HttpServletRequest)) { throw new ServletException("This filter only works for HTTP/HTTPS"); }//from w w w . j a v a 2 s.c o m HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpResp = (HttpServletResponse) resp; if (LOG.isDebugEnabled()) { LOG.debug("Remote address for request is: " + httpReq.getRemoteAddr()); } if (!getProxyAddresses().contains(httpReq.getRemoteAddr())) { String redirectUrl = findRedirectUrl(); redirectUrl = httpResp.encodeRedirectURL(redirectUrl + httpReq.getRequestURI()); httpResp.sendRedirect(redirectUrl); return; } String user = null; if (httpReq.getCookies() != null) { for (Cookie c : httpReq.getCookies()) { if (WebAppProxyServlet.PROXY_USER_COOKIE_NAME.equals(c.getName())) { user = c.getValue(); break; } } } if (user == null) { LOG.warn("Could not find " + WebAppProxyServlet.PROXY_USER_COOKIE_NAME + " cookie, so user will not be set"); chain.doFilter(req, resp); } else { final AmIpPrincipal principal = new AmIpPrincipal(user); ServletRequest requestWrapper = new AmIpServletRequestWrapper(httpReq, principal); chain.doFilter(requestWrapper, resp); } }
From source file:edu.emory.library.tast.database.graphs.GraphsServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); OutputStream stream = response.getOutputStream(); int width = Integer.parseInt(request.getParameter("width")); int height = Integer.parseInt(request.getParameter("height")); JFreeChart chart = (JFreeChart) session.getAttribute(GraphsBean.SESSION_KEY_GRAPH); if (chart == null) { response.encodeRedirectURL("../../images/blank.png"); return;// w w w . java 2 s . c o m } response.setHeader("Cache-Control", "no-cache"); response.setHeader("Cache-Control", "max-age=0"); response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/png"); ChartUtilities.writeChartAsPNG(stream, chart, width, height); }
From source file:org.grails.plugins.zkui.metaclass.RedirectDynamicMethod.java
private Object redirectResponse(String actualUri, HttpServletRequest request, HttpServletResponse response) { if (LOG.isDebugEnabled()) { LOG.debug("Dynamic method [redirect] forwarding request to [" + actualUri + "]"); }//from www . j av a 2s . c o m if (LOG.isDebugEnabled()) { LOG.debug("Executing redirect with response [" + response + "]"); } String redirectUrl = useJessionId ? response.encodeRedirectURL(actualUri) : actualUri; redirectUrl = UriUtil.fixToZk(redirectUrl, request.getContextPath()); Executions.getCurrent().sendRedirect(redirectUrl); Map<String, RedirectEventListener> redirectListeners = applicationContext .getBeansOfType(RedirectEventListener.class); for (RedirectEventListener redirectEventListener : redirectListeners.values()) { redirectEventListener.responseRedirected(redirectUrl); } request.setAttribute(GRAILS_REDIRECT_ISSUED, true); return null; }
From source file:org.etudes.mneme.tool.AssessmentInvalidView.java
/** * {@inheritDoc}//from w ww . j ava 2 s.co m */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { if (params.length != 4) { throw new IllegalArgumentException(); } // read the form String destination = uiService.decode(req, context); // redirect to the next destination res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.etudes.mneme.tool.GuestViewView.java
/** * {@inheritDoc}/*w ww . j ava 2 s . c om*/ */ 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 = this.uiService.decode(req, context); // go there! res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }
From source file:org.etudes.mneme.tool.AssessmentExportView.java
/** * {@inheritDoc}//from w ww .j a v a 2s . co m */ public void get(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { //[, assessment_export, 1679] - params String assessmentIds = params[2]; // security if (!this.assessmentService.allowManageAssessments(toolManager.getCurrentPlacement().getContext())) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.unauthorized))); return; } if (assessmentIds == null) { // redirect to error res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, "/error/" + Errors.invalid))); return; } String[] ids = StringUtil.split(assessmentIds, "+"); List<Assessment> assessments = new ArrayList<Assessment>(); for (String aId : ids) { Assessment assessment = this.assessmentService.getAssessment(aId); if (assessment != null) assessments.add(assessment); } context.put("assessments", assessments); //exportZipName String zipTitle; String siteId = null; try { siteId = toolManager.getCurrentPlacement().getContext(); zipTitle = SiteService.getSite(siteId).getTitle(); } catch (IdUnusedException e) { zipTitle = "ExportAssessments"; } Integer countAssessments = this.assessmentService.countAssessments(siteId); if (countAssessments.intValue() == ids.length) zipTitle = zipTitle + "_allAssessments.zip"; else zipTitle = zipTitle + "_someAssessments.zip"; Reference ref = EntityManager.newReference("/mneme/" + AttachmentService.DOWNLOAD + "/" + AttachmentService.ASMT_EXPORT + "/" + siteId + "/" + assessmentIds + ".zip"); context.put("exportZipName", ref); // render uiService.render(ui, context); }
From source file:net.sf.ginp.GinpServlet.java
/** * Deliver the view that the controller has selected. Do this in * a way that the page is not cached. Also works around a bug in * Session URL Encdoing in Tomcat//w w w . j a v a 2 s.co m * @param req The Servlet Request * @param res The Servlet response * @param url The URL To send to * @throws IOException if there is an error retrieving or * sending the page * @throws ServletException if there is some other error */ private void forwardToPage(final HttpServletRequest req, final HttpServletResponse res, String url) throws IOException, ServletException { Random rnd = new Random(); // Add no cache random number if (url.indexOf("?") == -1) { url = res.encodeRedirectURL(url + "?nocache=" + rnd.nextInt(999999999)); } else { // Pass the parameters throught the urlEncodeParameters method url = res.encodeRedirectURL(url + "&nocache=" + rnd.nextInt(999999999)); } // Add the Path if (!url.startsWith("/")) { String serPath = req.getServletPath(); url = serPath.substring(0, serPath.lastIndexOf("/")) + "/" + url; } // if ;jsessionid= then cookies not used so it is safer to redirect // than forward, due to a bug (or spec requirement) in Tomcat 4 if (url.indexOf(";jsessionid=") != -1) { // debug to log if (log.isDebugEnabled()) { log.debug("redirect to new page url=" + url); } // redirect to new page res.sendRedirect(url); } else { // debug to log if (log.isDebugEnabled()) { log.debug("forward to new page url=" + url); } getServletConfig().getServletContext().getRequestDispatcher(url).forward(req, res); } }
From source file:org.etudes.mneme.tool.AssessmentStatsView.java
/** * {@inheritDoc}//from ww w.j av a2s .co m */ public void post(HttpServletRequest req, HttpServletResponse res, Context context, String[] params) throws IOException { // [2]sort for /grades, [3]aid if (params.length < 4 || params.length > 5) throw new IllegalArgumentException(); // read form String destination = this.uiService.decode(req, context); res.sendRedirect(res.encodeRedirectURL(Web.returnUrl(req, destination))); }