I write a chat on the web socket. I use sockjs.js and stomp.js. The connection is successful, subscriber to the newsletter, too. But when you try to send a message to the backend (for sending to all those who joined the chat), nothing comes to the desired controller, although it writes to the console that it sent the data:
>>> SEND destination:/app/app-dest-prefix/chat content-length:76 {"from":"Lesha","text":"message","timeCreation":"2017-10-12T15:26:29.410Z"} so i join
stompClient = Stomp.over(new SockJS("/ContactBook/app/cbxSoc")); so sabsibre:
stompClient.subscribe('/topic/messages', function (message) { console.log(message); }); so i'm sending a message:
stompClient.send("/app-dest-prefix/chat", {}, JSON.stringify({'from':'Lesha', 'text':$scope.chatInput, 'timeCreation':new Date()}) I have such a controller
@Controller public class ChatController { @MessageMapping("/chat") @SendTo("/topic/messages") public Message send(Message message){ String time = new SimpleDateFormat("HH:mm").format(new Date()); message.setTimeCreation(time); return message; } }
such configuration:
@Configuration @EnableWebSocketMessageBroker public class CbxSocketConfig extends AbstractWebSocketMessageBrokerConfigurer{ @Override public void registerStompEndpoints(StompEndpointRegistry ser) { ser.addEndpoint("/cbxSoc").withSockJS(); } @Override public void configureMessageBroker(MessageBrokerRegistry config) { // Prefix for messages FROM client TO server config.setApplicationDestinationPrefixes("/app-dest-prefix"); // Prefix for messages FROM server TO client config.enableSimpleBroker("/events", "/topic", "/queue"); config.setUserDestinationPrefix("/user"); } } Tell me who knows where I was wrong. Thank. It seems that the URL did not indicate the correct one, but judging by the documentation, everything is correct ...
UPD Maybe someone knows how to deny everything at all. What comes from the client (not only on a certain path, which is specified in @MessageMapping ("/ chat"))?
UPD2 Added a handler to catch everyone’s post on the webbox
@Override public void configureClientInboundChannel(ChannelRegistration registration) { registration.setInterceptors(new MyChannelInterceptor()); } public class MyChannelInterceptor extends ChannelInterceptorAdapter { @Override public Message<?> preSend(Message<?> message, MessageChannel channel) { StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message); //StompCommand command = accessor.getStompCommand(); return message; } } When a client sends a message, this handler catches it, but it still does not reach the controller .. 
UPD3 example log mapping
2017-10-22 20:30:19 INFO RequestMappingHandlerMapping:220 - Mapped "{[/client/managers],methods=[GET],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public java.util.List com.miroktell.contactbook.controllers.ClientController.getManagers() 2017-10-22 20:30:19 INFO RequestMappingHandlerMapping:220 - Mapped "{[/client/filter],methods=[POST],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public com.miroktell.contactbook.containers.RowsContainer com.miroktell.contactbook.controllers.ClientController.getClientsByFilter(com.miroktell.contactbook.containers.ClientListFilter) throws java.io.IOException 2017-10-22 20:30:19 INFO RequestMappingHandlerMapping:220 - Mapped "{[/client/getFullClientByPhoneNumber],methods=[GET],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public com.miroktell.contactbook.model.Client com.miroktell.contactbook.controllers.ClientController.getFullClientByPhoneNumber(java.lang.String) 2017-10-22 20:30:19 INFO RequestMappingHandlerMapping:220 - Mapped "{[/client/addNotice],methods=[POST],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public com.miroktell.contactbook.utils.MyMesage com.miroktell.contactbook.controllers.ClientController.addNotice(com.miroktell.contactbook.model.ClientNotice) 2017-10-22 20:30:19 INFO RequestMappingHandlerMapping:220 - Mapped "{[/util/filter/delete/{id}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public com.miroktell.contactbook.utils.MyMesage com.miroktell.contactbook.controllers.UtilController.deleteFilter(int) 2017-10-22 20:30:19 INFO SimpleUrlHandlerMapping:315 - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler] 2017-10-22 20:30:19 INFO RequestMappingHandlerAdapter:523 - Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sun Oct 22 20:30:18 EEST 2017]; parent: Root WebApplicationContext