V
V
Vitaly2015-08-26 18:47:36
Java
Vitaly, 2015-08-26 18:47:36

How to "map" methods by headers in Spring STOMP messages?

The application uses the STOMP protocol to exchange messages in the Websockets environment.
There is a controller in which methods are "mapped":

@Controller
public class UserController {

    @Autowired
    private UserManager userManager;

    @MessageMapping("/users")
    @SendTo("/queue/users")
    @ResponseBody
    public List<User> list() {
        return userManager.findAll();
    }

    @MessageMapping("/users")
    @SendTo("/queue/users")
    @ResponseBody
    public User user(@Payload MessagePayload messagePayload) {
        int idUser = Integer.parseInt(messagePayload.getRequestValue("id_user"));
        User user = userManager.findUserById(idUser);
        if (user == null) {
            throw new UserNotFoundException(idUser);
        }
        return user;
    }

}

Messages have a custom "command" header. How can I additionally "map" methods depending on the content of "command'.
For example:
@MessageMapping("/users")
@Header("command" = "GETLOCALUSER")
@SendTo("/queue/users")
@ResponseBody
public List<User> list() {
     return userManager.findAll();
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question