|
39 | 39 | import org.springframework.messaging.MessageHeaders; |
40 | 40 | import org.springframework.messaging.SubscribableChannel; |
41 | 41 | import org.springframework.messaging.converter.MessageConverter; |
| 42 | +import org.springframework.messaging.handler.HandlerMethod; |
42 | 43 | import org.springframework.messaging.handler.annotation.DestinationVariable; |
43 | 44 | import org.springframework.messaging.handler.annotation.Header; |
44 | 45 | import org.springframework.messaging.handler.annotation.Headers; |
@@ -207,6 +208,20 @@ public void validationError() { |
207 | 208 | assertEquals("handleValidationException", this.testController.method); |
208 | 209 | } |
209 | 210 |
|
| 211 | + @Test |
| 212 | + public void exceptionWithHandlerMethodArg() { |
| 213 | + SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(); |
| 214 | + headers.setSessionId("session1"); |
| 215 | + headers.setSessionAttributes(new ConcurrentHashMap<>()); |
| 216 | + headers.setDestination("/pre/illegalState"); |
| 217 | + Message<?> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build(); |
| 218 | + this.messageHandler.handleMessage(message); |
| 219 | + assertEquals("handleExceptionWithHandlerMethodArg", this.testController.method); |
| 220 | + HandlerMethod handlerMethod = (HandlerMethod) this.testController.arguments.get("handlerMethod"); |
| 221 | + assertNotNull(handlerMethod); |
| 222 | + assertEquals("illegalState", handlerMethod.getMethod().getName()); |
| 223 | + } |
| 224 | + |
210 | 225 | @Test |
211 | 226 | public void simpScope() { |
212 | 227 | Map<String, Object> map = new ConcurrentHashMap<>(); |
@@ -405,11 +420,22 @@ public void payloadValidation(@Validated @Payload String payload) { |
405 | 420 | this.arguments.put("message", payload); |
406 | 421 | } |
407 | 422 |
|
| 423 | + @MessageMapping("/illegalState") |
| 424 | + public void illegalState() { |
| 425 | + throw new IllegalStateException(); |
| 426 | + } |
| 427 | + |
408 | 428 | @MessageExceptionHandler(MethodArgumentNotValidException.class) |
409 | 429 | public void handleValidationException() { |
410 | 430 | this.method = "handleValidationException"; |
411 | 431 | } |
412 | 432 |
|
| 433 | + @MessageExceptionHandler(IllegalStateException.class) |
| 434 | + public void handleExceptionWithHandlerMethodArg(HandlerMethod handlerMethod) { |
| 435 | + this.method = "handleExceptionWithHandlerMethodArg"; |
| 436 | + this.arguments.put("handlerMethod", handlerMethod); |
| 437 | + } |
| 438 | + |
413 | 439 | @MessageMapping("/scope") |
414 | 440 | public void scope() { |
415 | 441 | SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); |
|
0 commit comments