spring-websocket

Spring 4 WebSockect over STOMP Authentication

爷,独闯天下 提交于 2019-12-05 21:07:51
I'm developing a multiplayer game based on Spring 4 WebSocket. my server is stateless so in order to identify players i use tokens. after struggling for sometime with how to identify players over WebSockets i came up with this solution: on the client player registers like this: var sockjs = new SockJS("http://mygame/games/", null, {server : token}); this adds the token to the url, I have set up a filter using spring security: String requestURI = request.getRequestURI(); String[] parts = StringUtils.split(requestURI, "/"); if (parts.length == 4) { String token = parts[1]; List<GrantedAuthority>

Spring websocket getting 404 not found

家住魔仙堡 提交于 2019-12-05 20:54:11
问题 I am trying to create an websocket endpoint with spring. But Whenever I am trying to connect from the client end, I get 404. I also have an Java implementation with @ServerEndpoint(value = "/websocket") which works good. Below is the code of my spring implementation which is not working. What am I doing wrong here? package com.tlab.endpoint; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.socket

Why is ServletServerContainerFactoryBean casuing problems when testing?

▼魔方 西西 提交于 2019-12-05 19:45:31
I'm doing a web application using Spring Boot. This application is also configured to use WebSocket and handle (pretty basic) incoming messages. The application seems to work fine. The problem is when I'm doing some testing. The relevant parts are these: //WebManagerApplication.java @Configuration @ComponentScan @EnableAutoConfiguration public class WebManagerApplication { public static void main(String[] args) { SpringApplication.run(WebManagerApplication.class, args); } } // //WebSocketConfig.java @Configuration @EnableWebSocket public class WebSocketConfig implements WebSocketConfigurer{

WebSocketConfigurer and @Scheduled() are not work well in an application

China☆狼群 提交于 2019-12-05 16:43:28
I can either use websocket that configure with WebSocketConfigurer or use @Scheduled() to schedule task without any problem. However, java does not compile when i use both of them. @Scheduled() annotation may crash with org.springframework.web.socket.config.annotation.WebSocketConfigurationSupport$NoOpScheduler.scheduleAtFixedRate() java.lang.IllegalStateException: Unexpected use of scheduler. at org.springframework.web.socket.config.annotation.WebSocketConfigurationSupport$NoOpScheduler.scheduleAtFixedRate(WebSocketConfigurationSupport.java:123) at org.springframework.scheduling.config

Spring 4 websocket + stomp + rabbitmq and clustering

穿精又带淫゛_ 提交于 2019-12-05 14:21:54
I am going through Spring 4 websocket + stomp + rabbitmq(RabbitMQ-Web-Stomp plugin) architecture and I have a question about clustering. As per my understanding here Spring MVC act as a gateway for STOMP requests. If we cluster the application instance with spring web socket configuration will it create any confusion? For an example will it open multiple listeners and how will in such a case this architecture behave? In this scenario, you would need to use load balancing and a message broker. I used HAProxy to load balance 4 Spring MVC instances (websocket) running on 4 tomcat servers. Also

Spring security websocket and HTTP authentication/authorization

假如想象 提交于 2019-12-05 06:55:47
Summary I would like to implement websocket communication over STOMP. Authenticate The user in the time of the first (HTTP request) websocket handshake and use this Principal for authorizing websocket messages later. Problem The system authenticates the client at the first time when it tries to connect to the websocket endpoint (the time of HTTP handshake). My spring security filter and Authentication provider does its job and authenticates the client properly. After this I can check that the client gets the Roles and my Authentication object is stored in the SecurityContext as well. (At this

Send Message to all clients via SimpMessagingTemplate in ServletContextListener

ぐ巨炮叔叔 提交于 2019-12-05 04:40:18
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 { @Override public void configureMessageBroker(MessageBrokerRegistry config) { config.enableSimpleBroker("

Spring Websockets STOMP - get client IP address

六月ゝ 毕业季﹏ 提交于 2019-12-05 02:42:29
问题 Is there any way to obtain STOMP client IP address? I am intercepting inbound channel but I cannot see any way to check the ip address. Any help appreciated. 回答1: You could set the client IP as a WebSocket session attribute during the handshake with a HandshakeInterceptor : public class IpHandshakeInterceptor implements HandshakeInterceptor { public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes)

Spring Boot WebSocket with embedded ActiveMQ Broker

爱⌒轻易说出口 提交于 2019-12-04 20:58:43
I tried to change an web application from simple broker to an embedded ActiveMq Broker with stomp using Spring boot 1.5.4 but always getting an error on start up Caused by: java.lang.IllegalArgumentException: No handlers at org.springframework.util.Assert.isTrue(Assert.java:92) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.start(SubProtocolWebSocketHandler.java:244) ~[spring-websocket-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java

Spring boot websocket 1.2.1.RELEASE - IllegalArgumentException in bean 'subProtocolWebSocketHandler' : No handlers

百般思念 提交于 2019-12-04 18:21:32
So I'm looking to upgrade my projects from spring boot 1.1.9.RELEASE to 1.2.1.RELEASE. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> <version>${spring.boot.version}</version> </dependency> However, on startup, I gained: Exception in thread "Thread-0" org.springframework.context.ApplicationContextException: Failed to start bean 'subProtocolWebSocketHandler'; nested exception is java.lang.IllegalArgumentException: No handlers at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java