|
30 | 30 |
|
31 | 31 | import org.springframework.beans.factory.ListableBeanFactory;
|
32 | 32 | import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
| 33 | +import org.springframework.boot.web.servlet.AbstractFilterRegistrationBean; |
33 | 34 | import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean;
|
34 | 35 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
35 | 36 | import org.springframework.boot.web.servlet.RegistrationBean;
|
36 |
| -import org.springframework.boot.web.servlet.ServletContextInitializer; |
37 | 37 | import org.springframework.boot.web.servlet.ServletContextInitializerBeans;
|
38 | 38 | import org.springframework.context.ApplicationContext;
|
39 | 39 | import org.springframework.context.ConfigurableApplicationContext;
|
@@ -108,25 +108,11 @@ private LinesWriter getLinesWriter() {
|
108 | 108 | }
|
109 | 109 |
|
110 | 110 | private void addFilters(ConfigurableMockMvcBuilder<?> builder) {
|
111 |
| - FilterRegistrationBeans initializers = new FilterRegistrationBeans(this.context); |
112 |
| - for (ServletContextInitializer initializer : initializers) { |
113 |
| - if (initializer instanceof FilterRegistrationBean) { |
114 |
| - addFilter(builder, (FilterRegistrationBean<?>) initializer); |
115 |
| - } |
116 |
| - if (initializer instanceof DelegatingFilterProxyRegistrationBean) { |
117 |
| - addFilter(builder, (DelegatingFilterProxyRegistrationBean) initializer); |
118 |
| - } |
119 |
| - } |
120 |
| - } |
121 |
| - |
122 |
| - private void addFilter(ConfigurableMockMvcBuilder<?> builder, |
123 |
| - FilterRegistrationBean<?> registration) { |
124 |
| - addFilter(builder, registration.getFilter(), registration.getUrlPatterns()); |
125 |
| - } |
126 |
| - |
127 |
| - private void addFilter(ConfigurableMockMvcBuilder<?> builder, |
128 |
| - DelegatingFilterProxyRegistrationBean registration) { |
129 |
| - addFilter(builder, registration.getFilter(), registration.getUrlPatterns()); |
| 111 | + FilterRegistrationBeans registrations = new FilterRegistrationBeans(this.context); |
| 112 | + registrations.stream().map(AbstractFilterRegistrationBean.class::cast) |
| 113 | + .filter(AbstractFilterRegistrationBean::isEnabled) |
| 114 | + .forEach((registration) -> addFilter(builder, registration.getFilter(), |
| 115 | + registration.getUrlPatterns())); |
130 | 116 | }
|
131 | 117 |
|
132 | 118 | private void addFilter(ConfigurableMockMvcBuilder<?> builder, Filter filter,
|
|
0 commit comments