List of usage examples for javax.servlet.http HttpServletResponse encodeUrl
@Deprecated
public String encodeUrl(String url);
From source file:org.shredzone.cilla.web.tag.ImageTag.java
@Override public int doStartTag() throws JspException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String url = null;/*from w ww . j a v a2 s. co m*/ Integer outWidth = null, outHeight = null; LinkBuilder lb = linkService.linkTo(); if (picture != null) { lb.view("picture").picture(picture); unlockService.unlockStore(request.getSession(), picture); if (type != null) { lb.param("type", type); } else { outWidth = picture.getWidth(); outHeight = picture.getHeight(); } url = lb.toString(); } else if (header != null && (uncropped == null || uncropped == false)) { lb.view("headerImage").header(header).toString(); if (type != null) { lb.param("type", type); } else { outWidth = header.getWidth(); outHeight = header.getHeight(); } url = lb.toString(); } else if (header != null && uncropped != null && uncropped == true) { lb.view("headerUncropped").header(header); if (type != null) { lb.param("type", type); } url = lb.toString(); } else if (medium != null) { lb.view("medium").page(medium.getPage()).param("name", medium.getImage().getName()); if (type != null) { lb.param("type", type); } url = lb.toString(); } if (url == null) { throw new JspException("No image target was set, or image was not found."); } if (var != null) { TagUtils.setScopedAttribute(pageContext, var, url, scope); return EVAL_BODY_INCLUDE; } HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); StringBuilder imgtag = new StringBuilder(); imgtag.append("<img src=\""); imgtag.append(HtmlUtils.htmlEscape(response.encodeURL(url))); imgtag.append('"'); if (outWidth != null) { imgtag.append(" width=\"").append(outWidth).append('"'); } if (outHeight != null) { imgtag.append(" height=\"").append(outHeight).append('"'); } if (styleClass != null) { imgtag.append(" class=\"").append(HtmlUtils.htmlEscape(styleClass)).append('"'); } if (style != null) { imgtag.append(" style=\"").append(HtmlUtils.htmlEscape(style)).append('"'); } if (title != null) { imgtag.append(" title=\"").append(HtmlUtils.htmlEscape(title)).append('"'); } if (alt != null) { imgtag.append(" alt=\"").append(HtmlUtils.htmlEscape(alt)).append('"'); } imgtag.append(" />"); try { pageContext.getOut().print(imgtag.toString()); } catch (IOException ex) { throw new JspException(ex); } return EVAL_BODY_INCLUDE; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.OntologyController.java
private void doRedirect(HttpServletRequest req, HttpServletResponse res, String redirectURL) throws IOException { //It seems like there must be a more standard way to do a redirect in tomcat. String hn = req.getHeader("Host"); if (req.isSecure()) { res.setHeader("Location", res.encodeURL("https://" + hn + req.getContextPath() + redirectURL)); log.info("doRedirect by using HTTPS"); } else {/* w ww. j a v a 2 s . c om*/ res.setHeader("Location", res.encodeURL("http://" + hn + req.getContextPath() + redirectURL)); log.info("doRedirect by using HTTP"); } res.setStatus(res.SC_SEE_OTHER); }
From source file:de.hybris.platform.addonsupport.controllers.page.AbstractAddOnPageController.java
/** * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not. * //from w w w. ja v a 2 s . c o m * @param request * - request that contains current URL * @param response * response to write "301 Moved Permanently" status to if redirected * @param resolvedUrlPath * - properly resolved URL * @param responseStatusAttributeName * - response attribute name to which write the "301 Moved Permanently" status * @return null if url is properly resolved or redirection string if not * @throws UnsupportedEncodingException */ protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response, final String resolvedUrlPath, final String responseStatusAttributeName) throws UnsupportedEncodingException { try { final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath); final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8"); final String decoded = URIUtil.decode(resolvedUrl, "utf-8"); if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) { return null; } else { request.setAttribute(responseStatusAttributeName, HttpStatus.MOVED_PERMANENTLY); final String queryString = request.getQueryString(); if (queryString != null && !queryString.isEmpty()) { return "redirect:" + resolvedUrlPath + "?" + queryString; } return "redirect:" + resolvedUrlPath; } } catch (final URIException e) { throw new UnsupportedEncodingException(); } }
From source file:org.wings.externalizer.AbstractExternalizeManager.java
public void setResponse(HttpServletResponse response) { if (response != null) { sessionEncoding = response.encodeURL(FOO).substring(FOO.length()); }//from www . j a v a2 s .com }
From source file:de.hybris.platform.acceleratorstorefrontcommons.controllers.pages.AbstractPageController.java
/** * Checks request URL against properly resolved URL and returns null if url is proper or redirection string if not. * * @param request * - request that contains current URL * @param response//from w ww . j a va 2 s .co m * - response to write "301 Moved Permanently" status to if redirected * @param resolvedUrlPath * - properly resolved URL * @return null if url is properly resolved or redirection string if not * @throws UnsupportedEncodingException */ protected String checkRequestUrl(final HttpServletRequest request, final HttpServletResponse response, final String resolvedUrlPath) throws UnsupportedEncodingException { try { final String resolvedUrl = response.encodeURL(request.getContextPath() + resolvedUrlPath); final String requestURI = URIUtil.decode(request.getRequestURI(), "utf-8"); final String decoded = URIUtil.decode(resolvedUrl, "utf-8"); if (StringUtils.isNotEmpty(requestURI) && requestURI.endsWith(decoded)) { return null; } else { // org.springframework.web.servlet.View.RESPONSE_STATUS_ATTRIBUTE = "org.springframework.web.servlet.View.responseStatus" request.setAttribute("org.springframework.web.servlet.View.responseStatus", HttpStatus.MOVED_PERMANENTLY); final String queryString = request.getQueryString(); if (queryString != null && !queryString.isEmpty()) { return "redirect:" + resolvedUrlPath + "?" + queryString; } return "redirect:" + resolvedUrlPath; } } catch (final URIException e) { LOGGER.error("URIException:" + e.getMessage(), e); throw new UnsupportedEncodingException(e.getMessage()); } }
From source file:net.lightbody.bmp.proxy.jetty.servlet.SessionDump.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); Page page = new Page(); HttpSession session = request.getSession(getURI(request).indexOf("new") > 0); page.title("Session Dump Servlet: "); TableForm tf = new TableForm(response.encodeURL(getURI(request))); tf.method("POST"); if (session == null) { page.add("<H1>No Session</H1>"); tf.addButton("Action", "New Session"); } else {/*from w ww . j av a2 s . c o m*/ try { tf.addText("ID", session.getId()); tf.addText("State", session.isNew() ? "NEW" : "Valid"); tf.addText("Creation", new Date(session.getCreationTime()).toString()); tf.addText("Last Access", new Date(session.getLastAccessedTime()).toString()); tf.addText("Max Inactive", "" + session.getMaxInactiveInterval()); tf.addText("Context", "" + session.getServletContext()); Enumeration keys = session.getAttributeNames(); while (keys.hasMoreElements()) { String name = (String) keys.nextElement(); String value = session.getAttribute(name).toString(); tf.addText(name, value); } tf.addTextField("Name", "Property Name", 20, "name"); tf.addTextField("Value", "Property Value", 20, "value"); tf.addTextField("MaxAge", "MaxAge(s)", 5, ""); tf.addButtonArea(); tf.addButton("Action", "Set"); tf.addButton("Action", "Remove"); tf.addButton("Action", "Invalidate"); page.add(tf); tf = null; if (request.isRequestedSessionIdFromCookie()) page.add("<P>Turn off cookies in your browser to try url encoding<BR>"); if (request.isRequestedSessionIdFromURL()) page.add("<P>Turn on cookies in your browser to try cookie encoding<BR>"); } catch (IllegalStateException e) { log.debug(LogSupport.EXCEPTION, e); page.add("<H1>INVALID Session</H1>"); tf = new TableForm(getURI(request)); tf.addButton("Action", "New Session"); } } if (tf != null) page.add(tf); Writer writer = response.getWriter(); page.write(writer); writer.flush(); }
From source file:org.shredzone.cilla.web.tag.LinkTag.java
@Override public int doEndTag() throws JspException { String url = null;/*from w ww . j a v a2 s. com*/ String useTitle = null; lb.view(view); lb.author(author); lb.category(category); lb.page(page); lb.section(section); lb.picture(picture); lb.tag(tag); lb.header(header); lb.ref(ref); lb.qualifier(qualifier); lb.commentable(commentable); if (title != null) { useTitle = title; } else if (page != null) { useTitle = page.getTitle(); } else if (category != null) { useTitle = category.getTitle(); } else if (header != null) { useTitle = header.getCaption(); } if (anchor != null) { lb.anchor(anchor); } url = lb.toString(); if (url == null) { throw new JspException("Cannot link to view '" + view + "'"); } if (var != null) { TagUtils.setScopedAttribute(pageContext, var, url, scope); return EVAL_PAGE; } HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); StringBuilder linktag = new StringBuilder(); linktag.append("<a href=\""); linktag.append(HtmlUtils.htmlEscape(response.encodeURL(url))); linktag.append('"'); if (id != null) { linktag.append(" id=\"").append(HtmlUtils.htmlEscape(id)).append('"'); } if (onclick != null) { linktag.append(" onclick=\"").append(HtmlUtils.htmlEscape(onclick)).append('"'); } if (styleClass != null) { linktag.append(" class=\"").append(HtmlUtils.htmlEscape(styleClass)).append('"'); } if (style != null) { linktag.append(" style=\"").append(HtmlUtils.htmlEscape(style)).append('"'); } if (useTitle != null) { linktag.append(" title=\"").append(HtmlUtils.htmlEscape(useTitle)).append('"'); } linktag.append('>'); try { pageContext.getOut().print(linktag.toString()); BodyContent bc = getBodyContent(); if (bc != null) { bc.writeOut(pageContext.getOut()); } pageContext.getOut().print("</a>"); } catch (IOException ex) { throw new JspException(ex); } return EVAL_PAGE; }
From source file:org.shredzone.cilla.web.tag.FeedTag.java
@Override public int doEndTag() throws JspException { FeedType feedType = FeedType.valueOf(type); LinkBuilder lb = linkService.linkTo(); lb.param("feed", feedType.getSuffix()); if (category != null) { lb.category(category);/*w w w . jav a2 s . c o m*/ } else if (tag != null) { lb.tag(tag); } else if (author != null) { lb.author(author); } else if (ref != null) { lb.ref(ref); } String url = lb.toString(); if (var != null) { TagUtils.setScopedAttribute(pageContext, var, url, scope); return EVAL_PAGE; } HttpServletResponse response = (HttpServletResponse) pageContext.getResponse(); StringBuilder linktag = new StringBuilder(); linktag.append("<link rel=\"alternate\" type=\"").append(feedType.getContentType()).append('"'); if (title != null) { linktag.append(" title=\""); linktag.append(HtmlUtils.htmlEscape(title)); linktag.append('"'); } linktag.append(" href=\""); linktag.append(HtmlUtils.htmlEscape(response.encodeURL(url))); linktag.append("\" />"); try { pageContext.getOut().print(linktag.toString()); } catch (IOException ex) { throw new JspException(ex); } return EVAL_PAGE; }
From source file:org.jahia.bin.TokenChecker.java
public static int checkToken(HttpServletRequest req, HttpServletResponse resp, Map<String, List<String>> parameters) throws UnsupportedEncodingException { String token = parameters.get("form-token") != null ? parameters.get("form-token").get(0) : null; if (token != null) { @SuppressWarnings("unchecked") Map<String, Map<String, List<String>>> toks = (Map<String, Map<String, List<String>>>) req.getSession() .getAttribute("form-tokens"); if (toks != null && toks.containsKey(token)) { Map<String, List<String>> m = toks.get(token); if (m == null) { return INVALID_TOKEN; }//w w w. j a va 2 s. c o m Map<String, List<String>> values = new HashMap<String, List<String>>(m); if (!values.remove(Render.ALLOWS_MULTIPLE_SUBMITS).contains("true")) { toks.remove(token); } values.remove(Render.DISABLE_XSS_FILTERING); // Validate form token List<String> stringList1 = values.remove("form-action"); String formAction = stringList1.isEmpty() ? null : stringList1.get(0); String characterEncoding = SettingsBean.getInstance().getCharacterEncoding(); String requestURI = req.getRequestURI(); if (req.getQueryString() != null) { requestURI += "?" + req.getQueryString(); } if (formAction == null || (!URLDecoder.decode(requestURI, characterEncoding) .equals(URLDecoder.decode(formAction, characterEncoding)) && !URLDecoder.decode(resp.encodeURL(requestURI), characterEncoding) .equals(URLDecoder.decode(formAction, characterEncoding)))) { return INVALID_HIDDEN_FIELDS; } if (!req.getMethod().equalsIgnoreCase(values.remove("form-method").get(0))) { return INVALID_HIDDEN_FIELDS; } for (Map.Entry<String, List<String>> entry : values.entrySet()) { List<String> stringList = entry.getValue(); List<String> parameterValues = parameters.get(entry.getKey()); if (parameterValues == null || !CollectionUtils.isEqualCollection(stringList, parameterValues)) { if (entry.getKey().equals(Render.CAPTCHA)) { return INVALID_CAPTCHA; } return INVALID_HIDDEN_FIELDS; } } return VALID_TOKEN; } return INVALID_TOKEN; } return NO_TOKEN; }
From source file:net.lightbody.bmp.proxy.jetty.servlet.SendRedirect.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache,no-store"); String url = request.getParameter("URL"); if (url != null && url.length() > 0) { response.sendRedirect(url);//w w w .j a v a2 s . c o m } else { PrintWriter pout = response.getWriter(); Page page = null; try { page = new Page(); page.title("SendRedirect Servlet"); page.add(new Heading(1, "SendRedirect Servlet")); page.add(new Heading(1, "Form to generate Dump content")); TableForm tf = new TableForm(response .encodeURL(URI.addPaths(request.getContextPath(), request.getServletPath()) + "/action")); tf.method("GET"); tf.addTextField("URL", "URL", 40, request.getContextPath() + "/dump"); tf.addButton("Redirect", "Redirect"); page.add(tf); page.write(pout); pout.close(); } catch (Exception e) { log.warn(LogSupport.EXCEPTION, e); } } }