Example usage for org.springframework.web.servlet HandlerMapping BEST_MATCHING_PATTERN_ATTRIBUTE

List of usage examples for org.springframework.web.servlet HandlerMapping BEST_MATCHING_PATTERN_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.web.servlet HandlerMapping BEST_MATCHING_PATTERN_ATTRIBUTE.

Prototype

String BEST_MATCHING_PATTERN_ATTRIBUTE

To view the source code for org.springframework.web.servlet HandlerMapping BEST_MATCHING_PATTERN_ATTRIBUTE.

Click Source Link

Document

Name of the HttpServletRequest attribute that contains the best matching pattern within the handler mapping.

Usage

From source file:com.netflix.genie.web.controllers.UIControllerUnitTests.java

/**
 * Make sure the getFile method returns the right forward command.
 * @throws Exception if an error occurs//ww w  .j a  v a 2  s  .  c om
 */
@Test
public void canGetFile() throws Exception {
    final String id = UUID.randomUUID().toString();
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);

    Mockito.when(request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE))
            .thenReturn("/file/" + id + "/output/genie/log.out");
    Mockito.when(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE))
            .thenReturn("/file/{id}/**");

    final String encodedId = URLEncoder.encode(id, "UTF-8");
    final String expectedPath = "/api/v3/jobs/" + encodedId + "/output/genie/log.out";

    Assert.assertThat(this.controller.getFile(id, request), Matchers.is("forward:" + expectedPath));
}

From source file:com.bennavetta.appsite.webapi.ContentController.java

/**
 * Given a request that was matched against a @RequestMapping method, extract a trailing path from it.
 * For example, given a mapping of '/foo/**' and a request of '/foo/bar/baz', this would return 'bar/baz'.
 * @param request the matched request/* ww w . j av  a2  s. c o  m*/
 * @return the final path component
 * @see http://stackoverflow.com/questions/3686808/spring-3-requestmapping-get-path-value
 */
public static String extractPathFromPattern(HttpServletRequest request) {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);

    AntPathMatcher apm = new AntPathMatcher();
    String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path);

    return finalPath;
}

From source file:org.wallride.web.controller.guest.article.ArticleIndexController.java

private String extractPathFromPattern(final HttpServletRequest request) {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);

    AntPathMatcher apm = new AntPathMatcher();
    String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path);

    return finalPath;
}

From source file:bjerne.gallery.controller.GalleryController.java

/**
 * Due to some Spring MVC oddities with pattern matching, the following
 * method was put in place to correctly extract the path from the URL path
 * (remember, the URL path contains more information than just the image
 * path)./*from w ww  . j a v a2s  . c  o m*/
 * 
 * @param request
 *            Request
 * @return The public image path.
 */
private String extractPathFromPattern(final HttpServletRequest request) {
    String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    AntPathMatcher apm = new AntPathMatcher();
    String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path);
    return finalPath;
}

From source file:org.springframework.boot.actuate.autoconfigure.MetricsFilter.java

private String getFinalStatus(HttpServletRequest request, String path, int status) {
    Object bestMatchingPattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    if (bestMatchingPattern != null) {
        return fixSpecialCharacters(bestMatchingPattern.toString());
    }/*from   www .j  av  a 2  s. c om*/
    Series series = getSeries(status);
    if (Series.CLIENT_ERROR.equals(series) || Series.REDIRECTION.equals(series)) {
        return UNKNOWN_PATH_SUFFIX;
    }
    return path;
}

From source file:org.springframework.boot.actuate.metrics.web.servlet.MetricsFilter.java

private String determineMetricNameSuffix(HttpServletRequest request, String path, int status) {
    Object bestMatchingPattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
    if (bestMatchingPattern != null) {
        return fixSpecialCharacters(bestMatchingPattern.toString());
    }//  w  w  w. java2 s . co m
    Series series = getSeries(status);
    if (Series.CLIENT_ERROR.equals(series) || Series.SERVER_ERROR.equals(series)
            || Series.REDIRECTION.equals(series)) {
        return UNKNOWN_PATH_SUFFIX;
    }
    return path;
}