|
|
@ -31,6 +31,7 @@ import javax.servlet.ServletRegistration.Dynamic;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+
|
|
|
|
* A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+
|
|
|
@ -40,7 +41,9 @@ import org.springframework.util.Assert;
|
|
|
|
* <p>
|
|
|
|
* <p>
|
|
|
|
* The {@link #setServlet(Servlet) servlet} must be specified before calling
|
|
|
|
* The {@link #setServlet(Servlet) servlet} must be specified before calling
|
|
|
|
* {@link #onStartup}. URL mapping can be configured used {@link #setUrlMappings} or
|
|
|
|
* {@link #onStartup}. URL mapping can be configured used {@link #setUrlMappings} or
|
|
|
|
* omitted when mapping to '/*'. The servlet name will be deduced if not specified.
|
|
|
|
* omitted when mapping to '/*' (unless
|
|
|
|
|
|
|
|
* {@link #ServletRegistrationBean(Servlet, boolean, String...) alwaysMapUrl} is set to
|
|
|
|
|
|
|
|
* {@code false}). The servlet name will be deduced if not specified.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @see ServletContextInitializer
|
|
|
|
* @see ServletContextInitializer
|
|
|
@ -56,6 +59,8 @@ public class ServletRegistrationBean extends RegistrationBean {
|
|
|
|
|
|
|
|
|
|
|
|
private Set<String> urlMappings = new LinkedHashSet<String>();
|
|
|
|
private Set<String> urlMappings = new LinkedHashSet<String>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean alwaysMapUrl = true;
|
|
|
|
|
|
|
|
|
|
|
|
private int loadOnStartup = -1;
|
|
|
|
private int loadOnStartup = -1;
|
|
|
|
|
|
|
|
|
|
|
|
private MultipartConfigElement multipartConfig;
|
|
|
|
private MultipartConfigElement multipartConfig;
|
|
|
@ -73,9 +78,22 @@ public class ServletRegistrationBean extends RegistrationBean {
|
|
|
|
* @param urlMappings the URLs being mapped
|
|
|
|
* @param urlMappings the URLs being mapped
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public ServletRegistrationBean(Servlet servlet, String... urlMappings) {
|
|
|
|
public ServletRegistrationBean(Servlet servlet, String... urlMappings) {
|
|
|
|
|
|
|
|
this(servlet, true, urlMappings);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Create a new {@link ServletRegistrationBean} instance with the specified
|
|
|
|
|
|
|
|
* {@link Servlet} and URL mappings.
|
|
|
|
|
|
|
|
* @param servlet the servlet being mapped
|
|
|
|
|
|
|
|
* @param alwaysMapUrl if omitted URL mappings should be replaced with '/*'
|
|
|
|
|
|
|
|
* @param urlMappings the URLs being mapped
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public ServletRegistrationBean(Servlet servlet, boolean alwaysMapUrl,
|
|
|
|
|
|
|
|
String... urlMappings) {
|
|
|
|
Assert.notNull(servlet, "Servlet must not be null");
|
|
|
|
Assert.notNull(servlet, "Servlet must not be null");
|
|
|
|
Assert.notNull(urlMappings, "UrlMappings must not be null");
|
|
|
|
Assert.notNull(urlMappings, "UrlMappings must not be null");
|
|
|
|
this.servlet = servlet;
|
|
|
|
this.servlet = servlet;
|
|
|
|
|
|
|
|
this.alwaysMapUrl = alwaysMapUrl;
|
|
|
|
this.urlMappings.addAll(Arrays.asList(urlMappings));
|
|
|
|
this.urlMappings.addAll(Arrays.asList(urlMappings));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -164,7 +182,7 @@ public class ServletRegistrationBean extends RegistrationBean {
|
|
|
|
Assert.notNull(this.servlet, "Servlet must not be null");
|
|
|
|
Assert.notNull(this.servlet, "Servlet must not be null");
|
|
|
|
String name = getServletName();
|
|
|
|
String name = getServletName();
|
|
|
|
if (!isEnabled()) {
|
|
|
|
if (!isEnabled()) {
|
|
|
|
logger.info("Filter " + name + " was not registered (disabled)");
|
|
|
|
logger.info("Servlet " + name + " was not registered (disabled)");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings);
|
|
|
|
logger.info("Mapping servlet: '" + name + "' to " + this.urlMappings);
|
|
|
@ -186,10 +204,12 @@ public class ServletRegistrationBean extends RegistrationBean {
|
|
|
|
super.configure(registration);
|
|
|
|
super.configure(registration);
|
|
|
|
String[] urlMapping = this.urlMappings
|
|
|
|
String[] urlMapping = this.urlMappings
|
|
|
|
.toArray(new String[this.urlMappings.size()]);
|
|
|
|
.toArray(new String[this.urlMappings.size()]);
|
|
|
|
if (urlMapping.length == 0) {
|
|
|
|
if (urlMapping.length == 0 && this.alwaysMapUrl) {
|
|
|
|
urlMapping = DEFAULT_MAPPINGS;
|
|
|
|
urlMapping = DEFAULT_MAPPINGS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
registration.addMapping(urlMapping);
|
|
|
|
if (!ObjectUtils.isEmpty(urlMapping)) {
|
|
|
|
|
|
|
|
registration.addMapping(urlMapping);
|
|
|
|
|
|
|
|
}
|
|
|
|
registration.setLoadOnStartup(this.loadOnStartup);
|
|
|
|
registration.setLoadOnStartup(this.loadOnStartup);
|
|
|
|
if (this.multipartConfig != null) {
|
|
|
|
if (this.multipartConfig != null) {
|
|
|
|
registration.setMultipartConfig(this.multipartConfig);
|
|
|
|
registration.setMultipartConfig(this.multipartConfig);
|
|
|
|