@Nullable private String initRequestUri() { if (this.forwardedPrefix != null) { return this.forwardedPrefix + this.pathHelper.getPathWithinApplication(this.delegate.get()); } return null; }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; String requestPath = urlPathHelper.getPathWithinApplication(httpRequest); if (matches(requestPath)) { this.delegate.doFilter(request, response, filterChain); } else { filterChain.doFilter(request, response); } }
/** * Return the mapping lookup path for the given request, within the current * servlet mapping if applicable, else within the web application. * <p>Detects include request URL if called within a RequestDispatcher include. * @param request current HTTP request * @return the lookup path * @see #getPathWithinApplication * @see #getPathWithinServletMapping */ public String getLookupPathForRequest(HttpServletRequest request) { // Always use full path within current servlet context? if (this.alwaysUseFullPath) { return getPathWithinApplication(request); } // Else, use path within current servlet mapping if applicable String rest = getPathWithinServletMapping(request); if (!"".equals(rest)) { return rest; } else { return getPathWithinApplication(request); } }
@Nullable private String initRequestUri() { if (this.forwardedPrefix != null) { return this.forwardedPrefix + this.pathHelper.getPathWithinApplication(this.delegate.get()); } return null; }
private String getFilePath(HttpServletRequest request, String name, String profile, String label) { String stem; if(label != null ) { stem = String.format("/%s/%s/%s/", name, profile, label); }else { stem = String.format("/%s/%s/", name, profile); } String path = this.helper.getPathWithinApplication(request); path = path.substring(path.indexOf(stem) + stem.length()); return path; }
/** * Return the mapping lookup path for the given request, within the current * servlet mapping if applicable, else within the web application. * <p>Detects include request URL if called within a RequestDispatcher include. * @param request current HTTP request * @return the lookup path * @see #getPathWithinApplication * @see #getPathWithinServletMapping */ public String getLookupPathForRequest(HttpServletRequest request) { // Always use full path within current servlet context? if (this.alwaysUseFullPath) { return getPathWithinApplication(request); } // Else, use path within current servlet mapping if applicable String rest = getPathWithinServletMapping(request); if (!"".equals(rest)) { return rest; } else { return getPathWithinApplication(request); } }
String pathWithinApp = getPathWithinApplication(request); String servletPath = getServletPath(request); String sanitizedPathWithinApp = getSanitizedPath(pathWithinApp);
@Override public List<MediaType> resolveMediaTypes(NativeWebRequest request) throws HttpMediaTypeNotAcceptableException { String path = this.urlPathHelper.getPathWithinApplication( request.getNativeRequest(HttpServletRequest.class)); if (!StringUtils.hasText(path) || !path.equals("/")) { // Only care about "/" return MEDIA_TYPE_ALL_LIST; } String userAgent = request.getHeader(HttpHeaders.USER_AGENT); if (userAgent != null) { Agent agent = Agent.fromUserAgent(userAgent); if (agent != null) { if (AgentId.CURL.equals(agent.getId()) || AgentId.HTTPIE.equals(agent.getId())) { return Collections.singletonList(MediaType.TEXT_PLAIN); } } } return Collections.singletonList(MediaType.APPLICATION_JSON); }
@Test public void getPathWithinApplicationForRootWithNoLeadingSlash() { request.setContextPath("/petclinic"); request.setRequestURI("/petclinic"); assertEquals("Incorrect root path returned", "/", helper.getPathWithinApplication(request)); }
@Test public void getPathWithinApplicationForSlashContextPath() { request.setContextPath("/"); request.setRequestURI("/welcome.html"); assertEquals("Incorrect path returned", "/welcome.html", helper.getPathWithinApplication(request)); }
@Test public void getPathWithinApplication() { request.setContextPath("/petclinic"); request.setRequestURI("/petclinic/welcome.html"); assertEquals("Incorrect path returned", "/welcome.html", helper.getPathWithinApplication(request)); }
String pathWithinApp = getPathWithinApplication(request); String servletPath = getServletPath(request); String sanitizedPathWithinApp = getSanitizedPath(pathWithinApp);
Route route(HttpServletRequest request) { String requestURI = urlPathHelper.getPathWithinApplication(request); return routeLocator.getMatchingRoute(requestURI); }
@Override public void afterPropertiesSet() { URI baseUri = configuration.getBaseUri(); if (baseUri.isAbsolute()) { HttpServletRequest request = new UriAwareHttpServletRequest(getServletContext(), baseUri); this.prefix = URL_PATH_HELPER.getPathWithinApplication(request); } else { this.prefix = baseUri.toString(); } super.afterPropertiesSet(); }
/** * Return the path within the web application for the given request. * @see UrlPathHelper#getPathWithinApplication(HttpServletRequest) */ public static String getPathWithinApplication(HttpServletRequest request) { return urlPathHelper.getPathWithinApplication(request); }
@Nullable private String initRequestUri() { if (this.forwardedPrefix != null) { return this.forwardedPrefix + this.pathHelper.getPathWithinApplication(this.delegate.get()); } return null; }
private String getRequestPath(HttpServletRequest request) { if (this.urlPathHelper != null) { return this.urlPathHelper.getPathWithinApplication(request); } String url = request.getServletPath(); String pathInfo = request.getPathInfo(); if (pathInfo != null) { url = StringUtils.hasLength(url) ? url + pathInfo : pathInfo; } return url; }
protected String getPathWithoutStripSuffix(HttpServletRequest request) { String URI = this.urlPathHelper.getPathWithinApplication(request); if (URI.endsWith(ConstantsPath.PATH_ROOT)) { URI = org.apache.commons.lang.StringUtils.removeEnd(URI, ConstantsPath.PATH_ROOT); } URI = adjustPath(URI); return URI; }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; String requestPath = urlPathHelper.getPathWithinApplication(httpRequest); if(matches(requestPath)) { this.delegate.doFilter(request, response, filterChain); } else { filterChain.doFilter(request, response); } }
@Override public void afterPropertiesSet() { URI baseUri = configuration.getBaseUri(); if (baseUri.isAbsolute()) { HttpServletRequest request = new UriAwareHttpServletRequest(getServletContext(), baseUri); this.prefix = URL_PATH_HELPER.getPathWithinApplication(request); } else { this.prefix = baseUri.toString(); } super.afterPropertiesSet(); }