Skip to content

Commit

Permalink
Log invalid messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul2708 committed Dec 5, 2020
1 parent c00d749 commit 1b9d4fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ public void configureAndStart() {
roles(UserRole.TEACHER));

// Websocket endpoints
Logger logger = LoggerFactory.getLogger("WS-Listener");

List<MessageListener> listeners = List.of(
new LoginMessageListener(userRegistry, broadcaster),
new PatchMessageListener(userRegistry, broadcaster),
new CursorMessageListener(userRegistry),
new CodeRequestMessageListener(userRegistry)
);
MessageProcessing messageProcessing = new MessageProcessing(listeners);

Logger logger = LoggerFactory.getLogger("WS-Listener");
MessageProcessing messageProcessing = new MessageProcessing(listeners, logger);

EventListener connectListener = new ConnectListener();
EventListener closeListener = new CloseListener(userRegistry, broadcaster, logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import io.javalin.websocket.WsMessageContext;
import io.javalin.websocket.WsMessageHandler;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

import java.util.List;

public class MessageProcessing implements WsMessageHandler {

private final List<MessageListener> listeners;
private final Logger logger;

public MessageProcessing(List<MessageListener> listeners) {
public MessageProcessing(List<MessageListener> listeners, Logger logger) {
this.listeners = listeners;
this.logger = logger;
}

@Override
Expand All @@ -28,12 +31,10 @@ public void handleMessage(@NotNull WsMessageContext ctx) {
listener.handle(ctx, message.getAsJsonObject("data"));
}
}
} else {
System.out.println("Message missing");
}
} catch (JsonParseException e) {
// Invalid message
System.out.println("Invalid message");
logger.error("Received invalid message.");
}
}
}

0 comments on commit 1b9d4fe

Please sign in to comment.