aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-04-05 11:46:55 +0300
committerGravatar Vitaly Takmazov2017-04-05 11:46:55 +0300
commit21e3db95d7d2eddbbd4f901d8628b129804d13f6 (patch)
tree5c8f4845086c0a2b0c15ef7fe96c38093b2000aa /juick-api/src/main/java/com/juick/api
parent3bfe5d94da692fd4d388c29903f7d50117904950 (diff)
juick-api: fix NPE and try to reconnect telegram bot
Diffstat (limited to 'juick-api/src/main/java/com/juick/api')
-rw-r--r--juick-api/src/main/java/com/juick/api/TGBot.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/juick-api/src/main/java/com/juick/api/TGBot.java b/juick-api/src/main/java/com/juick/api/TGBot.java
index 7456c8e7..d665a197 100644
--- a/juick-api/src/main/java/com/juick/api/TGBot.java
+++ b/juick-api/src/main/java/com/juick/api/TGBot.java
@@ -20,6 +20,7 @@ import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.PingMessage;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
+import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import javax.inject.Inject;
@@ -42,6 +43,8 @@ public class TGBot extends TextWebSocketHandler {
TelegramService telegramService;
@Inject
MessagesService messagesService;
+ @Inject
+ WebSocketConnectionManager connectionManager;
WebSocketSession session;
@@ -76,14 +79,16 @@ public class TGBot extends TextWebSocketHandler {
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
- logger.info("WebSocket disconnected with code {}: {}", status.getCode(), status.getReason());
- this.session = null;
+ logger.info("WebSocket disconnected with code {}: {}, trying to reconnect", status.getCode(), status.getReason());
+ connectionManager.start();
}
@Scheduled(fixedRate = 30000)
public void ping() throws IOException {
- logger.debug("Sending WebSocket ping");
- session.sendMessage(new PingMessage());
+ if (session != null) {
+ logger.debug("Sending WebSocket ping");
+ session.sendMessage(new PingMessage());
+ }
}
@Override