WebSocketHandler { public void add(String path, ChannelHandler<?, ?> handler) { ChannelHandler<?, ?> previous = handlers.putIfAbsent(path, handler); if (previous != null) throw new Error(format("found duplicate channel listener, path={}, previousListener={}", path, previous.listener.getClass().getCanonicalName())); } WebSocketHandler(LogManager logManager, SessionManager sessionManager, RateControl rateControl); boolean checkWebSocket(HTTPMethod method, HeaderMap headers); void handle(HttpServerExchange exchange, RequestImpl request, ActionLog actionLog); void shutdown(); void add(String path, ChannelHandler<?, ?> handler); final WebSocketContextImpl context; }
@Test void add() { ChannelHandler<?, ?> handler = new ChannelHandler<>(TestWebSocketMessage.class, TestWebSocketMessage.class, new TestChannelListener()); this.handler.add("/ws", handler); assertThatThrownBy(() -> this.handler.add("/ws", handler)) .isInstanceOf(Error.class) .hasMessageContaining("found duplicate channel listener"); }