Make ServletRegistrationBean and FilterRegistration bean generic
Closes gh-7666
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -67,7 +67,8 @@ public class SkipSslVerificationHttpRequestFactoryTests {
|
||||
0);
|
||||
factory.setSsl(getSsl("password", "classpath:test.jks"));
|
||||
EmbeddedWebServer container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(), "/hello"));
|
||||
new ServletRegistrationBean<ExampleServlet>(new ExampleServlet(),
|
||||
"/hello"));
|
||||
container.start();
|
||||
return "https://localhost:" + container.getPort() + "/hello";
|
||||
}
|
||||
|
||||
@@ -61,10 +61,10 @@ public class H2ConsoleAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean h2Console() {
|
||||
public ServletRegistrationBean<WebServlet> h2Console() {
|
||||
String path = this.properties.getPath();
|
||||
String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
ServletRegistrationBean<WebServlet> registration = new ServletRegistrationBean<WebServlet>(
|
||||
new WebServlet(), urlMapping);
|
||||
H2ConsoleProperties.Settings settings = this.properties.getSettings();
|
||||
if (settings.isTrace()) {
|
||||
|
||||
@@ -134,8 +134,8 @@ public class JerseyAutoConfiguration implements ServletContextAware {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public FilterRegistrationBean requestContextFilter() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
public FilterRegistrationBean<RequestContextFilter> requestContextFilter() {
|
||||
FilterRegistrationBean<RequestContextFilter> registration = new FilterRegistrationBean<RequestContextFilter>();
|
||||
registration.setFilter(new RequestContextFilter());
|
||||
registration.setOrder(this.jersey.getFilter().getOrder() - 1);
|
||||
registration.setName("requestContextFilter");
|
||||
@@ -145,8 +145,8 @@ public class JerseyAutoConfiguration implements ServletContextAware {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "jerseyFilterRegistration")
|
||||
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "filter")
|
||||
public FilterRegistrationBean jerseyFilterRegistration() {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
public FilterRegistrationBean<ServletContainer> jerseyFilterRegistration() {
|
||||
FilterRegistrationBean<ServletContainer> registration = new FilterRegistrationBean<ServletContainer>();
|
||||
registration.setFilter(new ServletContainer(this.config));
|
||||
registration.setUrlPatterns(Arrays.asList(this.path));
|
||||
registration.setOrder(this.jersey.getFilter().getOrder());
|
||||
@@ -168,8 +168,8 @@ public class JerseyAutoConfiguration implements ServletContextAware {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "jerseyServletRegistration")
|
||||
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "servlet", matchIfMissing = true)
|
||||
public ServletRegistrationBean jerseyServletRegistration() {
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
public ServletRegistrationBean<ServletContainer> jerseyServletRegistration() {
|
||||
ServletRegistrationBean<ServletContainer> registration = new ServletRegistrationBean<ServletContainer>(
|
||||
new ServletContainer(this.config), this.path);
|
||||
addInitParameters(registration);
|
||||
registration.setName(getServletRegistrationName());
|
||||
|
||||
@@ -95,9 +95,9 @@ public class OAuth2RestOperationsConfiguration {
|
||||
protected static class SessionScopedConfiguration {
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean oauth2ClientFilterRegistration(
|
||||
public FilterRegistrationBean<OAuth2ClientContextFilter> oauth2ClientFilterRegistration(
|
||||
OAuth2ClientContextFilter filter, SecurityProperties security) {
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
FilterRegistrationBean<OAuth2ClientContextFilter> registration = new FilterRegistrationBean<OAuth2ClientContextFilter>();
|
||||
registration.setFilter(filter);
|
||||
registration.setOrder(security.getFilterOrder() - 10);
|
||||
return registration;
|
||||
|
||||
@@ -136,10 +136,11 @@ public class DispatcherServletAutoConfiguration {
|
||||
|
||||
@Bean(name = DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)
|
||||
@ConditionalOnBean(value = DispatcherServlet.class, name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)
|
||||
public ServletRegistrationBean dispatcherServletRegistration(
|
||||
public ServletRegistrationBean<DispatcherServlet> dispatcherServletRegistration(
|
||||
DispatcherServlet dispatcherServlet) {
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
dispatcherServlet, this.serverProperties.getServlet().getServletMapping());
|
||||
ServletRegistrationBean<DispatcherServlet> registration = new ServletRegistrationBean<DispatcherServlet>(
|
||||
dispatcherServlet,
|
||||
this.serverProperties.getServlet().getServletMapping());
|
||||
registration.setName(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME);
|
||||
registration.setLoadOnStartup(
|
||||
this.webMvcProperties.getServlet().getLoadOnStartup());
|
||||
|
||||
@@ -56,14 +56,14 @@ public class WebServicesAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean messageDispatcherServlet(
|
||||
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(
|
||||
ApplicationContext applicationContext) {
|
||||
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
|
||||
servlet.setApplicationContext(applicationContext);
|
||||
String path = this.properties.getPath();
|
||||
String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(servlet,
|
||||
urlMapping);
|
||||
ServletRegistrationBean<MessageDispatcherServlet> registration = new ServletRegistrationBean<MessageDispatcherServlet>(
|
||||
servlet, urlMapping);
|
||||
WebServicesProperties.Servlet servletProperties = this.properties.getServlet();
|
||||
registration.setLoadOnStartup(servletProperties.getLoadOnStartup());
|
||||
for (Map.Entry<String, String> entry : servletProperties.getInit().entrySet()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,7 +70,7 @@ public class H2ConsoleAutoConfigurationTests {
|
||||
"spring.h2.console.enabled:true");
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
||||
ServletRegistrationBean registrationBean = this.context
|
||||
ServletRegistrationBean<?> registrationBean = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(registrationBean.getUrlMappings()).contains("/h2-console/*");
|
||||
assertThat(registrationBean.getInitParameters()).doesNotContainKey("trace");
|
||||
@@ -95,8 +95,9 @@ public class H2ConsoleAutoConfigurationTests {
|
||||
"spring.h2.console.enabled:true", "spring.h2.console.path:/custom/");
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
||||
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
|
||||
.contains("/custom/*");
|
||||
ServletRegistrationBean<?> servletRegistrationBean = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(servletRegistrationBean.getUrlMappings()).contains("/custom/*");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,8 +107,9 @@ public class H2ConsoleAutoConfigurationTests {
|
||||
"spring.h2.console.enabled:true", "spring.h2.console.path:/custom");
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
||||
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
|
||||
.contains("/custom/*");
|
||||
ServletRegistrationBean<?> servletRegistrationBean = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(servletRegistrationBean.getUrlMappings()).contains("/custom/*");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +120,7 @@ public class H2ConsoleAutoConfigurationTests {
|
||||
"spring.h2.console.settings.webAllowOthers=true");
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
||||
ServletRegistrationBean registrationBean = this.context
|
||||
ServletRegistrationBean<?> registrationBean = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(registrationBean.getUrlMappings()).contains("/h2-console/*");
|
||||
assertThat(registrationBean.getInitParameters()).containsEntry("trace", "");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,7 +63,7 @@ public class DispatcherServletAutoConfigurationTests {
|
||||
this.context.setServletContext(new MockServletContext());
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(DispatcherServlet.class)).isNotNull();
|
||||
ServletRegistrationBean registration = this.context
|
||||
ServletRegistrationBean<?> registration = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(registration.getUrlMappings().toString()).isEqualTo("[/]");
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class DispatcherServletAutoConfigurationTests {
|
||||
DispatcherServletAutoConfiguration.class);
|
||||
this.context.setServletContext(new MockServletContext());
|
||||
this.context.refresh();
|
||||
ServletRegistrationBean registration = this.context
|
||||
ServletRegistrationBean<?> registration = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(registration.getUrlMappings().toString()).isEqualTo("[/]");
|
||||
assertThat(registration.getServletName()).isEqualTo("dispatcherServlet");
|
||||
@@ -105,7 +105,7 @@ public class DispatcherServletAutoConfigurationTests {
|
||||
DispatcherServletAutoConfiguration.class);
|
||||
this.context.setServletContext(new MockServletContext());
|
||||
this.context.refresh();
|
||||
ServletRegistrationBean registration = this.context
|
||||
ServletRegistrationBean<?> registration = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(registration.getUrlMappings().toString()).isEqualTo("[/foo]");
|
||||
assertThat(registration.getServletName()).isEqualTo("customDispatcher");
|
||||
@@ -121,7 +121,7 @@ public class DispatcherServletAutoConfigurationTests {
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "server.servlet_path:/spring");
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBean(DispatcherServlet.class)).isNotNull();
|
||||
ServletRegistrationBean registration = this.context
|
||||
ServletRegistrationBean<?> registration = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(registration.getUrlMappings().toString()).isEqualTo("[/spring/*]");
|
||||
assertThat(registration.getMultipartConfig()).isNull();
|
||||
@@ -134,7 +134,7 @@ public class DispatcherServletAutoConfigurationTests {
|
||||
this.context.register(MultipartConfiguration.class,
|
||||
DispatcherServletAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
ServletRegistrationBean registration = this.context
|
||||
ServletRegistrationBean<?> registration = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(registration.getMultipartConfig()).isNotNull();
|
||||
}
|
||||
@@ -217,9 +217,9 @@ public class DispatcherServletAutoConfigurationTests {
|
||||
protected static class CustomAutowiredRegistration {
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean dispatcherServletRegistration(
|
||||
public ServletRegistrationBean<?> dispatcherServletRegistration(
|
||||
DispatcherServlet dispatcherServlet) {
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
ServletRegistrationBean<DispatcherServlet> registration = new ServletRegistrationBean<DispatcherServlet>(
|
||||
dispatcherServlet, "/foo");
|
||||
registration.setName("customDispatcher");
|
||||
return registration;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -218,8 +218,9 @@ public class EmbeddedServletContainerAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Bean(name = DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME)
|
||||
public ServletRegistrationBean dispatcherRegistration() {
|
||||
return new ServletRegistrationBean(dispatcherServlet(), "/app/*");
|
||||
public ServletRegistrationBean<DispatcherServlet> dispatcherRegistration() {
|
||||
return new ServletRegistrationBean<DispatcherServlet>(dispatcherServlet(),
|
||||
"/app/*");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,23 +66,25 @@ public class WebServicesAutoConfigurationTests {
|
||||
@Test
|
||||
public void customPathWithTrailingSlash() {
|
||||
load(WebServicesAutoConfiguration.class, "spring.webservices.path=/valid/");
|
||||
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
|
||||
.contains("/valid/*");
|
||||
ServletRegistrationBean<?> servletRegistrationBean = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(servletRegistrationBean.getUrlMappings()).contains("/valid/*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customPath() {
|
||||
load(WebServicesAutoConfiguration.class, "spring.webservices.path=/valid");
|
||||
assertThat(this.context.getBeansOfType(ServletRegistrationBean.class)).hasSize(1);
|
||||
assertThat(this.context.getBean(ServletRegistrationBean.class).getUrlMappings())
|
||||
.contains("/valid/*");
|
||||
ServletRegistrationBean<?> servletRegistrationBean = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(servletRegistrationBean.getUrlMappings()).contains("/valid/*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customLoadOnStartup() {
|
||||
load(WebServicesAutoConfiguration.class,
|
||||
"spring.webservices.servlet.load-on-startup=1");
|
||||
ServletRegistrationBean registrationBean = this.context
|
||||
ServletRegistrationBean<?> registrationBean = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(ReflectionTestUtils.getField(registrationBean, "loadOnStartup"))
|
||||
.isEqualTo(1);
|
||||
@@ -93,7 +95,7 @@ public class WebServicesAutoConfigurationTests {
|
||||
load(WebServicesAutoConfiguration.class,
|
||||
"spring.webservices.servlet.init.key1=value1",
|
||||
"spring.webservices.servlet.init.key2=value2");
|
||||
ServletRegistrationBean registrationBean = this.context
|
||||
ServletRegistrationBean<?> registrationBean = this.context
|
||||
.getBean(ServletRegistrationBean.class);
|
||||
assertThat(registrationBean.getInitParameters()).containsEntry("key1", "value1");
|
||||
assertThat(registrationBean.getInitParameters()).containsEntry("key2", "value2");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,10 +45,10 @@ public class SampleAtmosphereApplication {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean atmosphereServlet() {
|
||||
public ServletRegistrationBean<AtmosphereServlet> atmosphereServlet() {
|
||||
// Dispatcher servlet is mapped to '/home' to allow the AtmosphereServlet
|
||||
// to be mapped to '/chat'
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
ServletRegistrationBean<AtmosphereServlet> registration = new ServletRegistrationBean<AtmosphereServlet>(
|
||||
new AtmosphereServlet(), "/chat/*");
|
||||
registration.addInitParameter("org.atmosphere.cpr.packages", "sample");
|
||||
registration.addInitParameter("org.atmosphere.interceptor.HeartbeatInterceptor"
|
||||
|
||||
@@ -46,8 +46,8 @@ public class SampleJersey1Application {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean jersey() {
|
||||
FilterRegistrationBean bean = new FilterRegistrationBean();
|
||||
public FilterRegistrationBean<ServletContainer> jersey() {
|
||||
FilterRegistrationBean<ServletContainer> bean = new FilterRegistrationBean<ServletContainer>();
|
||||
bean.setFilter(new ServletContainer());
|
||||
bean.addInitParameter("com.sun.jersey.config.property.packages",
|
||||
"com.sun.jersey;sample.jersey1");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -109,7 +109,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
|
||||
this.context);
|
||||
for (ServletContextInitializer initializer : Initializers) {
|
||||
if (initializer instanceof FilterRegistrationBean) {
|
||||
addFilter(builder, (FilterRegistrationBean) initializer);
|
||||
addFilter(builder, (FilterRegistrationBean<?>) initializer);
|
||||
}
|
||||
if (initializer instanceof DelegatingFilterProxyRegistrationBean) {
|
||||
addFilter(builder, (DelegatingFilterProxyRegistrationBean) initializer);
|
||||
@@ -118,7 +118,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
|
||||
}
|
||||
|
||||
private void addFilter(ConfigurableMockMvcBuilder<?> builder,
|
||||
FilterRegistrationBean registration) {
|
||||
FilterRegistrationBean<?> registration) {
|
||||
addFilter(builder, registration.getFilter(), registration.getUrlPatterns());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,9 +38,10 @@ import org.springframework.util.Assert;
|
||||
* Abstract base {@link ServletContextInitializer} to register {@link Filter}s in a
|
||||
* Servlet 3.0+ container.
|
||||
*
|
||||
* @param <T> the type of {@link Filter} to register
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
abstract class AbstractFilterRegistrationBean extends RegistrationBean {
|
||||
abstract class AbstractFilterRegistrationBean<T extends Filter> extends RegistrationBean {
|
||||
|
||||
/**
|
||||
* Filters that wrap the servlet request should be ordered less than or equal to this.
|
||||
@@ -58,7 +59,7 @@ abstract class AbstractFilterRegistrationBean extends RegistrationBean {
|
||||
|
||||
private static final String[] DEFAULT_URL_MAPPINGS = { "/*" };
|
||||
|
||||
private Set<ServletRegistrationBean> servletRegistrationBeans = new LinkedHashSet<ServletRegistrationBean>();
|
||||
private Set<ServletRegistrationBean<?>> servletRegistrationBeans = new LinkedHashSet<ServletRegistrationBean<?>>();
|
||||
|
||||
private Set<String> servletNames = new LinkedHashSet<String>();
|
||||
|
||||
@@ -73,7 +74,8 @@ abstract class AbstractFilterRegistrationBean extends RegistrationBean {
|
||||
* {@link ServletRegistrationBean}s.
|
||||
* @param servletRegistrationBeans associate {@link ServletRegistrationBean}s
|
||||
*/
|
||||
AbstractFilterRegistrationBean(ServletRegistrationBean... servletRegistrationBeans) {
|
||||
AbstractFilterRegistrationBean(
|
||||
ServletRegistrationBean<?>... servletRegistrationBeans) {
|
||||
Assert.notNull(servletRegistrationBeans,
|
||||
"ServletRegistrationBeans must not be null");
|
||||
Collections.addAll(this.servletRegistrationBeans, servletRegistrationBeans);
|
||||
@@ -84,10 +86,10 @@ abstract class AbstractFilterRegistrationBean extends RegistrationBean {
|
||||
* @param servletRegistrationBeans the Servlet registration beans
|
||||
*/
|
||||
public void setServletRegistrationBeans(
|
||||
Collection<? extends ServletRegistrationBean> servletRegistrationBeans) {
|
||||
Collection<? extends ServletRegistrationBean<?>> servletRegistrationBeans) {
|
||||
Assert.notNull(servletRegistrationBeans,
|
||||
"ServletRegistrationBeans must not be null");
|
||||
this.servletRegistrationBeans = new LinkedHashSet<ServletRegistrationBean>(
|
||||
this.servletRegistrationBeans = new LinkedHashSet<ServletRegistrationBean<?>>(
|
||||
servletRegistrationBeans);
|
||||
}
|
||||
|
||||
@@ -98,7 +100,7 @@ abstract class AbstractFilterRegistrationBean extends RegistrationBean {
|
||||
* @see #setServletNames
|
||||
* @see #setUrlPatterns
|
||||
*/
|
||||
public Collection<ServletRegistrationBean> getServletRegistrationBeans() {
|
||||
public Collection<ServletRegistrationBean<?>> getServletRegistrationBeans() {
|
||||
return this.servletRegistrationBeans;
|
||||
}
|
||||
|
||||
@@ -108,7 +110,7 @@ abstract class AbstractFilterRegistrationBean extends RegistrationBean {
|
||||
* @see #setServletRegistrationBeans
|
||||
*/
|
||||
public void addServletRegistrationBeans(
|
||||
ServletRegistrationBean... servletRegistrationBeans) {
|
||||
ServletRegistrationBean<?>... servletRegistrationBeans) {
|
||||
Assert.notNull(servletRegistrationBeans,
|
||||
"ServletRegistrationBeans must not be null");
|
||||
Collections.addAll(this.servletRegistrationBeans, servletRegistrationBeans);
|
||||
@@ -235,7 +237,7 @@ abstract class AbstractFilterRegistrationBean extends RegistrationBean {
|
||||
* Return the {@link Filter} to be registered.
|
||||
* @return the filter
|
||||
*/
|
||||
public abstract Filter getFilter();
|
||||
public abstract T getFilter();
|
||||
|
||||
/**
|
||||
* Configure registration settings. Subclasses can override this method to perform
|
||||
@@ -250,7 +252,7 @@ abstract class AbstractFilterRegistrationBean extends RegistrationBean {
|
||||
: NON_ASYNC_DISPATCHER_TYPES);
|
||||
}
|
||||
Set<String> servletNames = new LinkedHashSet<String>();
|
||||
for (ServletRegistrationBean servletRegistrationBean : this.servletRegistrationBeans) {
|
||||
for (ServletRegistrationBean<?> servletRegistrationBean : this.servletRegistrationBeans) {
|
||||
servletNames.add(servletRegistrationBean.getServletName());
|
||||
}
|
||||
servletNames.addAll(this.servletNames);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,7 +51,8 @@ import org.springframework.web.filter.DelegatingFilterProxy;
|
||||
* @see FilterRegistrationBean
|
||||
* @see DelegatingFilterProxy
|
||||
*/
|
||||
public class DelegatingFilterProxyRegistrationBean extends AbstractFilterRegistrationBean
|
||||
public class DelegatingFilterProxyRegistrationBean
|
||||
extends AbstractFilterRegistrationBean<DelegatingFilterProxy>
|
||||
implements ApplicationContextAware {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
@@ -66,7 +67,7 @@ public class DelegatingFilterProxyRegistrationBean extends AbstractFilterRegistr
|
||||
* @param servletRegistrationBeans associate {@link ServletRegistrationBean}s
|
||||
*/
|
||||
public DelegatingFilterProxyRegistrationBean(String targetBeanName,
|
||||
ServletRegistrationBean... servletRegistrationBeans) {
|
||||
ServletRegistrationBean<?>... servletRegistrationBeans) {
|
||||
super(servletRegistrationBeans);
|
||||
Assert.hasLength(targetBeanName, "TargetBeanName must not be null or empty");
|
||||
this.targetBeanName = targetBeanName;
|
||||
@@ -84,7 +85,7 @@ public class DelegatingFilterProxyRegistrationBean extends AbstractFilterRegistr
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
public DelegatingFilterProxy getFilter() {
|
||||
return new DelegatingFilterProxy(this.targetBeanName,
|
||||
getWebApplicationContext()) {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,20 +33,22 @@ import org.springframework.util.Assert;
|
||||
* URL pattern or servlets are specified the filter will be associated to '/*'. The filter
|
||||
* name will be deduced if not specified.
|
||||
*
|
||||
* @param <T> the type of {@link Filter} to register
|
||||
* @author Phillip Webb
|
||||
* @since 1.4.0
|
||||
* @see ServletContextInitializer
|
||||
* @see ServletContext#addFilter(String, Filter)
|
||||
* @see DelegatingFilterProxyRegistrationBean
|
||||
*/
|
||||
public class FilterRegistrationBean extends AbstractFilterRegistrationBean {
|
||||
public class FilterRegistrationBean<T extends Filter>
|
||||
extends AbstractFilterRegistrationBean<T> {
|
||||
|
||||
/**
|
||||
* Filters that wrap the servlet request should be ordered less than or equal to this.
|
||||
*/
|
||||
public static final int REQUEST_WRAPPER_FILTER_MAX_ORDER = AbstractFilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER;
|
||||
|
||||
private Filter filter;
|
||||
private T filter;
|
||||
|
||||
/**
|
||||
* Create a new {@link FilterRegistrationBean} instance.
|
||||
@@ -60,15 +62,15 @@ public class FilterRegistrationBean extends AbstractFilterRegistrationBean {
|
||||
* @param filter the filter to register
|
||||
* @param servletRegistrationBeans associate {@link ServletRegistrationBean}s
|
||||
*/
|
||||
public FilterRegistrationBean(Filter filter,
|
||||
ServletRegistrationBean... servletRegistrationBeans) {
|
||||
public FilterRegistrationBean(T filter,
|
||||
ServletRegistrationBean<?>... servletRegistrationBeans) {
|
||||
super(servletRegistrationBeans);
|
||||
Assert.notNull(filter, "Filter must not be null");
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
public T getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
@@ -76,7 +78,7 @@ public class FilterRegistrationBean extends AbstractFilterRegistrationBean {
|
||||
* Set the filter to be registered.
|
||||
* @param filter the filter
|
||||
*/
|
||||
public void setFilter(Filter filter) {
|
||||
public void setFilter(T filter) {
|
||||
Assert.notNull(filter, "Filter must not be null");
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@@ -98,12 +98,12 @@ public class ServletContextInitializerBeans
|
||||
private void addServletContextInitializerBean(String beanName,
|
||||
ServletContextInitializer initializer, ListableBeanFactory beanFactory) {
|
||||
if (initializer instanceof ServletRegistrationBean) {
|
||||
Servlet source = ((ServletRegistrationBean) initializer).getServlet();
|
||||
Servlet source = ((ServletRegistrationBean<?>) initializer).getServlet();
|
||||
addServletContextInitializerBean(Servlet.class, beanName, initializer,
|
||||
beanFactory, source);
|
||||
}
|
||||
else if (initializer instanceof FilterRegistrationBean) {
|
||||
Filter source = ((FilterRegistrationBean) initializer).getFilter();
|
||||
Filter source = ((FilterRegistrationBean<?>) initializer).getFilter();
|
||||
addServletContextInitializerBean(Filter.class, beanName, initializer,
|
||||
beanFactory, source);
|
||||
}
|
||||
@@ -282,7 +282,8 @@ public class ServletContextInitializerBeans
|
||||
if (name.equals(DISPATCHER_SERVLET_NAME)) {
|
||||
url = "/"; // always map the main dispatcherServlet to "/"
|
||||
}
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(source, url);
|
||||
ServletRegistrationBean<Servlet> bean = new ServletRegistrationBean<Servlet>(
|
||||
source, url);
|
||||
bean.setMultipartConfig(this.multipartConfig);
|
||||
return bean;
|
||||
}
|
||||
@@ -298,7 +299,7 @@ public class ServletContextInitializerBeans
|
||||
@Override
|
||||
public RegistrationBean createRegistrationBean(String name, Filter source,
|
||||
int totalNumberOfSourceBeans) {
|
||||
return new FilterRegistrationBean(source);
|
||||
return new FilterRegistrationBean<Filter>(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,18 +46,19 @@ import org.springframework.util.ObjectUtils;
|
||||
* {@link #ServletRegistrationBean(Servlet, boolean, String...) alwaysMapUrl} is set to
|
||||
* {@code false}). The servlet name will be deduced if not specified.
|
||||
*
|
||||
* @param <T> the type of the {@link Servlet} to register
|
||||
* @author Phillip Webb
|
||||
* @since 1.4.0
|
||||
* @see ServletContextInitializer
|
||||
* @see ServletContext#addServlet(String, Servlet)
|
||||
*/
|
||||
public class ServletRegistrationBean extends RegistrationBean {
|
||||
public class ServletRegistrationBean<T extends Servlet> extends RegistrationBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ServletRegistrationBean.class);
|
||||
|
||||
private static final String[] DEFAULT_MAPPINGS = { "/*" };
|
||||
|
||||
private Servlet servlet;
|
||||
private T servlet;
|
||||
|
||||
private Set<String> urlMappings = new LinkedHashSet<String>();
|
||||
|
||||
@@ -79,7 +80,7 @@ public class ServletRegistrationBean extends RegistrationBean {
|
||||
* @param servlet the servlet being mapped
|
||||
* @param urlMappings the URLs being mapped
|
||||
*/
|
||||
public ServletRegistrationBean(Servlet servlet, String... urlMappings) {
|
||||
public ServletRegistrationBean(T servlet, String... urlMappings) {
|
||||
this(servlet, true, urlMappings);
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ public class ServletRegistrationBean extends RegistrationBean {
|
||||
* @param alwaysMapUrl if omitted URL mappings should be replaced with '/*'
|
||||
* @param urlMappings the URLs being mapped
|
||||
*/
|
||||
public ServletRegistrationBean(Servlet servlet, boolean alwaysMapUrl,
|
||||
public ServletRegistrationBean(T servlet, boolean alwaysMapUrl,
|
||||
String... urlMappings) {
|
||||
Assert.notNull(servlet, "Servlet must not be null");
|
||||
Assert.notNull(urlMappings, "UrlMappings must not be null");
|
||||
@@ -103,7 +104,7 @@ public class ServletRegistrationBean extends RegistrationBean {
|
||||
* Returns the servlet being registered.
|
||||
* @return the servlet
|
||||
*/
|
||||
protected Servlet getServlet() {
|
||||
protected T getServlet() {
|
||||
return this.servlet;
|
||||
}
|
||||
|
||||
@@ -111,7 +112,7 @@ public class ServletRegistrationBean extends RegistrationBean {
|
||||
* Sets the servlet to be registered.
|
||||
* @param servlet the servlet
|
||||
*/
|
||||
public void setServlet(Servlet servlet) {
|
||||
public void setServlet(T servlet) {
|
||||
Assert.notNull(servlet, "Servlet must not be null");
|
||||
this.servlet = servlet;
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
public void startServletAndFilter() throws Exception {
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
this.container = factory.getEmbeddedServletContainer(exampleServletRegistration(),
|
||||
new FilterRegistrationBean(new ExampleFilter()));
|
||||
new FilterRegistrationBean<ExampleFilter>(new ExampleFilter()));
|
||||
this.container.start();
|
||||
assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("[Hello World]");
|
||||
}
|
||||
@@ -409,8 +409,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
Ssl ssl = getSsl(null, "password", "classpath:test.jks");
|
||||
ssl.setEnabled(false);
|
||||
factory.setSsl(ssl);
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet(true, false), "/hello"));
|
||||
this.container.start();
|
||||
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
|
||||
new SSLContextBuilder()
|
||||
@@ -427,8 +428,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
public void sslGetScheme() throws Exception { // gh-2232
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet(true, false), "/hello"));
|
||||
this.container.start();
|
||||
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
|
||||
new SSLContextBuilder()
|
||||
@@ -445,8 +447,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
public void serverHeaderIsDisabledByDefaultWhenUsingSsl() throws Exception {
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet(true, false), "/hello"));
|
||||
this.container.start();
|
||||
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
|
||||
new SSLContextBuilder()
|
||||
@@ -463,8 +466,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
factory.setServerHeader("MyServer");
|
||||
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet(true, false), "/hello"));
|
||||
this.container.start();
|
||||
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
|
||||
new SSLContextBuilder()
|
||||
@@ -685,8 +689,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks", null,
|
||||
protocols, ciphers));
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet(true, false), "/hello"));
|
||||
this.container.start();
|
||||
|
||||
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
|
||||
@@ -806,8 +811,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
Compression compression = new Compression();
|
||||
compression.setEnabled(true);
|
||||
factory.setCompression(compression);
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(false, true), "/hello"));
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet(false, true), "/hello"));
|
||||
this.container.start();
|
||||
TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
|
||||
Map<String, InputStreamFactory> contentDecoderMap = Collections
|
||||
@@ -1117,8 +1123,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
|
||||
protected void assertForwardHeaderIsUsed(EmbeddedServletContainerFactory factory)
|
||||
throws IOException, URISyntaxException {
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(true, false), "/hello"));
|
||||
this.container = factory
|
||||
.getEmbeddedServletContainer(new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet(true, false), "/hello"));
|
||||
this.container.start();
|
||||
assertThat(getResponse(getLocalUrl("/hello"), "X-Forwarded-For:140.211.11.130"))
|
||||
.contains("remoteaddr=140.211.11.130");
|
||||
@@ -1130,39 +1137,43 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
|
||||
throws Exception;
|
||||
|
||||
protected ServletContextInitializer exampleServletRegistration() {
|
||||
return new ServletRegistrationBean(new ExampleServlet(), "/hello");
|
||||
return new ServletRegistrationBean<ExampleServlet>(new ExampleServlet(),
|
||||
"/hello");
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private ServletContextInitializer errorServletRegistration() {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(new ExampleServlet() {
|
||||
ServletRegistrationBean<ExampleServlet> bean = new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet() {
|
||||
|
||||
@Override
|
||||
public void service(ServletRequest request, ServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
@Override
|
||||
public void service(ServletRequest request, ServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
|
||||
}, "/bang");
|
||||
}, "/bang");
|
||||
bean.setName("error");
|
||||
return bean;
|
||||
}
|
||||
|
||||
protected final ServletContextInitializer sessionServletRegistration() {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(new ExampleServlet() {
|
||||
ServletRegistrationBean<ExampleServlet> bean = new ServletRegistrationBean<ExampleServlet>(
|
||||
new ExampleServlet() {
|
||||
|
||||
@Override
|
||||
public void service(ServletRequest request, ServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
HttpSession session = ((HttpServletRequest) request).getSession(true);
|
||||
long value = System.currentTimeMillis();
|
||||
Object existing = session.getAttribute("boot");
|
||||
session.setAttribute("boot", value);
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.append(String.valueOf(existing) + ":" + value);
|
||||
}
|
||||
@Override
|
||||
public void service(ServletRequest request, ServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
HttpSession session = ((HttpServletRequest) request)
|
||||
.getSession(true);
|
||||
long value = System.currentTimeMillis();
|
||||
Object existing = session.getAttribute("boot");
|
||||
session.setAttribute("boot", value);
|
||||
PrintWriter writer = response.getWriter();
|
||||
writer.append(String.valueOf(existing) + ":" + value);
|
||||
}
|
||||
|
||||
}, "/session");
|
||||
}, "/session");
|
||||
bean.setName("session");
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -97,8 +97,8 @@ public class EmbeddedServletContainerMvcIntegrationTests {
|
||||
String resourcePath) throws Exception {
|
||||
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
|
||||
ClientHttpRequest request = clientHttpRequestFactory.createRequest(
|
||||
new URI("http://localhost:"
|
||||
+ context.getEmbeddedWebServer().getPort() + resourcePath),
|
||||
new URI("http://localhost:" + context.getEmbeddedWebServer().getPort()
|
||||
+ resourcePath),
|
||||
HttpMethod.GET);
|
||||
ClientHttpResponse response = request.execute();
|
||||
try {
|
||||
@@ -190,8 +190,8 @@ public class EmbeddedServletContainerMvcIntegrationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean dispatcherRegistration() {
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(
|
||||
public ServletRegistrationBean<DispatcherServlet> dispatcherRegistration() {
|
||||
ServletRegistrationBean<DispatcherServlet> registration = new ServletRegistrationBean<DispatcherServlet>(
|
||||
dispatcherServlet());
|
||||
registration.addUrlMappings("/spring/*");
|
||||
return registration;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -232,7 +232,7 @@ public class EmbeddedWebApplicationContextTests {
|
||||
addEmbeddedServletContainerFactoryBean();
|
||||
OrderedFilter filter = new OrderedFilter();
|
||||
this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||
FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<Filter>();
|
||||
registration.setFilter(mock(Filter.class));
|
||||
registration.setOrder(100);
|
||||
this.context.registerBeanDefinition("filterRegistrationBean",
|
||||
@@ -391,8 +391,8 @@ public class EmbeddedWebApplicationContextTests {
|
||||
addEmbeddedServletContainerFactoryBean();
|
||||
Servlet servlet = mock(Servlet.class);
|
||||
Filter filter = mock(Filter.class);
|
||||
ServletRegistrationBean initializer = new ServletRegistrationBean(servlet,
|
||||
"/foo");
|
||||
ServletRegistrationBean<Servlet> initializer = new ServletRegistrationBean<Servlet>(
|
||||
servlet, "/foo");
|
||||
this.context.registerBeanDefinition("initializerBean",
|
||||
beanDefinition(initializer));
|
||||
this.context.registerBeanDefinition("servletBean", beanDefinition(servlet));
|
||||
@@ -408,7 +408,8 @@ public class EmbeddedWebApplicationContextTests {
|
||||
public void filterRegistrationBeansSkipsRegisteredFilters() throws Exception {
|
||||
addEmbeddedServletContainerFactoryBean();
|
||||
Filter filter = mock(Filter.class);
|
||||
FilterRegistrationBean initializer = new FilterRegistrationBean(filter);
|
||||
FilterRegistrationBean<Filter> initializer = new FilterRegistrationBean<Filter>(
|
||||
filter);
|
||||
this.context.registerBeanDefinition("initializerBean",
|
||||
beanDefinition(initializer));
|
||||
this.context.registerBeanDefinition("filterBean", beanDefinition(filter));
|
||||
|
||||
@@ -291,7 +291,7 @@ public class JettyEmbeddedServletContainerFactoryTests
|
||||
}
|
||||
factory.setCompression(compression);
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new HttpServlet() {
|
||||
new ServletRegistrationBean<HttpServlet>(new HttpServlet() {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -73,7 +73,8 @@ public class UndertowEmbeddedServletContainerFactoryTests
|
||||
AbstractEmbeddedServletContainerFactory factory = getFactory();
|
||||
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/hello"));
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(), "/hello"));
|
||||
new ServletRegistrationBean<ExampleServlet>(new ExampleServlet(),
|
||||
"/hello"));
|
||||
this.container.start();
|
||||
assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
|
||||
assertThat(getResponse(getLocalUrl("/not-found"))).isEqualTo("Hello World");
|
||||
@@ -199,7 +200,8 @@ public class UndertowEmbeddedServletContainerFactoryTests
|
||||
factory.setAccessLogDirectory(accessLogDirectory);
|
||||
assertThat(accessLogDirectory.listFiles()).isEmpty();
|
||||
this.container = factory.getEmbeddedServletContainer(
|
||||
new ServletRegistrationBean(new ExampleServlet(), "/hello"));
|
||||
new ServletRegistrationBean<ExampleServlet>(new ExampleServlet(),
|
||||
"/hello"));
|
||||
this.container.start();
|
||||
assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
|
||||
File accessLog = new File(accessLogDirectory, expectedFile);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterRegistration;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -74,7 +75,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void startupWithDefaults() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.servletContext).addFilter(eq("mockFilter"), getExpectedFilter());
|
||||
verify(this.registration).setAsyncSupported(true);
|
||||
@@ -84,7 +85,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void startupWithSpecifiedValues() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.setName("test");
|
||||
bean.setAsyncSupported(false);
|
||||
bean.setInitParameters(Collections.singletonMap("a", "b"));
|
||||
@@ -112,7 +113,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void specificName() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.setName("specificName");
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.servletContext).addFilter(eq("specificName"), getExpectedFilter());
|
||||
@@ -120,14 +121,14 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void deducedName() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.servletContext).addFilter(eq("mockFilter"), getExpectedFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disable() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.setEnabled(false);
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.servletContext, times(0)).addFilter(eq("mockFilter"),
|
||||
@@ -136,7 +137,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void setServletRegistrationBeanMustNotBeNull() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ServletRegistrationBeans must not be null");
|
||||
bean.setServletRegistrationBeans(null);
|
||||
@@ -144,7 +145,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void addServletRegistrationBeanMustNotBeNull() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ServletRegistrationBeans must not be null");
|
||||
bean.addServletRegistrationBeans((ServletRegistrationBean[]) null);
|
||||
@@ -152,9 +153,9 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void setServletRegistrationBeanReplacesValue() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean(
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean(
|
||||
mockServletRegistration("a"));
|
||||
bean.setServletRegistrationBeans(new LinkedHashSet<ServletRegistrationBean>(
|
||||
bean.setServletRegistrationBeans(new LinkedHashSet<ServletRegistrationBean<?>>(
|
||||
Arrays.asList(mockServletRegistration("b"))));
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.registration).addMappingForServletNames(ASYNC_DISPATCHER_TYPES, false,
|
||||
@@ -163,7 +164,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void modifyInitParameters() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.addInitParameter("a", "b");
|
||||
bean.getInitParameters().put("a", "c");
|
||||
bean.onStartup(this.servletContext);
|
||||
@@ -172,7 +173,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void setUrlPatternMustNotBeNull() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("UrlPatterns must not be null");
|
||||
bean.setUrlPatterns(null);
|
||||
@@ -180,7 +181,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void addUrlPatternMustNotBeNull() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("UrlPatterns must not be null");
|
||||
bean.addUrlPatterns((String[]) null);
|
||||
@@ -188,7 +189,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void setServletNameMustNotBeNull() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ServletNames must not be null");
|
||||
bean.setServletNames(null);
|
||||
@@ -196,7 +197,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void addServletNameMustNotBeNull() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ServletNames must not be null");
|
||||
bean.addServletNames((String[]) null);
|
||||
@@ -204,7 +205,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void withSpecificDispatcherTypes() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
bean.setDispatcherTypes(DispatcherType.INCLUDE, DispatcherType.FORWARD);
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.registration).addMappingForUrlPatterns(
|
||||
@@ -213,7 +214,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void withSpecificDispatcherTypesEnumSet() throws Exception {
|
||||
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
||||
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
||||
EnumSet<DispatcherType> types = EnumSet.of(DispatcherType.INCLUDE,
|
||||
DispatcherType.FORWARD);
|
||||
bean.setDispatcherTypes(types);
|
||||
@@ -223,11 +224,11 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
||||
|
||||
protected abstract Filter getExpectedFilter();
|
||||
|
||||
protected abstract AbstractFilterRegistrationBean createFilterRegistrationBean(
|
||||
ServletRegistrationBean... servletRegistrationBeans);
|
||||
protected abstract AbstractFilterRegistrationBean<?> createFilterRegistrationBean(
|
||||
ServletRegistrationBean<?>... servletRegistrationBeans);
|
||||
|
||||
protected final ServletRegistrationBean mockServletRegistration(String name) {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean();
|
||||
protected final ServletRegistrationBean<?> mockServletRegistration(String name) {
|
||||
ServletRegistrationBean<?> bean = new ServletRegistrationBean<Servlet>();
|
||||
bean.setName(name);
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -75,7 +75,7 @@ public class DelegatingFilterProxyRegistrationBeanTests
|
||||
|
||||
@Test
|
||||
public void getFilterUsesDelegatingFilterProxy() throws Exception {
|
||||
AbstractFilterRegistrationBean registrationBean = createFilterRegistrationBean();
|
||||
DelegatingFilterProxyRegistrationBean registrationBean = createFilterRegistrationBean();
|
||||
Filter filter = registrationBean.getFilter();
|
||||
assertThat(filter).isInstanceOf(DelegatingFilterProxy.class);
|
||||
assertThat(ReflectionTestUtils.getField(filter, "webApplicationContext"))
|
||||
@@ -88,7 +88,7 @@ public class DelegatingFilterProxyRegistrationBeanTests
|
||||
public void initShouldNotCauseEarlyInitialization() throws Exception {
|
||||
this.applicationContext.registerBeanDefinition("mockFilter",
|
||||
new RootBeanDefinition(MockFilter.class));
|
||||
AbstractFilterRegistrationBean registrationBean = createFilterRegistrationBean();
|
||||
DelegatingFilterProxyRegistrationBean registrationBean = createFilterRegistrationBean();
|
||||
Filter filter = registrationBean.getFilter();
|
||||
filter.init(new MockFilterConfig());
|
||||
assertThat(mockFilterInitialized.get()).isNull();
|
||||
@@ -106,8 +106,8 @@ public class DelegatingFilterProxyRegistrationBeanTests
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractFilterRegistrationBean createFilterRegistrationBean(
|
||||
ServletRegistrationBean... servletRegistrationBeans) {
|
||||
protected DelegatingFilterProxyRegistrationBean createFilterRegistrationBean(
|
||||
ServletRegistrationBean<?>... servletRegistrationBeans) {
|
||||
DelegatingFilterProxyRegistrationBean bean = new DelegatingFilterProxyRegistrationBean(
|
||||
"mockFilter", servletRegistrationBeans);
|
||||
bean.setApplicationContext(this.applicationContext);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,7 @@ public class FilterRegistrationBeanTests extends AbstractFilterRegistrationBeanT
|
||||
|
||||
@Test
|
||||
public void setFilter() throws Exception {
|
||||
FilterRegistrationBean bean = new FilterRegistrationBean();
|
||||
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<Filter>();
|
||||
bean.setFilter(this.filter);
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.servletContext).addFilter("mockFilter", this.filter);
|
||||
@@ -44,7 +44,7 @@ public class FilterRegistrationBeanTests extends AbstractFilterRegistrationBeanT
|
||||
|
||||
@Test
|
||||
public void setFilterMustNotBeNull() throws Exception {
|
||||
FilterRegistrationBean bean = new FilterRegistrationBean();
|
||||
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<Filter>();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Filter must not be null");
|
||||
bean.onStartup(this.servletContext);
|
||||
@@ -54,20 +54,22 @@ public class FilterRegistrationBeanTests extends AbstractFilterRegistrationBeanT
|
||||
public void constructFilterMustNotBeNull() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Filter must not be null");
|
||||
new FilterRegistrationBean(null);
|
||||
new FilterRegistrationBean<Filter>(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createServletRegistrationBeanMustNotBeNull() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("ServletRegistrationBeans must not be null");
|
||||
new FilterRegistrationBean(this.filter, (ServletRegistrationBean[]) null);
|
||||
new FilterRegistrationBean<MockFilter>(this.filter,
|
||||
(ServletRegistrationBean[]) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractFilterRegistrationBean createFilterRegistrationBean(
|
||||
ServletRegistrationBean... servletRegistrationBeans) {
|
||||
return new FilterRegistrationBean(this.filter, servletRegistrationBeans);
|
||||
protected AbstractFilterRegistrationBean<MockFilter> createFilterRegistrationBean(
|
||||
ServletRegistrationBean<?>... servletRegistrationBeans) {
|
||||
return new FilterRegistrationBean<MockFilter>(this.filter,
|
||||
servletRegistrationBeans);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -67,9 +67,10 @@ public class ServletComponentScanIntegrationTests {
|
||||
this.context.register(TestConfiguration.class);
|
||||
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
|
||||
this.context.refresh();
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map<String, ServletRegistrationBean> beans = this.context
|
||||
.getBeansOfType(ServletRegistrationBean.class);
|
||||
ServletRegistrationBean servletRegistrationBean = beans
|
||||
ServletRegistrationBean<?> servletRegistrationBean = beans
|
||||
.get(TestMultipartServlet.class.getName());
|
||||
assertThat(servletRegistrationBean).isNotNull();
|
||||
MultipartConfigElement multipartConfig = servletRegistrationBean
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,7 +76,8 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void startupWithDefaults() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(this.servlet);
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>(
|
||||
this.servlet);
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.servletContext).addServlet("mockServlet", this.servlet);
|
||||
verify(this.registration).setAsyncSupported(true);
|
||||
@@ -85,7 +86,8 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void startupWithDoubleRegistration() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(this.servlet);
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>(
|
||||
this.servlet);
|
||||
given(this.servletContext.addServlet(anyString(), (Servlet) any()))
|
||||
.willReturn(null);
|
||||
bean.onStartup(this.servletContext);
|
||||
@@ -95,7 +97,7 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void startupWithSpecifiedValues() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean();
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>();
|
||||
bean.setName("test");
|
||||
bean.setServlet(this.servlet);
|
||||
bean.setAsyncSupported(false);
|
||||
@@ -117,7 +119,7 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void specificName() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean();
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>();
|
||||
bean.setName("specificName");
|
||||
bean.setServlet(this.servlet);
|
||||
bean.onStartup(this.servletContext);
|
||||
@@ -126,7 +128,7 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void deducedName() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean();
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>();
|
||||
bean.setServlet(this.servlet);
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.servletContext).addServlet("mockServlet", this.servlet);
|
||||
@@ -134,7 +136,7 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void disable() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean();
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>();
|
||||
bean.setServlet(this.servlet);
|
||||
bean.setEnabled(false);
|
||||
bean.onStartup(this.servletContext);
|
||||
@@ -143,7 +145,7 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void setServletMustNotBeNull() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean();
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Servlet must not be null");
|
||||
bean.onStartup(this.servletContext);
|
||||
@@ -153,12 +155,13 @@ public class ServletRegistrationBeanTests {
|
||||
public void createServletMustNotBeNull() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Servlet must not be null");
|
||||
new ServletRegistrationBean(null);
|
||||
new ServletRegistrationBean<MockServlet>(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setMappingMustNotBeNull() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(this.servlet);
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>(
|
||||
this.servlet);
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("UrlMappings must not be null");
|
||||
bean.setUrlMappings(null);
|
||||
@@ -168,12 +171,13 @@ public class ServletRegistrationBeanTests {
|
||||
public void createMappingMustNotBeNull() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("UrlMappings must not be null");
|
||||
new ServletRegistrationBean(this.servlet, (String[]) null);
|
||||
new ServletRegistrationBean<MockServlet>(this.servlet, (String[]) null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addMappingMustNotBeNull() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(this.servlet);
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>(
|
||||
this.servlet);
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("UrlMappings must not be null");
|
||||
bean.addUrlMappings((String[]) null);
|
||||
@@ -181,8 +185,8 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void setMappingReplacesValue() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(this.servlet, "/a",
|
||||
"/b");
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>(
|
||||
this.servlet, "/a", "/b");
|
||||
bean.setUrlMappings(new LinkedHashSet<String>(Arrays.asList("/c", "/d")));
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.registration).addMapping("/c", "/d");
|
||||
@@ -190,8 +194,8 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void modifyInitParameters() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(this.servlet, "/a",
|
||||
"/b");
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>(
|
||||
this.servlet, "/a", "/b");
|
||||
bean.addInitParameter("a", "b");
|
||||
bean.getInitParameters().put("a", "c");
|
||||
bean.onStartup(this.servletContext);
|
||||
@@ -200,7 +204,8 @@ public class ServletRegistrationBeanTests {
|
||||
|
||||
@Test
|
||||
public void withoutDefaultMappings() throws Exception {
|
||||
ServletRegistrationBean bean = new ServletRegistrationBean(this.servlet, false);
|
||||
ServletRegistrationBean<MockServlet> bean = new ServletRegistrationBean<MockServlet>(
|
||||
this.servlet, false);
|
||||
bean.onStartup(this.servletContext);
|
||||
verify(this.registration, never()).addMapping((String[]) any());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user