Having A Service Called With STOMP Which Accepts More Than One Parameter
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!?
Answer
@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}")
ettify?-->@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) {
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM