Class UrlHandlerFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.springframework.web.filter.UrlHandlerFilter
- All Implemented Interfaces:
jakarta.servlet.Filter, Aware, BeanNameAware, DisposableBean, InitializingBean, EnvironmentAware, EnvironmentCapable, ServletContextAware
Filter that modifies the URL, and then either
redirects or wraps the request to effect the change.
To create an instance, you can use the following:
UrlHandlerFilter filter = UrlHandlerFilter
.trailingSlashHandler("/path1/**").redirect(HttpStatus.PERMANENT_REDIRECT)
.trailingSlashHandler("/path2/**").wrapRequest()
.build();
This Filter should be ordered after ForwardedHeaderFilter,
before ServletRequestPathFilter, and before security filters.
- Since:
- 6.2
- Author:
- Rossen Stoyanchev
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class OncePerRequestFilter
ALREADY_FILTERED_SUFFIX -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) Same contract as fordoFilter, but guaranteed to be just invoked once per request within a single request thread.trailingSlashHandler(String... pathPatterns) Create a builder by adding a handler for URL's with a trailing slash.Methods inherited from class OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatchMethods inherited from class GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Method Details
-
doFilterInternal
protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) throws jakarta.servlet.ServletException, IOException Description copied from class:OncePerRequestFilterSame contract as fordoFilter, but guaranteed to be just invoked once per request within a single request thread. SeeOncePerRequestFilter.shouldNotFilterAsyncDispatch()for details.Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.
- Specified by:
doFilterInternalin classOncePerRequestFilter- Throws:
jakarta.servlet.ServletExceptionIOException
-
trailingSlashHandler
public static UrlHandlerFilter.Builder.TrailingSlashSpec trailingSlashHandler(String... pathPatterns) Create a builder by adding a handler for URL's with a trailing slash.- Parameters:
pathPatterns- path patterns to map the handler to, for example,"/path/*","/path/**","/path/foo/".- Returns:
- a spec to configure the trailing slash handler with
- See Also:
-