connectionlostexception:连接已关闭

lrpiutwd  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(272)

在尝试对stompclient websocket应用程序运行测试时,收到以下错误消息:

java.util.concurrent.ExecutionException: org.springframework.messaging.simp.stomp.ConnectionLostException: Connection closed

虽然通过react在web上进行连接时,效果很好。
下面是我的代码:

@Test
public void getGreeting() throws Exception {

    WebSocketContainer container = ContainerProvider.getWebSocketContainer();
    container.setDefaultMaxTextMessageBufferSize(MAX_TEXT_MESSAGE_BUFFER_SIZE);
    StandardWebSocketClient standardWebSocketClient=new StandardWebSocketClient(container);
    Transport webSocketTransport = new WebSocketTransport(standardWebSocketClient);
    List<Transport> transports = new ArrayList<Transport>();
    transports.add(webSocketTransport);
    SockJsClient sockJsClient = new SockJsClient(transports);
    WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
    stompClient.setReceiptTimeLimit(3000);
    stompClient.setDefaultHeartbeat(new long[] { 10000l, 10000l });
    ThreadPoolTaskScheduler task = new ThreadPoolTaskScheduler();
    task.initialize();
    stompClient.setTaskScheduler(task);
    stompClient.setInboundMessageSizeLimit(Integer.MAX_VALUE);
    stompClient.connect(getWsPath(), new MySimpleStompFrameHandler("/test", "Welcome Home"))
            .get(10, SECONDS);
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题