Example usage for org.springframework.web.util WebUtils INCLUDE_REQUEST_URI_ATTRIBUTE

List of usage examples for org.springframework.web.util WebUtils INCLUDE_REQUEST_URI_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.web.util WebUtils INCLUDE_REQUEST_URI_ATTRIBUTE.

Prototype

String INCLUDE_REQUEST_URI_ATTRIBUTE

To view the source code for org.springframework.web.util WebUtils INCLUDE_REQUEST_URI_ATTRIBUTE.

Click Source Link

Document

Standard Servlet 2.3+ spec request attribute for include request URI.

Usage

From source file:net.paoding.rose.web.RequestPath.java

public RequestPath(HttpServletRequest request) {
    // method//from  w  ww  .  j  a  v a2s.com
    setMethod(parseMethod(request));

    // ctxpath
    setCtxpath(request.getContextPath());
    String invocationCtxpath = null; // includeinvocationCtxPathincludectxpath
    // dispather, uri, ctxpath
    String uri;
    if (WebUtils.isIncludeRequest(request)) {
        setDispatcher(Dispatcher.INCLUDE);
        uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
        invocationCtxpath = ((String) request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE));
        setRosePath((String) request.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE));
    } else {
        uri = request.getRequestURI();
        this.setRosePath(request.getServletPath());
        if (request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) == null) {
            this.setDispatcher(Dispatcher.REQUEST);
        } else {
            this.setDispatcher(Dispatcher.FORWARD);
        }
    }
    if (uri.startsWith("http://") || uri.startsWith("https://")) {
        int start = uri.indexOf('/', 9);
        if (start == -1) {
            uri = "";
        } else {
            uri = uri.substring(start);
        }
    }
    if (uri.indexOf('%') != -1) {
        try {
            String encoding = request.getCharacterEncoding();
            if (encoding == null || encoding.length() == 0) {
                encoding = "UTF-8";
            }
            uri = URLDecoder.decode(uri, encoding);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    this.setUri(uri);
    // requestPathctxpathincludeinvocationCtxpath

    if (getCtxpath().length() <= 1) {
        setRosePath(getUri());
    } else {
        setRosePath(
                getUri().substring((invocationCtxpath == null ? getCtxpath() : invocationCtxpath).length()));
    }
}

From source file:com.sinosoft.one.mvc.web.RequestPath.java

public RequestPath(HttpServletRequest request) {
    // method/*from  w w w  .j av  a2  s.c  o  m*/
    setMethod(parseMethod(request));

    // ctxpath
    setCtxpath(request.getContextPath());
    String invocationCtxpath = null; // includeinvocationCtxPathincludectxpath
    // dispather, uri, ctxpath
    String uri;
    if (WebUtils.isIncludeRequest(request)) {
        setDispatcher(Dispatcher.INCLUDE);
        uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
        invocationCtxpath = ((String) request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE));
        setMvcPath((String) request.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE));
    } else {
        if (request.getAttribute(MvcConstants.WINDOW_REQUEST_URI) != null) {
            uri = (String) request.getAttribute(MvcConstants.WINDOW_REQUEST_URI);
            request.removeAttribute(MvcConstants.WINDOW_REQUEST_URI);
            request.setAttribute(MvcConstants.IS_WINDOW_REQUEST, "1");
        } else {
            uri = request.getRequestURI();
            request.removeAttribute(MvcConstants.IS_WINDOW_REQUEST);
        }

        this.setMvcPath(request.getServletPath());
        if (request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) == null) {
            this.setDispatcher(Dispatcher.REQUEST);
        } else {
            this.setDispatcher(Dispatcher.FORWARD);
        }
    }
    if (uri.startsWith("http://") || uri.startsWith("https://")) {
        int start = uri.indexOf('/', 9);
        if (start == -1) {
            uri = "";
        } else {
            uri = uri.substring(start);
        }
    }
    if (uri.indexOf('%') != -1) {
        try {
            String encoding = request.getCharacterEncoding();
            if (encoding == null || encoding.length() == 0) {
                encoding = "UTF-8";
            }
            uri = URLDecoder.decode(uri, encoding);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    this.setUri(uri);
    // requestPathctxpathincludeinvocationCtxpath

    if (getCtxpath().length() <= 1) {
        setMvcPath(getUri());
    } else {
        setMvcPath(getUri().substring((invocationCtxpath == null ? getCtxpath() : invocationCtxpath).length()));
    }
}

From source file:org.hyperic.hq.ui.servlet.RenditServlet.java

public static boolean requestIsValid(HttpServletRequest req) {
    String reqUri = (String) req.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
    boolean useInclude = false;

    if (reqUri != null)
        useInclude = true;//w w w .  j  a  v a  2 s. co  m
    if (reqUri == null && !useInclude)
        reqUri = req.getRequestURI();

    List fullPath = StringUtil.explode(reqUri, "/");
    int pathSize = fullPath.size();

    Iterator<String> it = fullPath.iterator();
    while (it.hasNext()) {
        if ("..".equals(it.next())) {
            return false;
        }
    }

    if (_log.isDebugEnabled()) {
        _log.debug("Examining path: " + fullPath);
    }

    if (pathSize < 3) {
        _log.warn("Illegal request path [" + fullPath + "]");
        return false;
    }
    String elem1 = (String) fullPath.get(1);
    String elem2 = (String) fullPath.get(2);

    if (elem1.equals("public") || elem2.equals("public"))
        return true;

    if (pathSize < 4 || !fullPath.get(pathSize - 4).equals("hqu")) {
        _log.warn("Illegal request path [" + fullPath + "]");
        return false;
    }

    String lastElem = (String) fullPath.get(pathSize - 1);
    if (lastElem.endsWith(".hqu") == false) {
        _log.warn("non .hqu file requested [" + fullPath + "]");
        return false;
    }

    return true;
}

From source file:org.hyperic.hq.ui.servlet.RenditServlet.java

protected void handleRequest(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    boolean useInclude = false;

    // Since we may be processing via an internal RequestDispatcher 
    // include(), we need to investigate the subrequest URIs, etc.
    // and use those, as Tomcat won't set them up in subrequest objects
    String reqUri = (String) req.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
    if (reqUri != null)
        useInclude = true;//w ww . j av  a 2  s .com
    if (reqUri == null && !useInclude)
        reqUri = req.getRequestURI();

    String ctxPath = (String) req.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE);
    if (ctxPath != null)
        useInclude = true;
    if (ctxPath == null && !useInclude)
        ctxPath = req.getContextPath();

    String pathInfo = (String) req.getAttribute(WebUtils.INCLUDE_PATH_INFO_ATTRIBUTE);
    if (pathInfo != null)
        useInclude = true;
    if (pathInfo == null && !useInclude)
        pathInfo = req.getPathInfo();

    String servletPath = (String) req.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE);
    if (servletPath != null)
        useInclude = true;
    if (servletPath == null && !useInclude)
        servletPath = req.getServletPath();

    String queryStr = (String) req.getAttribute(WebUtils.INCLUDE_QUERY_STRING_ATTRIBUTE);
    if (queryStr != null)
        useInclude = true;
    if (queryStr == null && !useInclude)
        queryStr = req.getQueryString();

    List fullPath = StringUtil.explode(reqUri, "/");
    int pathSize = fullPath.size();

    if (_log.isDebugEnabled()) {
        _log.debug("Request path [" + fullPath + "]");
    }

    if (((String) fullPath.get(pathSize - 1)).endsWith(".groovy")) {
        _log.warn(".groovy file requested [" + fullPath + "]");
        throw new ServletException("Illegal request path [" + fullPath + "]");
    }

    if (!requestIsValid(req)) {
        throw new ServletException("Illegal request path [" + fullPath + "]");
    }

    List subPath = fullPath.subList(pathSize - 3, fullPath.size());

    String plugin = (String) subPath.get(0);
    if (_log.isDebugEnabled()) {
        _log.debug("Request for [" + plugin + "]: " + reqUri + (queryStr == null ? "" : ("?" + queryStr)));
    }

    int sessId = RequestUtils.getSessionIdInt(req);
    WebApplicationContext springContext = WebApplicationContextUtils
            .getWebApplicationContext(getServletContext());
    AuthzBoss authzBoss = springContext.getBean(AuthzBoss.class);

    AuthzSubject user;

    try {
        user = authzBoss.getCurrentSubject(sessId);
    } catch (SessionException e) {
        // Could not get the current user.  We should default to a 'nobody'
        // user here.
        _log.error("Unable to get current user.  Bailing", e);
        throw new ServletException(e);
    }

    RequestInvocationBindings b = new RequestInvocationBindings(reqUri, ctxPath, pathInfo, servletPath,
            queryStr, user, req, resp, getServletContext());
    long start = System.currentTimeMillis();
    try {
        Bootstrap.getBean(RenditServer.class).handleRequest(plugin, b);
    } catch (Exception e) {
        throw new ServletException(e);
    } finally {
        _log.debug("Processed request for [" + plugin + "] in " + (System.currentTimeMillis() - start) + " ms");
    }
}

From source file:org.springframework.web.servlet.DispatcherServlet.java

private static String getRequestUri(HttpServletRequest request) {
    String uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
    if (uri == null) {
        uri = request.getRequestURI();//from  w  w w .j a  va2 s  .  co  m
    }
    return uri;
}

From source file:org.springframework.web.util.UrlPathHelper.java

/**
 * Return the request URI for the given request, detecting an include request
 * URL if called within a RequestDispatcher include.
 * <p>As the value returned by {@code request.getRequestURI()} is <i>not</i>
 * decoded by the servlet container, this method will decode it.
 * <p>The URI that the web container resolves <i>should</i> be correct, but some
 * containers like JBoss/Jetty incorrectly include ";" strings like ";jsessionid"
 * in the URI. This method cuts off such incorrect appendices.
 * @param request current HTTP request/*from   ww w  .  j a  v a2s. c  o  m*/
 * @return the request URI
 */
public String getRequestUri(HttpServletRequest request) {
    String uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE);
    if (uri == null) {
        uri = request.getRequestURI();
    }
    return decodeAndCleanUriString(request, uri);
}