use of cn.taketoday.web.servlet.DispatcherServlet in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerIntegrationTests method classpathLocationWithEncodedPath.
@ParameterizedTest
@MethodSource("argumentSource")
void classpathLocationWithEncodedPath(boolean usePathPatterns, String pathPrefix) throws Exception {
MockHttpServletRequest request = initRequest(pathPrefix + "/test/foo with spaces.css");
MockHttpServletResponse response = new MockHttpServletResponse();
DispatcherServlet servlet = initDispatcherServlet(WebConfig.class);
servlet.service(request, response);
String description = "usePathPattern=" + usePathPatterns + ", prefix=" + pathPrefix;
assertThat(response.getStatus()).as(description).isEqualTo(200);
assertThat(response.getContentType()).as(description).isEqualTo("text/css");
assertThat(response.getContentAsString()).as(description).isEqualTo("h1 { color:red; }");
}
use of cn.taketoday.web.servlet.DispatcherServlet in project today-framework by TAKETODAY.
the class DispatcherServletInitializer method getServlet.
@Override
public DispatcherServlet getServlet() {
DispatcherServlet dispatcherServlet = super.getServlet();
if (dispatcherServlet == null && isAutoCreateDispatcher()) {
WebServletApplicationContext context = getApplicationContext();
BeanDefinitionRegistry registry = context.unwrapFactory(BeanDefinitionRegistry.class);
if (!registry.containsBeanDefinition(DispatcherServlet.class)) {
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(context, registry);
reader.setEnableConditionEvaluation(false);
reader.registerBean(DISPATCHER_SERVLET, DispatcherServlet.class);
}
dispatcherServlet = context.getBean(DispatcherServlet.class);
setServlet(dispatcherServlet);
}
return dispatcherServlet;
}
use of cn.taketoday.web.servlet.DispatcherServlet in project today-framework by TAKETODAY.
the class ResponseEntityExceptionHandlerTests method controllerAdviceWithinDispatcherServlet.
@Test
public void controllerAdviceWithinDispatcherServlet() throws Exception {
StaticWebApplicationContext ctx = new StaticWebApplicationContext();
ctx.registerSingleton("controller", ExceptionThrowingController.class);
ctx.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class);
ctx.registerSingleton("parameterResolvingRegistry", ParameterResolvingRegistry.class);
ctx.registerSingleton("returnValueHandlerManager", ReturnValueHandlerManager.class);
ctx.refresh();
DispatcherServlet servlet = new DispatcherServlet(ctx);
servlet.init(new MockServletConfig());
servlet.service(this.servletRequest, this.servletResponse);
assertThat(this.servletResponse.getStatus()).isEqualTo(400);
assertThat(this.servletResponse.getContentAsString()).isEqualTo("error content");
assertThat(this.servletResponse.getHeader("someHeader")).isEqualTo("someHeaderValue");
}
use of cn.taketoday.web.servlet.DispatcherServlet in project today-framework by TAKETODAY.
the class ResponseEntityExceptionHandlerTests method controllerAdviceWithNestedExceptionWithinDispatcherServlet.
@Test
public void controllerAdviceWithNestedExceptionWithinDispatcherServlet() throws Exception {
StaticWebApplicationContext ctx = new StaticWebApplicationContext();
ctx.registerSingleton("controller", NestedExceptionThrowingController.class);
ctx.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class);
ctx.registerSingleton("parameterResolvingRegistry", ParameterResolvingRegistry.class);
ctx.registerSingleton("returnValueHandlerManager", ReturnValueHandlerManager.class);
ctx.refresh();
DispatcherServlet servlet = new DispatcherServlet(ctx);
servlet.init(new MockServletConfig());
try {
servlet.service(this.servletRequest, this.servletResponse);
} catch (ServletException ex) {
boolean condition1 = ex.getCause() instanceof IllegalStateException;
assertThat(condition1).isTrue();
boolean condition = ex.getCause().getCause() instanceof RequestBindingException;
assertThat(condition).isTrue();
}
}
use of cn.taketoday.web.servlet.DispatcherServlet in project today-framework by TAKETODAY.
the class ResourceHttpRequestHandlerIntegrationTests method cssFile.
@ParameterizedTest
@MethodSource("argumentSource")
void cssFile(boolean usePathPatterns, String pathPrefix) throws Exception {
MockHttpServletRequest request = initRequest(pathPrefix + "/test/foo.css");
MockHttpServletResponse response = new MockHttpServletResponse();
DispatcherServlet servlet = initDispatcherServlet(WebConfig.class);
servlet.service(request, response);
String description = "usePathPattern=" + usePathPatterns + ", prefix=" + pathPrefix;
assertThat(response.getStatus()).as(description).isEqualTo(200);
assertThat(response.getContentType()).as(description).isEqualTo("text/css");
assertThat(response.getContentAsString()).as(description).isEqualTo("h1 { color:red; }");
}
Aggregations