/** * Return a global {@link UrlPathHelper} instance for path matching * patterns in {@link HandlerMapping HandlerMappings}. * This instance can be configured using the {@link PathMatchConfigurer} * in {@link #configurePathMatch(PathMatchConfigurer)}. * @since 4.1 */ @Bean public UrlPathHelper mvcUrlPathHelper() { UrlPathHelper pathHelper = getPathMatchConfigurer().getUrlPathHelper(); return (pathHelper != null ? pathHelper : new UrlPathHelper()); }
/** * Private constructor accepting a collection of patterns. */ private PatternsRequestCondition(Collection<String> patterns, @Nullable UrlPathHelper urlPathHelper, @Nullable PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch, @Nullable List<String> fileExtensions) { this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns)); this.pathHelper = (urlPathHelper != null ? urlPathHelper : new UrlPathHelper()); this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher()); this.useSuffixPatternMatch = useSuffixPatternMatch; this.useTrailingSlashMatch = useTrailingSlashMatch; if (fileExtensions != null) { for (String fileExtension : fileExtensions) { if (fileExtension.charAt(0) != '.') { fileExtension = "." + fileExtension; } this.fileExtensions.add(fileExtension); } } }
public ForwardedHeaderFilter() { this.pathHelper = new UrlPathHelper(); this.pathHelper.setUrlDecode(false); this.pathHelper.setRemoveSemicolonContent(false); }
/** * Prepare a builder from the host, port, scheme, context path, and * servlet mapping of the given HttpServletRequest. * <p>If the servlet is mapped by name, e.g. {@code "/main/*"}, the path * will end with "/main". If the servlet is mapped otherwise, e.g. * {@code "/"} or {@code "*.do"}, the result will be the same as * if calling {@link #fromContextPath(HttpServletRequest)}. */ public static ServletUriComponentsBuilder fromServletMapping(HttpServletRequest request) { ServletUriComponentsBuilder builder = fromContextPath(request); if (StringUtils.hasText(new UrlPathHelper().getPathWithinServletMapping(request))) { builder.path(request.getServletPath()); } return builder; }
/** * Return a global {@link UrlPathHelper} instance for path matching * patterns in {@link HandlerMapping HandlerMappings}. * This instance can be configured using the {@link PathMatchConfigurer} * in {@link #configurePathMatch(PathMatchConfigurer)}. * @since 4.1 */ @Bean public UrlPathHelper mvcUrlPathHelper() { UrlPathHelper pathHelper = getPathMatchConfigurer().getUrlPathHelper(); return (pathHelper != null ? pathHelper : new UrlPathHelper()); }
/** * Private constructor accepting a collection of patterns. */ private PatternsRequestCondition(Collection<String> patterns, @Nullable UrlPathHelper urlPathHelper, @Nullable PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch, @Nullable List<String> fileExtensions) { this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns)); this.pathHelper = (urlPathHelper != null ? urlPathHelper : new UrlPathHelper()); this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher()); this.useSuffixPatternMatch = useSuffixPatternMatch; this.useTrailingSlashMatch = useTrailingSlashMatch; if (fileExtensions != null) { for (String fileExtension : fileExtensions) { if (fileExtension.charAt(0) != '.') { fileExtension = "." + fileExtension; } this.fileExtensions.add(fileExtension); } } }
public ForwardedHeaderFilter() { this.pathHelper = new UrlPathHelper(); this.pathHelper.setUrlDecode(false); this.pathHelper.setRemoveSemicolonContent(false); }
/** * Prepare a builder from the host, port, scheme, context path, and * servlet mapping of the given HttpServletRequest. * <p>If the servlet is mapped by name, e.g. {@code "/main/*"}, the path * will end with "/main". If the servlet is mapped otherwise, e.g. * {@code "/"} or {@code "*.do"}, the result will be the same as * if calling {@link #fromContextPath(HttpServletRequest)}. */ public static ServletUriComponentsBuilder fromServletMapping(HttpServletRequest request) { ServletUriComponentsBuilder builder = fromContextPath(request); if (StringUtils.hasText(new UrlPathHelper().getPathWithinServletMapping(request))) { builder.path(request.getServletPath()); } return builder; }
@Override public String getSectionKey(boolean withTypeKey) { HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest(); if (request != null) { String originatingUri = new UrlPathHelper().getOriginatingRequestUri(request); int startIndex = request.getContextPath().length(); String sectionKey = originatingUri.substring(startIndex); int endIndex = sectionKey.indexOf("/", 1); if (endIndex > 0) { // If we want a 'typeKey', grab a new end index if (withTypeKey) { endIndex = sectionKey.indexOf("/", endIndex); } // check again to make sure there is an end index if (endIndex > 0) { sectionKey = sectionKey.substring(0, endIndex); } } return sectionKey; } return null; } }
String originatingUri = new UrlPathHelper().getOriginatingRequestUri(request); int startIndex = request.getContextPath().length();
WebUtils.getResponseEncodedHtmlEscape(this.webApplicationContext.getServletContext()); this.urlPathHelper = new UrlPathHelper();
WebUtils.getResponseEncodedHtmlEscape(this.webApplicationContext.getServletContext()); this.urlPathHelper = new UrlPathHelper();
String originatingUri = new UrlPathHelper().getOriginatingRequestUri(request); int startIndex = request.getContextPath().length();
@Before public void setUp() { GenericWebApplicationContext appContext = new GenericWebApplicationContext(); appContext.refresh(); this.registry = new ResourceHandlerRegistry(appContext, new MockServletContext(), new ContentNegotiationManager(), new UrlPathHelper()); this.registration = this.registry.addResourceHandler("/resources/**"); this.registration.addResourceLocations("classpath:org/springframework/web/servlet/config/annotation/"); this.response = new MockHttpServletResponse(); }
@SuppressWarnings("unchecked") @Test public void handleMatchUriTemplateVariables() { RequestMappingInfo key = RequestMappingInfo.paths("/{path1}/{path2}").build(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/1/2"); String lookupPath = new UrlPathHelper().getLookupPathForRequest(request); this.handlerMapping.handleMatch(key, lookupPath, request); String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE; Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name); assertNotNull(uriVariables); assertEquals("1", uriVariables.get("path1")); assertEquals("2", uriVariables.get("path2")); }
@Test public void handlerMapping() { SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) this.endpointRegistry.getHandlerMapping(); assertEquals(0, hm.getUrlMap().size()); UrlPathHelper pathHelper = new UrlPathHelper(); this.endpointRegistry.setUrlPathHelper(pathHelper); this.endpointRegistry.addEndpoint("/stompOverWebSocket"); this.endpointRegistry.addEndpoint("/stompOverSockJS").withSockJS(); //SPR-12403 assertEquals(1, this.webSocketHandler.getProtocolHandlers().size()); hm = (SimpleUrlHandlerMapping) this.endpointRegistry.getHandlerMapping(); assertEquals(2, hm.getUrlMap().size()); assertNotNull(hm.getUrlMap().get("/stompOverWebSocket")); assertNotNull(hm.getUrlMap().get("/stompOverSockJS/**")); assertSame(pathHelper, hm.getUrlPathHelper()); }
@Test // SPR-10140, SPR-16867 public void handleMatchMatrixVariablesDecoding() { MockHttpServletRequest request; UrlPathHelper urlPathHelper = new UrlPathHelper(); urlPathHelper.setUrlDecode(false); urlPathHelper.setRemoveSemicolonContent(false); this.handlerMapping.setUrlPathHelper(urlPathHelper); request = new MockHttpServletRequest(); handleMatch(request, "/{cars}", "/cars;mvar=a%2Fb"); MultiValueMap<String, String> matrixVariables = getMatrixVariables(request, "cars"); Map<String, String> uriVariables = getUriTemplateVariables(request); assertNotNull(matrixVariables); assertEquals(Collections.singletonList("a/b"), matrixVariables.get("mvar")); assertEquals("cars", uriVariables.get("cars")); }
@SuppressWarnings("unchecked") @Test // SPR-9098 public void handleMatchUriTemplateVariablesDecode() { RequestMappingInfo key = RequestMappingInfo.paths("/{group}/{identifier}").build(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/group/a%2Fb"); UrlPathHelper pathHelper = new UrlPathHelper(); pathHelper.setUrlDecode(false); String lookupPath = pathHelper.getLookupPathForRequest(request); this.handlerMapping.setUrlPathHelper(pathHelper); this.handlerMapping.handleMatch(key, lookupPath, request); String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE; Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(name); assertNotNull(uriVariables); assertEquals("group", uriVariables.get("group")); assertEquals("a/b", uriVariables.get("identifier")); }
@Test public void relativePathEncodedForUrlResource() throws Exception { TestUrlResource location = new TestUrlResource("file:///tmp"); List<TestUrlResource> locations = Collections.singletonList(location); // ISO-8859-1 this.resolver.setUrlPathHelper(new UrlPathHelper()); this.resolver.setLocationCharsets(Collections.singletonMap(location, StandardCharsets.ISO_8859_1)); this.resolver.resolveResource(new MockHttpServletRequest(), "/Ä ;ä.txt", locations, null); assertEquals("%C4%20%3B%E4.txt", location.getSavedRelativePath()); // UTF-8 this.resolver.setLocationCharsets(Collections.singletonMap(location, StandardCharsets.UTF_8)); this.resolver.resolveResource(new MockHttpServletRequest(), "/Ä ;ä.txt", locations, null); assertEquals("%C3%84%20%3B%C3%A4.txt", location.getSavedRelativePath()); // UTF-8 by default this.resolver.setLocationCharsets(Collections.emptyMap()); this.resolver.resolveResource(new MockHttpServletRequest(), "/Ä ;ä.txt", locations, null); assertEquals("%C3%84%20%3B%C3%A4.txt", location.getSavedRelativePath()); }
public FilenameFlowUrlHandler() { urlPathHelper = new UrlPathHelper(); }