use of cn.taketoday.web.servlet.initializer.WebServletInitializer in project today-framework by TAKETODAY.
the class AbstractServletWebServer method addDefaultServlet.
/**
* Add default servlet
*/
protected void addDefaultServlet() {
DefaultServletConfiguration servletConfiguration = this.defaultServletConfiguration;
if (servletConfiguration != null) {
// config default servlet
getWebApplicationConfiguration().configureDefaultServlet(servletConfiguration);
if (servletConfiguration.isEnable()) {
Servlet defaultServlet = getDefaultServlet(servletConfiguration);
if (defaultServlet != null) {
log.info("Default servlet is enabled, use servlet: [{}]", defaultServlet.getServletInfo());
WebServletInitializer<Servlet> initializer = new WebServletInitializer<>(defaultServlet);
initializer.setName(Constant.DEFAULT);
initializer.setOrder(Ordered.HIGHEST_PRECEDENCE);
initializer.addUrlMappings(servletConfiguration.getUrlMappings());
initializer.setInitParameters(servletConfiguration.getInitParameters());
getContextInitializers().add(initializer);
}
}
}
}
use of cn.taketoday.web.servlet.initializer.WebServletInitializer in project today-framework by TAKETODAY.
the class AbstractServletWebServer method addJspServlet.
/**
* Add jsp to context
*/
protected void addJspServlet() {
JspServletConfiguration jspServletConfiguration = this.jspServletConfiguration;
if (jspServletConfiguration != null) {
// config jsp servlet
getWebApplicationConfiguration().configureJspServlet(jspServletConfiguration);
if (jspServletConfiguration.isEnabled()) {
try {
Servlet jspServlet = BeanUtils.newInstance(jspServletConfiguration.getClassName());
log.info("Jsp is enabled, use jsp servlet: [{}]", jspServlet.getServletInfo());
WebServletInitializer<Servlet> initializer = new WebServletInitializer<>(jspServlet);
initializer.setName(jspServletConfiguration.getName());
initializer.setOrder(Ordered.HIGHEST_PRECEDENCE);
initializer.addUrlMappings(jspServletConfiguration.getUrlMappings());
initializer.setInitParameters(jspServletConfiguration.getInitParameters());
getContextInitializers().add(initializer);
} catch (ClassNotFoundException e) {
throw new ConfigurationException("jsp servlet class not found", e);
}
}
}
}
use of cn.taketoday.web.servlet.initializer.WebServletInitializer in project today-framework by TAKETODAY.
the class WebServletApplicationLoader method configureServletInitializers.
/**
* Configure {@link Servlet}
*
* @param applicationContext {@link ApplicationContext}
* @param contextInitializers {@link WebApplicationInitializer}s
*/
protected void configureServletInitializers(WebApplicationContext applicationContext, List<WebApplicationInitializer> contextInitializers) {
Collection<Servlet> servlets = applicationContext.getAnnotatedBeans(WebServlet.class);
for (Servlet servlet : servlets) {
Class<?> beanClass = servlet.getClass();
WebServletInitializer<Servlet> webServletInitializer = new WebServletInitializer<>(servlet);
WebServlet webServlet = beanClass.getAnnotation(WebServlet.class);
String[] urlPatterns = webServlet.urlPatterns();
if (ObjectUtils.isEmpty(urlPatterns)) {
urlPatterns = new String[] { BeanDefinitionBuilder.defaultBeanName(beanClass) };
}
webServletInitializer.addUrlMappings(urlPatterns);
webServletInitializer.setLoadOnStartup(webServlet.loadOnStartup());
webServletInitializer.setAsyncSupported(webServlet.asyncSupported());
for (WebInitParam initParam : webServlet.initParams()) {
webServletInitializer.addInitParameter(initParam.name(), initParam.value());
}
MultipartConfig multipartConfig = beanClass.getAnnotation(MultipartConfig.class);
if (multipartConfig != null) {
webServletInitializer.setMultipartConfig(new MultipartConfigElement(multipartConfig));
}
ServletSecurity servletSecurity = beanClass.getAnnotation(ServletSecurity.class);
if (servletSecurity != null) {
webServletInitializer.setServletSecurity(new ServletSecurityElement(servletSecurity));
}
String name = webServlet.name();
if (StringUtils.isEmpty(name)) {
String displayName = webServlet.displayName();
if (StringUtils.isEmpty(displayName)) {
name = BeanDefinitionBuilder.defaultBeanName(beanClass);
} else {
name = displayName;
}
}
webServletInitializer.setName(name);
contextInitializers.add(webServletInitializer);
}
}
Aggregations