I'm giving the Spring's STOMP+WebSocket implementation a try and I wonder if it's possible to call a service (at server) which takes in more than one parameter?
I get it that I can encapsulate a number of parameters into one class and then define a service taking in an object of that class. But that's not what I'm looking for. I want to be able to call one service through REST and STOMP at the same time. And since REST services are all about multiple parameter methods, I wonder how can I call them through STOMP!?
@RequestParam
is for query parameters and they don't make much sense when the client sends data to the server as opposed to a query. Both REST and STOMP allow you to use headers for meta information.
The equivalent of @PathVariable
is @DestinationVariable
and used the same way.
The equivalent of @RequestBody
is @Payload
, but Spring assumes that a method parameter without an annotation is the payload, so it's not really needed.
Example:
@RequestMapping("/foo/bar/{id}")
@ResponseBody
@MessageMapping("/foo/bar/{id}")
@SendTo("/baz")
public Answer method(
@PathVariable @DestinationVariable int id,
@RequestBody Message message,
@RequestHeader("foo") @Header("foo") String foo) {