Example usage for org.springframework.web.util UrlPathHelper getPathWithinApplication

List of usage examples for org.springframework.web.util UrlPathHelper getPathWithinApplication

Introduction

In this page you can find the example usage for org.springframework.web.util UrlPathHelper getPathWithinApplication.

Prototype

public String getPathWithinApplication(HttpServletRequest request) 

Source Link

Document

Return the path within the web application for the given request.

Usage

From source file:arena.utils.ServletUtils.java

public static String getURIFromRequest(HttpServletRequest request) {
    UrlPathHelper urlPathHelper = new UrlPathHelper();
    return urlPathHelper.getPathWithinApplication(request);
}

From source file:org.wallride.web.support.SetupRedirectInterceptor.java

private String getRequestPath(HttpServletRequest request) {
    UrlPathHelper urlPathHelper = new UrlPathHelper();
    return urlPathHelper.getPathWithinApplication(request);
    //        return (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
}

From source file:com.gisgraphy.webapp.filter.StaticFilter.java

/**
 * This method checks to see if the current path matches includes or
 * excludes. If it matches includes and not excludes, it forwards to the
 * static resource and ends the filter chain. Otherwise, it forwards to the
 * next filter in the chain.// www. j  a v  a  2  s  .c o  m
 * 
 * @param request
 *                the current request
 * @param response
 *                the current response
 * @param chain
 *                the filter chain
 * @throws ServletException
 *                 when something goes wrong
 * @throws IOException
 *                 when something goes terribly wrong
 */
@Override
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    UrlPathHelper urlPathHelper = new UrlPathHelper();
    String path = urlPathHelper.getPathWithinApplication(request);
    boolean pathExcluded = PatternMatchUtils.simpleMatch(excludes, path);
    boolean pathIncluded = PatternMatchUtils.simpleMatch(includes, path);

    if (pathIncluded && !pathExcluded) {
        if (logger.isDebugEnabled()) {
            logger.debug("Forwarding to static resource: " + path);
        }

        if (path.contains(".html")) {
            response.setContentType("text/html");
        }

        RequestDispatcher rd = getServletContext().getRequestDispatcher(path);
        rd.include(request, response);
        return;
    }

    if (servletName != null) {
        RequestDispatcher rd = getServletContext().getNamedDispatcher(servletName);
        rd.forward(request, response);
        return;
    }

    chain.doFilter(request, response);
}

From source file:ejportal.webapp.filter.StaticFilter.java

/**
 * This method checks to see if the current path matches includes or
 * excludes. If it matches includes and not excludes, it forwards to the
 * static resource and ends the filter chain. Otherwise, it forwards to the
 * next filter in the chain.//w  w w.j a va 2s .com
 * 
 * @param request
 *            the current request
 * @param response
 *            the current response
 * @param chain
 *            the filter chain
 * @throws IOException
 *             when something goes terribly wrong
 * @throws ServletException
 *             when something goes wrong
 */
@Override
public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) throws IOException, ServletException {

    final UrlPathHelper urlPathHelper = new UrlPathHelper();
    final String path = urlPathHelper.getPathWithinApplication(request);
    final boolean pathExcluded = PatternMatchUtils.simpleMatch(this.excludes, path);
    final boolean pathIncluded = PatternMatchUtils.simpleMatch(this.includes, path);

    if (pathIncluded && !pathExcluded) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Forwarding to static resource: " + path);
        }

        if (path.contains(".html")) {
            response.setContentType("text/html");
        }

        final RequestDispatcher rd = this.getServletContext().getRequestDispatcher(path);
        rd.include(request, response);
        return;
    }

    if (this.servletName != null) {
        final RequestDispatcher rd = this.getServletContext().getNamedDispatcher(this.servletName);
        rd.forward(request, response);
        return;
    }

    chain.doFilter(request, response);
}

From source file:info.joseluismartin.gtc.mvc.CacheController.java

/**
 * Parse request and create a new Tile.//from   ww  w.  j  a  v  a2  s  .c  o  m
 * Try to find tile in memory cache first, if not found, try to read from disk, if not found,
 * download tile from server and write it to cache.
 * @throws ServletException 
 */
