aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-26 09:10:42 +0300
committerGravatar Vitaly Takmazov2018-04-26 09:10:42 +0300
commit2d8655b5b61cab98f9f53703eb9f8fb8ecb68349 (patch)
tree901e8abc012e527d818074a628986ef17a0ab794 /juick-server/src/main/java
parent16f8d781f48d742a5f888ac1b0ceaaa73e723286 (diff)
ws: no need to handle messages from ws
Diffstat (limited to 'juick-server/src/main/java')
-rw-r--r--juick-server/src/main/java/com/juick/server/WebsocketManager.java34
1 files changed, 5 insertions, 29 deletions
diff --git a/juick-server/src/main/java/com/juick/server/WebsocketManager.java b/juick-server/src/main/java/com/juick/server/WebsocketManager.java
index fdee5065..bcb17bf1 100644
--- a/juick-server/src/main/java/com/juick/server/WebsocketManager.java
+++ b/juick-server/src/main/java/com/juick/server/WebsocketManager.java
@@ -18,7 +18,6 @@
package com.juick.server;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.juick.Message;
import com.juick.User;
import com.juick.server.helpers.AnonymousUser;
import com.juick.server.util.HttpBadRequestException;
@@ -26,7 +25,6 @@ import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.HttpNotFoundException;
import com.juick.service.MessagesService;
import com.juick.service.UserService;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,7 +34,6 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
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.handler.ConcurrentWebSocketSessionDecorator;
import org.springframework.web.socket.handler.TextWebSocketHandler;
@@ -46,6 +43,7 @@ import org.springframework.web.util.UriComponentsBuilder;
import javax.inject.Inject;
import java.io.IOException;
import java.net.URI;
+import java.time.Instant;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -129,7 +127,7 @@ public class WebsocketManager extends TextWebSocketHandler {
}
@Override
- public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
+ public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
synchronized (clients) {
logger.debug("session closed with status {}: {}", status.getCode(), status.getReason());
clients.removeIf(c -> c.session.getId().equals(session.getId()));
@@ -138,28 +136,6 @@ public class WebsocketManager extends TextWebSocketHandler {
}
- @Override
- protected void handleTextMessage(WebSocketSession session, TextMessage message) {
- if (StringUtils.defaultString(message.getPayload()).trim().isEmpty()) {
- return;
- }
- clients.stream().filter(c -> c.session.equals(session)).findFirst().ifPresent( c -> {
- if (c.visitor.getName().equals(serviceUser)) {
- try {
- Message draft = jsonMapper.readValue(message.asBytes(), Message.class);
- if (draft.getUser() != null && (draft.getText() != null || draft.getAttachment() != null)) {
- String attachmentFileName = draft.getAttachment() == null ? "" : draft.getAttachment().getUrl();
- commandsManager.processCommand(draft.getUser(), draft.getText(), URI.create(attachmentFileName));
- }
- } catch (Exception e) {
- throw new HttpBadRequestException();
- }
- } else {
- throw new HttpForbiddenException();
- }
- });
- }
-
@Scheduled(fixedRate = 30000)
public void ping() {
clients.forEach(c -> {
@@ -183,15 +159,15 @@ public class WebsocketManager extends TextWebSocketHandler {
int MID;
boolean allMessages;
boolean allReplies;
- long tsConnected;
- long tsLastData;
+ Instant tsConnected;
+ Instant tsLastData;
boolean legacy;
public SocketSubscribed(WebSocketSession session, String clientName, User visitor, boolean legacy) {
this.session = new ConcurrentWebSocketSessionDecorator(session, 60000, 65536);
this.clientName = clientName;
this.visitor = visitor;
- tsConnected = tsLastData = System.currentTimeMillis();
+ tsConnected = tsLastData = Instant.now();
this.legacy = legacy;
}
}