I'm trying to apply a destination variable to a method in my controller that handles incoming messages from WebSocket. Here's what I want to achieve:
@Controller
public class DocumentWebsocketController {
@MessageMapping("/lock-document")
@SendTo("/notify-open-documents/{id}")
public Response response(@DestinationVariable("id") Long id, Message message) {
return new Response(message.getDocumentId());
}
}
The problem is, that the destination variable is applied only to @SendTo
annotation. It causes following stack trace while attempting this endpoint:
12:36:43.044 [clientInboundChannel-7] ERROR org.springframework.web.socket.messaging.WebSocketAnnotationMethodMessageHandler - Unhandled exception
org.springframework.messaging.MessageHandlingException: Missing path template variable 'id' for method parameter type [class java.lang.Long]
at org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver.handleMissingValue(DestinationVariableMethodArgumentResolver.java:70) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.messaging.handler.annotation.support.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:96) ~[spring-messaging-4.2.4.RELEASE.jar:4.2.4.RELEASE]
(...)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_144]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_144]
My question is: is something like I want to achieve possible at all?