|
48 | 48 | import org.springframework.http.server.ServerHttpResponse; |
49 | 49 | import org.springframework.http.server.ServletServerHttpResponse; |
50 | 50 | import org.springframework.ui.Model; |
51 | | -import org.springframework.web.bind.annotation.ControllerAdvice; |
52 | | -import org.springframework.web.bind.annotation.ModelAttribute; |
53 | | -import org.springframework.web.bind.annotation.RequestBody; |
54 | | -import org.springframework.web.bind.annotation.RequestParam; |
55 | | -import org.springframework.web.bind.annotation.ResponseBody; |
56 | | -import org.springframework.web.bind.annotation.SessionAttributes; |
| 51 | +import org.springframework.web.bind.annotation.*; |
57 | 52 | import org.springframework.web.context.request.async.AsyncRequestNotUsableException; |
58 | 53 | import org.springframework.web.context.request.async.StandardServletAsyncWebRequest; |
59 | 54 | import org.springframework.web.context.request.async.WebAsyncManager; |
60 | 55 | import org.springframework.web.context.request.async.WebAsyncUtils; |
61 | 56 | import org.springframework.web.context.support.StaticWebApplicationContext; |
62 | 57 | import org.springframework.web.method.HandlerMethod; |
| 58 | +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; |
63 | 59 | import org.springframework.web.method.annotation.ModelMethodProcessor; |
64 | 60 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; |
65 | 61 | import org.springframework.web.method.support.HandlerMethodReturnValueHandler; |
@@ -131,6 +127,32 @@ void cacheControlWithoutSessionAttributes() throws Exception { |
131 | 127 | assertThat(response.getHeader("Cache-Control")).contains("max-age"); |
132 | 128 | } |
133 | 129 |
|
| 130 | + @Test |
| 131 | + void invalidBooleanRequestParamResultsInBadRequest() throws Exception { |
| 132 | + this.handlerAdapter.afterPropertiesSet(); |
| 133 | + |
| 134 | + this.request.setRequestURI("/test"); |
| 135 | + this.request.setParameter("bool", "dummy"); |
| 136 | + |
| 137 | + HandlerMethod handlerMethod = |
| 138 | + handlerMethod(new BooleanParamController(), "test", boolean.class); |
| 139 | + |
| 140 | + assertThatThrownBy(() -> { |
| 141 | + try { |
| 142 | + this.handlerAdapter.handle(this.request, this.response, handlerMethod); |
| 143 | + } |
| 144 | + catch (Exception ex) { |
| 145 | + throw new RuntimeException(ex); |
| 146 | + } |
| 147 | + }) |
| 148 | + .hasCauseInstanceOf(MethodArgumentTypeMismatchException.class); |
| 149 | + |
| 150 | + } |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
134 | 156 | @Test |
135 | 157 | void cacheControlWithSessionAttributes() throws Exception { |
136 | 158 | SessionAttributeController handler = new SessionAttributeController(); |
@@ -410,6 +432,15 @@ public ResponseEntity<?> handle(@RequestParam String q) throws IOException { |
410 | 432 |
|
411 | 433 | } |
412 | 434 |
|
| 435 | + @RestController |
| 436 | + static class BooleanParamController { |
| 437 | + |
| 438 | + @GetMapping("/test") |
| 439 | + void test(@RequestParam boolean bool) { |
| 440 | + } |
| 441 | + } |
| 442 | + |
| 443 | + |
413 | 444 |
|
414 | 445 | @ControllerAdvice |
415 | 446 | private static class ModelAttributeAdvice { |
|
0 commit comments