Tag: spring websocket

websocket会话示例不集群.. spring-session-1.2.2

我正在测试spring会话websocket样本的集群。 我按照文档中的描述运行示例: http : //docs.spring.io/spring-session/docs/current/reference/html5/guides/websocket.html 。 代码来自: https : //github.com/spring-projects/spring-session/archive/1.2.2.RELEASE.zip 。 如果我在一个Tomcat服务器上运行应用程序,则所有工作都按预期工作。 但如果我在两台服务器上运行两个应用程序,则无效。 我在8080和8090的两个Tomcat服务器中的每一个上启动应用程序并登录到每个服务器。 8080按预期出现。 8090按预期出现并列出8080的用户名。但8090的用户名永远不会添加到8080的列表中。 如果我刷新8090的网页,则用户将从列表中删除,8090的用户将被添加到8080的列表中。此循环将继续使用这两个应用程序。 看起来春季会议正在分享会话信息。 我在Redis中看到两个登录条目。 我是否希望此示例在多个服务器上运行? 提前致谢。

Spring websocket示例 – 错误 – 您是否在支持J SR-356的Servlet容器中运行?

我试图在@ https://spring.io/guides/gs/messaging-stomp-websocket上运行Spring 4示例。 当我尝试连接到套接字时,它会抛出exception。 根据示例,您需要tomcat 7.0.50并且我检查了具有正确版本的tomcat的可执行jar。 任何指针都会有所帮助。 java.lang.IllegalArgumentException: No ‘javax.websocket.server.ServerContainer’ ServletContext attribute. Are you running in a Servlet container that supports JSR-356?

适用于多个用户的Spring websocket安全性

我想在spring应用程序中使用websocket来处理联系请求。 我已经为用户设置了登录页面,我使用了spring security。 我的问题如下:如何安全地向两个不同的用户发送Web套接字消息。 我知道我可以使用@SendTo()向每个订阅某个主题的用户广播消息,并且只能通过类似的方式向一个用户广播消息 messagingTemplate .convertAndSendToUser(principal.getName(), “/queue/requests”, request); 因为他的用户名存储在本金中。 我的问题是如何处理我们必须从请求中定位2个用户并使其安全,以便您无法在未经授权的情况下从客户端收听任何渠道。 理想情况下,我正在寻找类似的东西 messagingTemplate .convertAndSendToUser(request.getFromUser(), “/queue/requests”, request) messagingTemplate .convertAndSendToUser(request.getToUser(), “/queue/requests”, request)

如何结合Spring Security和js sockjs-client

我想通过sockjs-client创建一个Spring Server和一个Broswer javascript客户端连接。 应通过Spring Security确保连接。 我有以下两难困境: Spring Security似乎假设websocket握手是通过经过身份validation的http会话发生的(例如,JSESSIONID cookie设置,登录发生)。 然而,sockjs-client似乎对开发人员施加限制,即必须使用未经过身份validation的http会话(请参阅https://github.com/sockjs/sockjs-client/issues/196 ),以任何方式强制执行此操作。 我对这种困境的评价是否正确,是否有任何明显的解决方案来实现带有websockets的弹簧服务器的安全性,以便sockjs-client可以安全地连接? 如果用于创建经过身份validation的HttpSession,建议的在GET / info请求中传递任何身份validation令牌的解决方案看起来像是无法绕过SockJS安全限制。 这似乎是几个人问题的基础,例如: 在使用sockjs和stomp的/ info请求期间没有cookie Spring Websocket + SockJS的身份validation模型,并按用户发送消息 如何从Spring 4 stomp websocket方法获取/设置主体和会话属性 https://stackoverflow.com/questions/33156282 Spring Websockets @SendToUser没有登录? Spring Session Basic Auth令牌作为Spring-Websocket中的查询参数传递 Spring安全websocket和HTTP身份validation/授权 Spring Session,Websocket Security集成流程 Spring安全/ Spring会话/ Web套接字 Spring Boot,Websockets无法从Session获取用户(即java.security.Principal) Spring 4 WebSockect over STOMP Authentication http://sunitkatkar.blogspot.de/2014/01/spring-4-websockets-with-sockjs-stomp.html 我看到3种可选方式: 不要使用SockJs,而只使用本机Websockets 通过query-param Token在经过身份validation的Http Session上使用SockJS,并牺牲一些安全性 […]

未找到404的Spring websocket

我正在尝试用spring创建一个websocket端点。 但每当我尝试从客户端连接时,我得到404.我也有一个Java实现 @ServerEndpoint(value = “/websocket”) 这很好用。 下面是我的spring实现的代码,它不起作用。 我在这做错了什么? package com.tlab.endpoint; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.config.annotation.EnableWebSocket; import org.springframework.web.socket.config.annotation.WebSocketConfigurer; import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; @Configuration @EnableWebSocket public class WebSocketConfig implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(socketHandler(),”/socket”);; } @Bean public WebSocketHandler socketHandler() { return new SocketHandler(); } } 下面是处理程序 package com.tlab.endpoint; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; […]

通过ServletContextListener中的SimpMessagingTemplate向所有客户端发送消息

我正在使用Spring框架,我有一个工作的websocket控制器,如下所示: @Controller public class GreetingController { @MessageMapping(“/hello”) @SendTo(“/topic/greetings”) public Greeting greeting(HelloMessage message) throws InterruptedException { return new Greeting(“Hello, ” + message.getName() + “!”); } } 我也有这个配置: @Configuration @EnableWebSocketMessageBroker public class HelloWebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void configureMessageBroker(MessageBrokerRegistry config) { config.enableSimpleBroker(“/topic”); config.setApplicationDestinationPrefixes(“/app”); } public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint(“/hello”).withSockJS(); } } 那部分效果很好! 我可以使用Stomp.js在两个或多个浏览器之间成功发送和接收消息。 这是不起作用的部分。 我已经实现了一个ServletContextListener […]

从Spring Websocket程序发送STOMP错误

我有一个Spring Websocket Stomp应用程序,它接受SUBSCRIBE请求。 在应用程序中,我有SUBSCRIBE的处理程序,即 @Component public class SubscribeStompEventHandler implements ApplicationListener { @Override public void onApplicationEvent(SessionSubscribeEvent event) {} } 我用来validation订阅。 我会检查onApplicationEvent中的某些内容,并从此函数将STOMP ERROR消息发送回客户端。 我发现这个配方如何使用Spring WebSocket向STOMP客户端发送ERROR消息? 但我需要了解如何获得outboundChannel。 我还尝试了以下代码: public void sendStompError(SimpMessagingTemplate simpMessagingTemplate, String sessionId, String topic, String errorMessage) { StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.ERROR); headerAccessor.setMessage(errorMessage); headerAccessor.setSessionId(sessionId); headerAccessor.setLeaveMutable(true); simpMessagingTemplate.convertAndSendToUser(sessionId, topic, new byte[0], headerAccessor.getMessageHeaders()); } 我尝试将主题作为一些subsciption主题和/ queue / error主题。 但是我没有看到消息传播到客户端。 在客户端,我使用: […]

Spring 4 Websocket – 什么都没发生

我正在学习spring 4 websocket,如果有人能指导我一步一步地学习spring 4 websocket,我会非常感激,或者可以建议一些书,我可以在这个主题上找到一步一步的实用方法。 但在此之前需要一点帮助,我想尝试使用tomcat 8在eclipse上执行这个片段。 的index.html Hello WebSocket var stompClient = null; function setConnected(connected) { document.getElementById(‘connect’).disabled = connected; document.getElementById(‘disconnect’).disabled = !connected; document.getElementById(‘conversationDiv’).style.visibility = connected ? ‘visible’ : ‘hidden’; document.getElementById(‘response’).innerHTML = ”; } function connect() { var socket = new SockJS(“”); stompClient = Stomp.over(socket); stompClient.connect(”, ”, function(frame) { setConnected(true); console.log(‘Connected: ‘ + frame); stompClient.subscribe(“”, […]

Java websocket客户端无法使用GDAX沙箱环境

我使用Spring WebSocket WebSocketClient连接GDAX服务器。 它在Live环境中运行良好,但相同的代码不适用于沙箱环境。 这是我连接到服务器的代码: public class Test { public static void main(String[] args) throws InterruptedException { String socketURL = “wss://ws-feed.gdax.com”; //Live URL //String socketURL = “wss://ws-feed-public.sandbox.gdax.com”; //sanbox URL, code will not work if you use sandvox URL WebSocketClient client = new StandardWebSocketClient(); WebSocketConnectionManager connectionManager = new WebSocketConnectionManager(client, new MySocketHandler(), socketURL); connectionManager.start(); Thread.sleep(1000000); } } […]

Spring Boot,Websockets无法从Session获取用户(即java.security.Principal)

使用Spring Boot 1.2.1.RELEASE和Spring Websockets 。 有一个部署运行时问题,当运行嵌入式Jetty 9 ,除了localhost之外的其他地方应用程序部署时,我无法成功伪造用户( java.security.Principal )。 我咨过过 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-authentication http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-server-runtime-configuration 下面的配置(我相信)已经“升级”了一个请求 @Configuration @EnableWebSocketMessageBroker @EnableScheduling public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void configureMessageBroker(MessageBrokerRegistry registry) { // see http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-handle-broker-relay // requires an external broker like AMQP or RabbitMQ //registry.enableStompBrokerRelay(“/queue/”, “/topic/”); // XXX This might wind up being the impl we actually deploy; […]