@RequestMapping("/**")
protected void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {

    UrlPathHelper pathHelper = new UrlPathHelper();
    String requestString = pathHelper.getPathWithinApplication(req);

    if (requestString == null)
        throw new ServletException("The request must include a cache path");

    if (req.getQueryString() != null)
        requestString += "?" + req.getQueryString();

    String cachePath = null;
    String query = null;
    Matcher m = URI_PATTERN.matcher(requestString);

    if (m.find()) {
        cachePath = m.group(1);
        query = pathHelper.decodeRequestString(req, m.group(2));
        if (log.isDebugEnabled()) {
            log.debug("received request: cachePath [" + cachePath + "] query [" + query + "]");
        }
    }

    TileCache cache = cacheService.findCache(cachePath);

    if (cache == null) {
        throw new ServletException("There is not tile cache configured for path [" + cachePath + "]");
    }

    // Have a cache to handle request, now test the tile
    Tile tile = cache.getTile(query);

    String remoteUrlString = cache.getServerUrl(query) + (query.startsWith("?") ? query : "/" + query);
    URL remoteUrl = new URL(remoteUrlString);

    if (tile == null) {
        proxyConnection(req, resp, requestString, cache, remoteUrlString, remoteUrl);
    } else {
        if (tile.isEmpty()) {
            // try three times...
            for (int i = 0; i < 3; i++) {
                try {
                    downloadTile(tile, remoteUrl);
                    break;
                } catch (IOException ioe) {
                    log.error("Error downloading the tile, try: " + i, ioe);
                }
            }
            cache.storeTile(tile);
        }
        // may be still empty
        if (!tile.isEmpty()) {
            resp.setContentType(tile.getMimeType());
            resp.getOutputStream().write(tile.getImage());
        } else {
            throw new ServletException("Cannot download tile: " + tile.toString());
        }
    }
}

From source file:org.codehaus.groovy.grails.web.util.WebUtils.java

/**
 * The Grails dispatch servlet maps URIs like /app/grails/example/index.dispatch. This method infers the
 * controller URI for the dispatch URI so that /app/grails/example/index.dispatch becomes /app/example/index
 *
 * @param request The request//from  ww w . ja va  2  s.co m
 */
public static String getRequestURIForGrailsDispatchURI(HttpServletRequest request) {
    UrlPathHelper pathHelper = new UrlPathHelper();
    if (request.getRequestURI().endsWith(GrailsUrlPathHelper.GRAILS_DISPATCH_EXTENSION)) {
        String path = pathHelper.getPathWithinApplication(request);
        if (path.startsWith(GrailsUrlPathHelper.GRAILS_SERVLET_PATH)) {
            path = path.substring(GrailsUrlPathHelper.GRAILS_SERVLET_PATH.length(), path.length());
        }
        return path.substring(0, path.length() - GrailsUrlPathHelper.GRAILS_DISPATCH_EXTENSION.length());
    }
    return pathHelper.getPathWithinApplication(request);
}

From source file:org.openhie.openempi.webapp.filter.StaticFilter.java

/**
 * This method checks to see if the current path matches includes or excludes. If it matches includes and
 * not excludes, it forwards to the static resource and ends the filter chain. Otherwise, it forwards to the
 * next filter in the chain./*from  ww  w.j  av a2  s  .  c  o m*/
 *
 * @param request the current request
 * @param response the current response
 * @param chain the filter chain
 * @throws ServletException when something goes wrong
 * @throws IOException when something goes terribly wrong
 */
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    UrlPathHelper urlPathHelper = new UrlPathHelper();
    String path = urlPathHelper.getPathWithinApplication(request);
    boolean pathExcluded = PatternMatchUtils.simpleMatch(excludes, path);
    boolean pathIncluded = PatternMatchUtils.simpleMatch(includes, path);

    if (pathIncluded && !pathExcluded) {
        if (logger.isDebugEnabled()) {
            logger.debug("Forwarding to static resource: " + path);
        }

        if (path.contains(".html")) {
            response.setContentType("text/html");
        }

        RequestDispatcher rd = getServletContext().getRequestDispatcher(path);
        rd.include(request, response);
        return;
    }

    if (servletName != null) {
        RequestDispatcher rd = getServletContext().getNamedDispatcher(servletName);
        rd.forward(request, response);
        return;
    }

    chain.doFilter(request, response);
}