Java Code Examples for org.springframework.web.util.UrlPathHelper#getLookupPathForRequest()
The following examples show how to use
org.springframework.web.util.UrlPathHelper#getLookupPathForRequest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceUrlEncodingFilter.java From spring-analysis-note with MIT License | 6 votes |
private void initLookupPath(ResourceUrlProvider urlProvider) { this.resourceUrlProvider = urlProvider; if (this.indexLookupPath == null) { UrlPathHelper pathHelper = this.resourceUrlProvider.getUrlPathHelper(); String requestUri = pathHelper.getRequestUri(this); String lookupPath = pathHelper.getLookupPathForRequest(this); this.indexLookupPath = requestUri.lastIndexOf(lookupPath); Assert.isTrue(this.indexLookupPath != -1, () -> "Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + ". " + "Does the path have invalid encoded characters " + "for characterEncoding=" + getRequest().getCharacterEncoding() + "?"); this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath); if ("/".equals(lookupPath) && !"/".equals(requestUri)) { String contextPath = pathHelper.getContextPath(this); if (requestUri.equals(contextPath)) { this.indexLookupPath = requestUri.length(); this.prefixLookupPath = requestUri; } } } }
Example 2
Source File: RequestMappingInfoHandlerMappingTests.java From spring-analysis-note with MIT License | 6 votes |
@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")); }
Example 3
Source File: ResourceUrlEncodingFilter.java From java-technology-stack with MIT License | 6 votes |
private void initLookupPath(ResourceUrlProvider urlProvider) { this.resourceUrlProvider = urlProvider; if (this.indexLookupPath == null) { UrlPathHelper pathHelper = this.resourceUrlProvider.getUrlPathHelper(); String requestUri = pathHelper.getRequestUri(this); String lookupPath = pathHelper.getLookupPathForRequest(this); this.indexLookupPath = requestUri.lastIndexOf(lookupPath); this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath); if ("/".equals(lookupPath) && !"/".equals(requestUri)) { String contextPath = pathHelper.getContextPath(this); if (requestUri.equals(contextPath)) { this.indexLookupPath = requestUri.length(); this.prefixLookupPath = requestUri; } } } }
Example 4
Source File: RequestMappingInfoHandlerMappingTests.java From java-technology-stack with MIT License | 6 votes |
@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")); }
Example 5
Source File: ResourceUrlEncodingFilter.java From lams with GNU General Public License v2.0 | 6 votes |
private void initLookupPath(ResourceUrlProvider urlProvider) { if (this.indexLookupPath == null) { UrlPathHelper pathHelper = urlProvider.getUrlPathHelper(); String requestUri = pathHelper.getRequestUri(this.request); String lookupPath = pathHelper.getLookupPathForRequest(this.request); this.indexLookupPath = requestUri.lastIndexOf(lookupPath); this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath); if ("/".equals(lookupPath) && !"/".equals(requestUri)) { String contextPath = pathHelper.getContextPath(this.request); if (requestUri.equals(contextPath)) { this.indexLookupPath = requestUri.length(); this.prefixLookupPath = requestUri; } } } }
Example 6
Source File: RequestMappingInfoHandlerMappingTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void uriTemplateVariablesDecode() { PatternsRequestCondition patterns = new PatternsRequestCondition("/{group}/{identifier}"); RequestMappingInfo key = new RequestMappingInfo(patterns, null, null, null, null, null, null); 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); @SuppressWarnings("unchecked") Map<String, String> uriVariables = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); assertNotNull(uriVariables); assertEquals("group", uriVariables.get("group")); assertEquals("a/b", uriVariables.get("identifier")); }
Example 7
Source File: BlogLanguageRewriteMatch.java From wallride with Apache License 2.0 | 5 votes |
@Override public boolean execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { UrlPathHelper urlPathHelper = new UrlPathHelper(); String originalPath = urlPathHelper.getLookupPathForRequest(request); String rewritePath = originalPath.replaceAll("^/" + blogLanguage.getLanguage() + "/", "/"); matchingUrl = rewritePath; logger.debug(originalPath + " => " + rewritePath); request.setAttribute(BlogLanguageMethodArgumentResolver.BLOG_LANGUAGE_ATTRIBUTE, blogLanguage); RequestDispatcher rd = request.getRequestDispatcher(urlPathHelper.getServletPath(request) + rewritePath); rd.forward(request, response); return true; }
Example 8
Source File: BlogLanguageRewriteRule.java From wallride with Apache License 2.0 | 5 votes |
@Override public RewriteMatch matches(HttpServletRequest request, HttpServletResponse response) { UrlPathHelper urlPathHelper = new UrlPathHelper(); String servletPath = urlPathHelper.getOriginatingServletPath(request); if (ObjectUtils.nullSafeEquals(servletPath, WallRideServletConfiguration.ADMIN_SERVLET_PATH)) { return null; } String lookupPath = urlPathHelper.getLookupPathForRequest(request); Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); if (blog == null) { return null; } BlogLanguage matchedBlogLanguage = null; for (BlogLanguage blogLanguage : blog.getLanguages()) { if (lookupPath.startsWith("/" + blogLanguage.getLanguage() + "/")) { matchedBlogLanguage = blogLanguage; break; } } if (matchedBlogLanguage == null) { matchedBlogLanguage = blog.getLanguage(blog.getDefaultLanguage()); } return new BlogLanguageRewriteMatch(matchedBlogLanguage); }
Example 9
Source File: ResourceUrlProvider.java From java-technology-stack with MIT License | 4 votes |
private int getLookupPathIndex(HttpServletRequest request) { UrlPathHelper pathHelper = getUrlPathHelper(); String requestUri = pathHelper.getRequestUri(request); String lookupPath = pathHelper.getLookupPathForRequest(request); return requestUri.indexOf(lookupPath); }
Example 10
Source File: ResourceUrlProvider.java From lams with GNU General Public License v2.0 | 4 votes |
private int getLookupPathIndex(HttpServletRequest request) { UrlPathHelper pathHelper = getUrlPathHelper(); String requestUri = pathHelper.getRequestUri(request); String lookupPath = pathHelper.getLookupPathForRequest(request); return requestUri.indexOf(lookupPath); }