package com.juick.server.tests; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.TextWebSocketHandler; import java.io.IOException; import java.util.concurrent.CountDownLatch; class WebsocketClientHandler extends TextWebSocketHandler { private final CountDownLatch latch; private WebSocketSession session; private String lastMessage; public WebsocketClientHandler(CountDownLatch latch) { this.latch = latch; } @Override public void afterConnectionEstablished(WebSocketSession session) throws IOException { this.session = session; session.sendMessage(new TextMessage("PING")); } @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) { this.lastMessage = message.getPayload(); latch.countDown(); } public WebSocketSession getSession() { return session; } public String getLastMessage() { return lastMessage; } }