/** * Map a simple controller to the given URL path (or pattern) in order to * set the response status to the given code without rendering a body. * @since 4.1 */ public void addStatusController(String urlPath, HttpStatus statusCode) { ViewControllerRegistration registration = new ViewControllerRegistration(urlPath); registration.setApplicationContext(this.applicationContext); registration.setStatusCode(statusCode); registration.getViewController().setStatusOnly(true); this.registrations.add(registration); }
/** * Map a simple controller to the given URL path (or pattern) in order to * set the response status to the given code without rendering a body. * @since 4.1 */ public void addStatusController(String urlPath, HttpStatus statusCode) { ViewControllerRegistration registration = new ViewControllerRegistration(urlPath); registration.setApplicationContext(this.applicationContext); registration.setStatusCode(statusCode); registration.getViewController().setStatusOnly(true); this.registrations.add(registration); }
@Test public void statusOnly() throws Exception { this.controller.setStatusCode(HttpStatus.NOT_FOUND); this.controller.setStatusOnly(true); ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response); assertNull(modelAndView); assertEquals(404, this.response.getStatus()); }
/** * Map a simple controller to the given URL path (or pattern) in order to * set the response status to the given code without rendering a body. * @since 4.1 */ public void addStatusController(String urlPath, HttpStatus statusCode) { ViewControllerRegistration registration = new ViewControllerRegistration(urlPath); registration.setApplicationContext(this.applicationContext); registration.setStatusCode(statusCode); registration.getViewController().setStatusOnly(true); this.registrations.add(registration); }