mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Add FilterRegistrationBean.setDispatcherTypes(...)
Add setDispatcherTypes method to FilterRegistrationBean. Fixes gh-871
This commit is contained in:
parent
f761daf253
commit
e018f2af25
@ -210,6 +210,23 @@ public class FilterRegistrationBean extends RegistrationBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to {@link #setDispatcherTypes(EnumSet) set dispatcher types}
|
||||||
|
* using the specified elements.
|
||||||
|
*/
|
||||||
|
public void setDispatcherTypes(DispatcherType first, DispatcherType... rest) {
|
||||||
|
this.dispatcherTypes = EnumSet.of(first, rest);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the dispatcher types that should be used with the registration. If not
|
||||||
|
* specified the types will be deduced based on the value of
|
||||||
|
* {@link #isAsyncSupported()}.
|
||||||
|
*/
|
||||||
|
public void setDispatcherTypes(EnumSet<DispatcherType> dispatcherTypes) {
|
||||||
|
this.dispatcherTypes = dispatcherTypes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set if the filter mappings should be matched after any declared filter mappings of
|
* Set if the filter mappings should be matched after any declared filter mappings of
|
||||||
* the ServletContext. Defaults to {@code false} indicating the filters are supposed
|
* the ServletContext. Defaults to {@code false} indicating the filters are supposed
|
||||||
|
@ -18,10 +18,12 @@ package org.springframework.boot.context.embedded;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.servlet.DispatcherType;
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
import javax.servlet.FilterRegistration;
|
import javax.servlet.FilterRegistration;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
@ -222,6 +224,25 @@ public class FilterRegistrationBeanTests {
|
|||||||
bean.addServletNames((String[]) null);
|
bean.addServletNames((String[]) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withSpecificDispatcherTypes() throws Exception {
|
||||||
|
FilterRegistrationBean bean = new FilterRegistrationBean(this.filter);
|
||||||
|
bean.setDispatcherTypes(DispatcherType.INCLUDE, DispatcherType.FORWARD);
|
||||||
|
bean.onStartup(this.servletContext);
|
||||||
|
verify(this.registration).addMappingForUrlPatterns(
|
||||||
|
EnumSet.of(DispatcherType.INCLUDE, DispatcherType.FORWARD), false, "/*");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withSpecificDispatcherTypesEnumSet() throws Exception {
|
||||||
|
FilterRegistrationBean bean = new FilterRegistrationBean(this.filter);
|
||||||
|
EnumSet<DispatcherType> types = EnumSet.of(DispatcherType.INCLUDE,
|
||||||
|
DispatcherType.FORWARD);
|
||||||
|
bean.setDispatcherTypes(types);
|
||||||
|
bean.onStartup(this.servletContext);
|
||||||
|
verify(this.registration).addMappingForUrlPatterns(types, false, "/*");
|
||||||
|
}
|
||||||
|
|
||||||
private ServletRegistrationBean mockServletRegistation(String name) {
|
private ServletRegistrationBean mockServletRegistation(String name) {
|
||||||
ServletRegistrationBean bean = new ServletRegistrationBean();
|
ServletRegistrationBean bean = new ServletRegistrationBean();
|
||||||
bean.setName(name);
|
bean.setName(name);
|
||||||
|
Loading…
Reference in New Issue
Block a user