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

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

Introduction

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

Prototype

String INCLUDE_CONTEXT_PATH_ATTRIBUTE

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

Click Source Link

Document

Standard Servlet 2.3+ spec request attribute for include context path.

Usage

From source file:com.capgemini.b2bassets.storefront.web.mvc.AcceleratorUrlPathHelperTest.java

@Test
public void testGetContextPath() {
    final AcceleratorUrlPathHelper pathHelper = new AcceleratorUrlPathHelper();
    request.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, TEST_VALUE);
    request.setAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE, TEST_VALUE);
    final String result = pathHelper.getContextPath(request);
    Assertions.assertThat(result.equals(StringUtils.EMPTY)).isTrue();
}

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

public RequestPath(HttpServletRequest request) {
    // method/*ww  w .j a v  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));
        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 a v  a 2  s .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));
        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:edu.northwestern.bioinformatics.studycalendar.web.tools.SecureSectionInterceptorTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    alice = createUser("alice", PscRole.STUDY_SUBJECT_CALENDAR_MANAGER);
    eve = createUser("eve", PscRole.STUDY_TEAM_ADMINISTRATOR, PscRole.DATA_READER);
    SecurityContextHolderTestHelper.setSecurityContext(alice, EMPTY);

    beanFactory = new DefaultListableBeanFactory();

    interceptor = new SecureSectionInterceptor();
    interceptor.setApplicationSecurityManager(applicationSecurityManager);
    ControllerRequiredAuthorityExtractor extractor = new ControllerRequiredAuthorityExtractor();
    interceptor.setControllerRequiredAuthorityExtractor(extractor);
    interceptor.postProcessBeanFactory(beanFactory);

    workloadTask = new Task();
    workloadTask.setLinkName("workloadController");

    Task scheduleTask = new Task();
    scheduleTask.setLinkName("scheduleController");

    managementSection = new Section();
    managementSection.setDisplayName("Management");
    managementSection.setTasks(asList(workloadTask));
    managementSection.setPathMapping("/**");

    subjectSection = new Section();
    subjectSection.setDisplayName("Subjects");
    subjectSection.setTasks(asList(scheduleTask));
    subjectSection.setPathMapping("/**");

    interceptor.setSections(asList(managementSection, subjectSection));

    request.setAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE, "/psc");

    // Bean Name: siteCoordController    Alias: /workloadController
    registerControllerBean("workload", WorkloadController.class);

    // Bean Name: subjCoordController   Alias: /scheduleController
    registerControllerBean("schedule", ScheduleController.class);
}

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  ww.  j  av 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");
    }
}

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

/**
 * Return the context path for the given request, detecting an include request
 * URL if called within a RequestDispatcher include.
 * <p>As the value returned by {@code request.getContextPath()} is <i>not</i>
 * decoded by the servlet container, this method will decode it.
 * @param request current HTTP request//from  w  w  w.j a va2 s . c  om
 * @return the context path
 */
public String getContextPath(HttpServletRequest request) {
    String contextPath = (String) request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE);
    if (contextPath == null) {
        contextPath = request.getContextPath();
    }
    if ("/".equals(contextPath)) {
        // Invalid case, but happens for includes on Jetty: silently adapt it.
        contextPath = "";
    }
    return decodeRequestString(request, contextPath);
}