spring-websocket

How to get/set the principal and session attributes from Spring 4 stomp websocket methods

二次信任 提交于 2019-12-03 07:14:20
问题 I'm doing experiments with Spring 4 websockets and stomp, and I have a hard time figuring out how to get/set the current user and other session attributes in a message handling method annotated with @MessageMapping . The documentation says that the message handling methods can take a Principal as argument, and I found that the principal is retrieved by Spring by calling getUserPrincipal() on the native socket session, and then associated with the socket session, but I haven't found any way to

Webflux websocketclient, How to send multiple requests in same session[design client library]

折月煮酒 提交于 2019-12-03 07:09:58
TL;DR; We are trying to design a WebSocket server using spring webflux WebSocket implementation. The server has usual HTTP server operations e.g. create/fetch/update/fetchall . Using WebSockets we were trying to expose one endpoint so the clients could leverage a single connection for all sort of operations, given WebSockets are meant for this purpose. Is it a right design with webflux and WebSockets? Long Version We are starting a project which is going to use reactive web sockets from spring-webflux . We need to build a reactive client library which can be used by consumers to connect to the

How to send ERROR message to STOMP clients with Spring WebSocket?

孤者浪人 提交于 2019-12-03 05:44:42
I am using Spring's STOMP over WebSocket implementation with a full-featured ActiveMQ broker. When users SUBSCRIBE to a topic, there is some permissions logic that they must pass through before being successfully subscribed. I am using a ChannelInterceptor to apply the permissions logic, as configured below: WebSocketConfig.java: @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/stomp") .setAllowedOrigins("*") .withSockJS(); }

Spring Stomp @SendToUser with unauthenticated user not working

六眼飞鱼酱① 提交于 2019-12-03 04:05:43
I'm trying to respond to an unauthenticated user using @SendToUser . Spring 4.1.1 I'm using a newly created Spring Boot application and the only config I have is: @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/stomp").withSockJS(); } @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/topic"); registry.setApplicationDestinationPrefixes("/app"); registry

Spring: send message to websocket clients

余生颓废 提交于 2019-12-03 03:32:25
I'm building a webchat with Spring Boot, RabbitMQ and WebSocket as POC, but I'm stucked a the last point: WebSockets I want my ws clients to connect to a specific endpoint, like /room/{id} and when a new message arrives, I want the server to send the response to clients, but I searched for something similar and didn't found. Currently, when the message arrives, I process it with RabbitMQ, like container.setMessageListener(new MessageListenerAdapter(){ @Override public void onMessage(org.springframework.amqp.core.Message message, Channel channel) throws Exception { log.info(message); log.info(

WebSocketStompClient won't connect to SockJS endpoint

前提是你 提交于 2019-12-03 02:24:10
I'm playing around with the new (as of version 4.2) java STOMP client support. My starting point is the getting started guide ( Using WebSocket to build an interactive web application ). The following endpoint is provided in the example: @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/hello").withSockJS(); } I can successfully connect using the browser client. When attempting to connect to this endpoint using the java stomp client using the following: WebSocketClient transport = new StandardWebSocketClient(); WebSocketStompClient

How to call @SendTo from Normal Request Call i.e @RequestMapping

╄→гoц情女王★ 提交于 2019-12-03 01:02:43
I have implemented Web Socket using Spring MVC and it is working fine for me i.e work from one browser to another browser which is open for those socket using this code. @MessageMapping("/hello") @SendTo("/topic/greetings") public HelloMessage greeting(HelloMessage message) throws Exception { Thread.sleep(3000); // simulated delay return message; } Can any one help me for who to call @SendTo("/topic/greetings") from normal api controller.I have try using this but it is not working for me @RequestMapping(value = "/sendMessage") @SendTo("/topic/greetings") public HelloMessage sendMessage()

Spring websocket: how convert easily the Message<?>'s payload to POJO in ChannelInterceptorAdapter

夙愿已清 提交于 2019-12-02 22:11:52
问题 I have a Spring App working with websocket I can do the connection and send messages etc. The @Controller is: @MessageMapping("/ws/notification") @SendTo("/topic/springframework.topic.websocket.reply") public NotificationReply handleNotification(Notification notification) { ... } It works fine. Observe the parameter type, Notification , it is a custom object. Now because audit purposes I have the following: @Component public class MessageChannelInterceptorAdapter extends

How to get/set the principal and session attributes from Spring 4 stomp websocket methods

早过忘川 提交于 2019-12-02 20:48:21
I'm doing experiments with Spring 4 websockets and stomp , and I have a hard time figuring out how to get/set the current user and other session attributes in a message handling method annotated with @MessageMapping . The documentation says that the message handling methods can take a Principal as argument, and I found that the principal is retrieved by Spring by calling getUserPrincipal() on the native socket session, and then associated with the socket session, but I haven't found any way to easily customize this behavior, other than writing a servlet filter and wrap the original request

Connect with iOS and Android clients to SockJS Backend

北慕城南 提交于 2019-12-02 20:06:49
I'm developing WebSocket messaging backend using Spring WebSockets , which uses SockJS + STOMP protocol. The reason why not to use plain WebSockets is because I will need to leverage security integration that SockJS provides in Spring WebSockets and also other neat features from SockJS, such as rooms, subscriptions, etc. I was wondering if this is a good option to use so that mobile (iOS and Android) and Web client apps can easily connect to the backend server and perform messaging. If yes, then what libraries I can use for iOS and Android. On SockJS GitHub page they are also listing available