@Override @Nullable public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { String lookupPath = this.urlPathHelper.getLookupPathForRequest(request); for (Map.Entry<String, CorsConfiguration> entry : this.corsConfigurations.entrySet()) { if (this.pathMatcher.match(entry.getKey(), lookupPath)) { return entry.getValue(); } } return null; }
@Override @Nullable protected String getMediaTypeKey(NativeWebRequest webRequest) { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); if (request == null) { return null; } String path = this.urlPathHelper.getLookupPathForRequest(request); String extension = UriUtils.extractFileExtension(path); return (StringUtils.hasText(extension) ? extension.toLowerCase(Locale.ENGLISH) : null); }
@Override protected String getMatchingMapping(String pattern, HttpServletRequest request) { String lookupPath = this.pathHelper.getLookupPathForRequest(request); return this.pathMatcher.match(pattern, lookupPath) ? pattern : null; }
@Override protected Comparator<String> getMappingComparator(HttpServletRequest request) { String lookupPath = this.pathHelper.getLookupPathForRequest(request); return this.pathMatcher.getPatternComparator(lookupPath); }
@Override public RequestMatchResult match(HttpServletRequest request, String pattern) { RequestMappingInfo info = RequestMappingInfo.paths(pattern).options(this.config).build(); RequestMappingInfo matchingInfo = info.getMatchingCondition(request); if (matchingInfo == null) { return null; } Set<String> patterns = matchingInfo.getPatternsCondition().getPatterns(); String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); return new RequestMatchResult(patterns.iterator().next(), lookupPath, getPathMatcher()); }
@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 getLookupPathWithSemicolonContent() { helper.setRemoveSemicolonContent(false); request.setContextPath("/petclinic"); request.setServletPath("/main"); request.setRequestURI("/petclinic;a=b/main;b=c/welcome.html;c=d"); assertEquals("/welcome.html;c=d", helper.getLookupPathForRequest(request)); }
@Test public void tomcatCasualServletRoot() throws Exception { request.setContextPath("/test"); request.setPathInfo("/"); request.setServletPath("/foo"); request.setRequestURI("/test/foo/"); assertEquals("/", helper.getLookupPathForRequest(request)); }
@Test public void tomcatDefaultServletRoot() throws Exception { request.setContextPath("/test"); request.setPathInfo(null); request.setServletPath("/"); request.setRequestURI("/test/"); assertEquals("/", helper.getLookupPathForRequest(request)); }
@Test public void tomcatDefaultServletFolder() throws Exception { request.setContextPath("/test"); request.setPathInfo(null); request.setServletPath("/foo/"); request.setRequestURI("/test/foo/"); assertEquals("/foo/", helper.getLookupPathForRequest(request)); }
@Test public void tomcatCasualServletFile() throws Exception { request.setContextPath("/test"); request.setPathInfo("/foo"); request.setServletPath("/foo"); request.setRequestURI("/test/foo/foo"); assertEquals("/foo", helper.getLookupPathForRequest(request)); }
@Test public void alwaysUseFullPath() { helper.setAlwaysUseFullPath(true); request.setContextPath("/petclinic"); request.setServletPath("/main"); request.setRequestURI("/petclinic/main/welcome.html"); assertEquals("Incorrect path returned", "/main/welcome.html", helper.getLookupPathForRequest(request)); }
@Test public void tomcatCasualServletFolder() throws Exception { request.setContextPath("/test"); request.setPathInfo("/foo/"); request.setServletPath("/foo"); request.setRequestURI("/test/foo/foo/"); assertEquals("/foo/", helper.getLookupPathForRequest(request)); }
@Test public void tomcatDefaultServletFile() throws Exception { request.setContextPath("/test"); request.setPathInfo(null); request.setServletPath("/foo"); request.setRequestURI("/test/foo"); assertEquals("/foo", helper.getLookupPathForRequest(request)); }
@Test public void wasDefaultServletFile() throws Exception { request.setContextPath("/test"); request.setPathInfo("/foo"); request.setServletPath(""); request.setRequestURI("/test/foo"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo"); assertEquals("/foo", helper.getLookupPathForRequest(request)); }
@Test @Ignore public void tomcatCasualServletRootWithMissingSlash() throws Exception { request.setContextPath("/test"); request.setPathInfo(null); request.setServletPath("/foo"); request.setRequestURI("/test/foo"); assertEquals("/", helper.getLookupPathForRequest(request)); }
@Test public void wasDefaultServletRoot() throws Exception { request.setContextPath("/test"); request.setPathInfo("/"); request.setServletPath(""); request.setRequestURI("/test/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/"); assertEquals("/", helper.getLookupPathForRequest(request)); }
@Test public void wasCasualServletFolder() throws Exception { request.setContextPath("/test"); request.setPathInfo("/foo/"); request.setServletPath("/foo"); request.setRequestURI("/test/foo/foo/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo/"); assertEquals("/foo/", helper.getLookupPathForRequest(request)); }
@Test public void wasCasualServletRoot() throws Exception { request.setContextPath("/test"); request.setPathInfo(null); request.setServletPath("/foo/"); request.setRequestURI("/test/foo/"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/"); assertEquals("/", helper.getLookupPathForRequest(request)); }
@Test public void wasCasualServletFile() throws Exception { request.setContextPath("/test"); request.setPathInfo("/foo"); request.setServletPath("/foo"); request.setRequestURI("/test/foo/foo"); request.setAttribute(WEBSPHERE_URI_ATTRIBUTE, "/test/foo/foo"); assertEquals("/foo", helper.getLookupPathForRequest(request)); }