use of jakarta.servlet.Servlet in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method servletAndFilterBeans.
@Test
void servletAndFilterBeans() {
addWebServerFactoryBean();
Servlet servlet = mock(Servlet.class);
Filter filter1 = mock(Filter.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) filter1).getOrder()).willReturn(1);
Filter filter2 = mock(Filter.class, withSettings().extraInterfaces(Ordered.class));
given(((Ordered) filter2).getOrder()).willReturn(2);
this.context.registerBeanDefinition("servletBean", beanDefinition(servlet));
this.context.registerBeanDefinition("filterBean2", beanDefinition(filter2));
this.context.registerBeanDefinition("filterBean1", beanDefinition(filter1));
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
ServletContext servletContext = factory.getServletContext();
InOrder ordered = inOrder(servletContext);
then(factory.getServletContext()).should().addServlet("servletBean", servlet);
then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/");
then(factory.getServletContext()).should(ordered).addFilter("filterBean1", filter1);
then(factory.getServletContext()).should(ordered).addFilter("filterBean2", filter2);
then(factory.getRegisteredFilter(0).getRegistration()).should().addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
then(factory.getRegisteredFilter(1).getRegistration()).should().addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
}
use of jakarta.servlet.Servlet in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method singleServletBean.
@Test
void singleServletBean() {
addWebServerFactoryBean();
Servlet servlet = mock(Servlet.class);
this.context.registerBeanDefinition("servletBean", beanDefinition(servlet));
this.context.refresh();
MockServletWebServerFactory factory = getWebServerFactory();
then(factory.getServletContext()).should().addServlet("servletBean", servlet);
then(factory.getRegisteredServlet(0).getRegistration()).should().addMapping("/");
}
use of jakarta.servlet.Servlet in project spring-boot by spring-projects.
the class AnnotationConfigServletWebServerApplicationContextTests method verifyContext.
private void verifyContext() {
MockServletWebServerFactory factory = this.context.getBean(MockServletWebServerFactory.class);
Servlet servlet = this.context.getBean(Servlet.class);
then(factory.getServletContext()).should().addServlet("servlet", servlet);
}
use of jakarta.servlet.Servlet in project spring-boot by spring-projects.
the class ServletContextInitializerBeans method addServletContextInitializerBean.
private void addServletContextInitializerBean(String beanName, ServletContextInitializer initializer, ListableBeanFactory beanFactory) {
if (initializer instanceof ServletRegistrationBean) {
Servlet source = ((ServletRegistrationBean<?>) initializer).getServlet();
addServletContextInitializerBean(Servlet.class, beanName, initializer, beanFactory, source);
} else if (initializer instanceof FilterRegistrationBean) {
Filter source = ((FilterRegistrationBean<?>) initializer).getFilter();
addServletContextInitializerBean(Filter.class, beanName, initializer, beanFactory, source);
} else if (initializer instanceof DelegatingFilterProxyRegistrationBean) {
String source = ((DelegatingFilterProxyRegistrationBean) initializer).getTargetBeanName();
addServletContextInitializerBean(Filter.class, beanName, initializer, beanFactory, source);
} else if (initializer instanceof ServletListenerRegistrationBean) {
EventListener source = ((ServletListenerRegistrationBean<?>) initializer).getListener();
addServletContextInitializerBean(EventListener.class, beanName, initializer, beanFactory, source);
} else {
addServletContextInitializerBean(ServletContextInitializer.class, beanName, initializer, beanFactory, initializer);
}
}
use of jakarta.servlet.Servlet in project spring-boot by spring-projects.
the class DispatcherServletsMappingDescriptionProvider method determineDispatcherServlets.
private Map<String, DispatcherServlet> determineDispatcherServlets(WebApplicationContext context) {
Map<String, DispatcherServlet> dispatcherServlets = new LinkedHashMap<>();
context.getBeansOfType(ServletRegistrationBean.class).values().forEach((registration) -> {
Servlet servlet = registration.getServlet();
if (servlet instanceof DispatcherServlet && !dispatcherServlets.containsValue(servlet)) {
dispatcherServlets.put(registration.getServletName(), (DispatcherServlet) servlet);
}
});
context.getBeansOfType(DispatcherServlet.class).forEach((name, dispatcherServlet) -> {
if (!dispatcherServlets.containsValue(dispatcherServlet)) {
dispatcherServlets.put(name, dispatcherServlet);
}
});
return dispatcherServlets;
}
Aggregations