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

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

Introduction

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

Prototype

String INCLUDE_QUERY_STRING_ATTRIBUTE

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

Click Source Link

Document

Standard Servlet 2.3+ spec request attribute for include query string.

Usage

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;/*from   w  w w . j a  v a 2 s.  c  o m*/
    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");
    }
}