spring-websocket

jpa repository websocket @MessageMapping

时光总嘲笑我的痴心妄想 提交于 2019-12-11 03:56:38
问题 I found out, that spring does not create a transaction for websocket requests that are going to a action annotated with @MessageMapping. Even if i annotate the action as @Transactional nothing happens. I also tried the way with an action that is @RequestMapping annotated. This works as usual. Has someone an idea how i can make this work? How to make an websocket request transactional? 回答1: You shoould show your code, because it really works, unless you have some async internal logic, which

spring-mvc, websockets push integration

此生再无相见时 提交于 2019-12-11 03:55:48
问题 I've followed this link http://spring.io/guides/gs/messaging-stomp-websocket/ and got the app up and running. What I wanted was a little more than that, I wanted to to be able to push the data back to the client without the client having to send any thing. So I've setup a long running task with a listener similar to the below GreetingController implements RunnableListener and the RunnableListener has a method public Greeting greeting(HelloMessage message); The implementation of the method is

How to send websocket message to concrete user?

孤街醉人 提交于 2019-12-11 02:24:55
问题 I have following code on server side: @Autowired private SimpMessagingTemplate simpMessagingTemplate; @MessageMapping("/hello") public void greeting(@Payload HelloMessage message, Principal principal) throws Exception { Thread.sleep(1000); // simulated delay simpMessagingTemplate.convertAndSendToUser(principal.getName(), "/topic/greetings", new Greeting("Ololo")); } client side code: function connect() { var socket = new SockJS('/gs-guide-websocket'); stompClient = Stomp.over(socket);

Missing data from socket

我与影子孤独终老i 提交于 2019-12-10 22:26:51
问题 I am trying to write Java code to receive data from a streaming HTTP connection (I would like to debug a problem I have with running Sockjs XHR-streaming against a spring-websocket server). I use some really simple code to connect: URI uri = // The server Socket socket = new Socket(); socket.connect(new InetSocketAddress(uri.getHost(), uri.getPort())); OutputStream os = socket.getOutputStream(); PrintWriter pw = new PrintWriter(os); int id = new Random().nextInt() % 100000; pw.println("POST

Spring WebSockets XML configuration not providing brokerMessagingTemplate

梦想与她 提交于 2019-12-10 18:35:08
问题 I'm trying to add in WebSockets support using STOMP to a Spring MVC application that is configured using XML. So far this has gone really well, and I've managed to get a WebSockets server listening, and stomp.js can connect to it and send messages and receive responses. What I've not managed to get working yet is the support for the server to send arbitrary messages to the client that aren't responses to one received from the client. That means this is actually just a more complicated version

No cookies during /info request using sockjs and stomp

时光毁灭记忆、已成空白 提交于 2019-12-10 18:02:56
问题 I'm trying to use Spring Security with websockets. As an example I'm using spring-websocket-chat (https://github.com/salmar/spring-websocket-chat) — demo application from talk "Deep dive into websockets". In that application CookieHttpSessionStrategy uses for storing session id, stored during authentication cookie is sending with /info request. Here are code that demonstrates connecting to server via sockjs (this request sends cookies) https://github.com/salmar/spring-websocket-chat/blob

Spring Websocket STOMP: send RECEIPT frames

馋奶兔 提交于 2019-12-10 17:06:49
问题 I have a Websocket-stomp server based on Spring and its SimpleBroker implementation (not utilizing an external broker). I would like to enable STOMP RECEIPT messages. How I could configure my code to send these automatically? 回答1: In Spring Integration test for the STOMP protocol we have this code: //SimpleBrokerMessageHandler doesn't support RECEIPT frame, hence we emulate it this way @Bean public ApplicationListener<SessionSubscribeEvent> webSocketEventListener( final

Why does sockJS add a '/info' to a given websocket url path

 ̄綄美尐妖づ 提交于 2019-12-10 12:59:39
问题 I want to open a websocket port with a "webapp/socket.do" path. When I use SockJS and try to initiate the call by code var socket = new SockJS('/webapp/socket.do'); stompClient = Stomp.over(socket); stompClient.connect({}, ... SockJS will by default add a "/info" to the end of the given path. I want to know why? Can this be changed or prevented? When using this with Spring MVC and have url pattern mappings to DispatcherServlet like < url-pattern >*.do</url-pattern> , this will return a 404

How to add custom headers to STOMP CREATED message in Spring Boot application?

落爺英雄遲暮 提交于 2019-12-10 11:34:57
问题 I'm trying to add custom headers to the STOMP 'CREATED' message, which is received by client at the first connection. Here is the function which connects to the WebSocket using STOMP JavaScript: function connect() { socket = new SockJS('/chat'); stompClient = Stomp.over(socket); stompClient.connect('', '', function(frame) { whoami = frame.headers['user-name']; console.log(frame); stompClient.subscribe('/user/queue/messages', function(message) { console.log("MESSAGE RECEIVED:"); console.log

Send Message to all clients via SimpMessagingTemplate in ServletContextListener

99封情书 提交于 2019-12-10 02:58:39
问题 I'm using the Spring framework and I have a working websocket controller that looks like this: @Controller public class GreetingController { @MessageMapping("/hello") @SendTo("/topic/greetings") public Greeting greeting(HelloMessage message) throws InterruptedException { return new Greeting("Hello, " + message.getName() + "!"); } } I also have this configuration: @Configuration @EnableWebSocketMessageBroker public class HelloWebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {