我试图测试websocket而不使用socketjs库,我也不想添加任何stomp连接.
我正在关注stackoverflow问题的例子: 带有Sockjs和Spring 4的WebSocket,但是没有Stomp
所以没有stomp服务器,我已经成功通过socketjs库与url连接:ws:// localhost:8080/greeting/741/0tb5jpyi/websocket
现在我想删除socketjs库以允许原始websocket连接(可能是android,ios等设备......)
当我删除参数:.withSockJS()时,我无法通过websocket连接.
我尝试了以下网址,但它们不起作用:
ws://localhost:8080/greeting/394/0d7xi9e1/websocket not worked
ws://localhost:8080/greeting/websocket not worked
ws://localhost:8080/greeting/ not worked
Run Code Online (Sandbox Code Playgroud)
我应该用哪个URL连接?
我在使用带有@ServerEndPoint注释类的spring时遇到了麻烦
我正在使用Springboot 1.2.3,我正试图弄清楚如何拥有一个端点的单个实例
@SpringBootApplication
@EnableJpaRepositories
@EnableWebSocket
public class ApplicationServer {
public static void main(String[] args) {
SpringApplication.run(ApplicationServer.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
弹簧配置:
@ConditionalOnWebApplication
@Configuration
public class WebSocketConfigurator {
@Bean
public ServerEndPoint serverEndpoint() {
return new ServerEndPoint();
}
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
Run Code Online (Sandbox Code Playgroud)
WebSocket端点:
@ServerEndpoint(value = "/", decoders = MessageDecoder.class,
encoders = MessageEncoder.class, configurator = SpringConfigurator.class)
public class ServerEndPoint {
private static final Logger LOG = LoggerFactory.getLogger(ServerEndPoint.class);
public static final Set<CommunicationObserver> OBSERVERS = Sets.newConcurrentHashSet();
@OnMessage
public void …Run Code Online (Sandbox Code Playgroud) 在这个伟大的答案/sf/answers/1901339051/有一个例子,说明如何使用没有STOMP子协议的原始Spring4 WebSockets(并且可能没有SockJS).
现在我的问题是:我如何向所有客户广播?我期望看到一个API,我可以使用类似于纯JSR 356 websockets API的API:session.getBasicRemote().sendText(messJson);
我是否需要自己保留所有WebSocketSession对象,然后调用sendMessage()每个对象?
有没有办法使用Spring提供的工具来连接webSocket而不使用SockJS和STOMP?我需要实现专有的webSocket协议,所以我现在不能使用任何一个.
我已经从以下答案中实施/破解了解决方案,但它需要重新实现我认为我不应该担心的事情.
我想我的问题归结为:有没有办法让我使用2.(下面)的优点,特别是MessageBroker,而不使用STOMP?
一点背景:
我需要做以下事情:
到目前为止我尝试过的是:
即(伪代码)
@ServerEndpoint("/trade/{id}")
public String handleMessage(@PathParam(id) String id, webSocketSession session){
if(id.equalsIgnoreCase("foo"){
for(Session s: session.getOpenSessions(){
//do things}
} else if(id.equalsIgnoreCase("bar")){
//do other things
}
}
}
Run Code Online (Sandbox Code Playgroud)
@MessageMapping("/trade")和使用Spring websocket实现@SendTo("/queue/position-updates").这要求我至少使用STOMP.这意味着要破坏流程中的其他应用程序,这是我目前无法做到的.此外,还有我需要实施的专有协议的问题.即(伪代码)
@MessageMapping("/trade/{id}")
@SendTo("/trades/all")
public Greeting greeting(String message){
//do things, return message
}
Run Code Online (Sandbox Code Playgroud)
{id}从registry.addHandler(WebsocketHandlerPool(), "/trade/{id}")进WebsocketHandlerPool(),所以我有,当我创建每一个人来解析路径WebsocketHandler.理想情况下,我不想这样做.@MessageMapping和,我没有支持(据我所知)@SendTo.即(处理程序的伪代码:)
@Override
public void afterConnectionEstablished(WebSocketSession …Run Code Online (Sandbox Code Playgroud) 我目前正在构建一个使用 Spring 来利用 websocket 支持和安全性的 Web 应用程序。问题是,我不想使用 STOMP。现在已经有大约 4 个版本没有更新了,我不需要它。因此,我按照另一个 Stackoverflow问题的答案,使用 SockJS 但不使用 STOMP 为 Websocket 配置 Spring。
现在我想集成 Spring Security 来进行 websocket 身份验证和授权。不幸的是,该文档必须为 STOMP-websockets 配置 Spring Security。
我非常感谢任何为我的案例配置 Spring Security 的帮助。有人知道这方面的教程或示例吗?我还没有找到。