@Test void channelRead() throws Exception { mockChannelHandlerContextChannelId(ctx, "abcedf"); final DssWebSocketHandler handler = new DssWebSocketHandler(); handler.channelRead(ctx, message); final TextWebSocketFrame msg = getDssWebSocketHandlerFieldWithReflection(handler, "message", TextWebSocketFrame.class); assertEquals("Hello", msg.text()); handler.channelRead(ctx, closeMessage); final CloseWebSocketFrame closeMsg = getDssWebSocketHandlerFieldWithReflection(handler, "closeMessage", CloseWebSocketFrame.class); assertEquals("Bye", closeMsg.reasonText()); assertEquals(1000, closeMsg.statusCode()); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof WebSocketFrame) { logger.info("Client Channel : {}", ctx.channel()); if (msg instanceof BinaryWebSocketFrame) { logger.info("BinaryWebSocketFrame Received"); } else if (msg instanceof TextWebSocketFrame) { logger.info("TextWebSocketFrame Received"); message = (TextWebSocketFrame) msg; ctx.channel().writeAndFlush(message.text()); logger.info("Received Message : {}", message.text()); } else if (msg instanceof PingWebSocketFrame) { logger.info("PingWebSocketFrame Received"); } else if (msg instanceof PongWebSocketFrame) { logger.info("PongWebSocketFrame Received"); } else if (msg instanceof CloseWebSocketFrame) { logger.info("CloseWebSocketFrame Received"); closeMessage = (CloseWebSocketFrame) msg; logger.info("ReasonText : {}", closeMessage.reasonText()); logger.info("StatusCode : {}", closeMessage.statusCode()); } else { throw new UnsupportedOperationException("Unsupported WebSocketFrame Type " + msg.getClass().getName()); } } }
DssWebSocketHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof WebSocketFrame) { logger.info("Client Channel : {}", ctx.channel()); if (msg instanceof BinaryWebSocketFrame) { logger.info("BinaryWebSocketFrame Received"); } else if (msg instanceof TextWebSocketFrame) { logger.info("TextWebSocketFrame Received"); message = (TextWebSocketFrame) msg; ctx.channel().writeAndFlush(message.text()); logger.info("Received Message : {}", message.text()); } else if (msg instanceof PingWebSocketFrame) { logger.info("PingWebSocketFrame Received"); } else if (msg instanceof PongWebSocketFrame) { logger.info("PongWebSocketFrame Received"); } else if (msg instanceof CloseWebSocketFrame) { logger.info("CloseWebSocketFrame Received"); closeMessage = (CloseWebSocketFrame) msg; logger.info("ReasonText : {}", closeMessage.reasonText()); logger.info("StatusCode : {}", closeMessage.statusCode()); } else { throw new UnsupportedOperationException("Unsupported WebSocketFrame Type " + msg.getClass().getName()); } } } }
DssWebSocketHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof WebSocketFrame) { logger.info("Client Channel : {}", ctx.channel()); if (msg instanceof BinaryWebSocketFrame) { logger.info("BinaryWebSocketFrame Received"); } else if (msg instanceof TextWebSocketFrame) { logger.info("TextWebSocketFrame Received"); message = (TextWebSocketFrame) msg; ctx.channel().writeAndFlush(message.text()); logger.info("Received Message : {}", message.text()); } else if (msg instanceof PingWebSocketFrame) { logger.info("PingWebSocketFrame Received"); } else if (msg instanceof PongWebSocketFrame) { logger.info("PongWebSocketFrame Received"); } else if (msg instanceof CloseWebSocketFrame) { logger.info("CloseWebSocketFrame Received"); closeMessage = (CloseWebSocketFrame) msg; logger.info("ReasonText : {}", closeMessage.reasonText()); logger.info("StatusCode : {}", closeMessage.statusCode()); } else { throw new UnsupportedOperationException("Unsupported WebSocketFrame Type " + msg.getClass().getName()); } } }  }
DssWebSocketHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof WebSocketFrame) { logger.info("Client Channel : {}", ctx.channel()); if (msg instanceof BinaryWebSocketFrame) { logger.info("BinaryWebSocketFrame Received"); } else if (msg instanceof TextWebSocketFrame) { logger.info("TextWebSocketFrame Received"); message = (TextWebSocketFrame) msg; ctx.channel().writeAndFlush(message.text()); logger.info("Received Message : {}", message.text()); } else if (msg instanceof PingWebSocketFrame) { logger.info("PingWebSocketFrame Received"); } else if (msg instanceof PongWebSocketFrame) { logger.info("PongWebSocketFrame Received"); } else if (msg instanceof CloseWebSocketFrame) { logger.info("CloseWebSocketFrame Received"); closeMessage = (CloseWebSocketFrame) msg; logger.info("ReasonText : {}", closeMessage.reasonText()); logger.info("StatusCode : {}", closeMessage.statusCode()); } else { throw new UnsupportedOperationException("Unsupported WebSocketFrame Type " + msg.getClass().getName()); } } }  @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); }
DssWebSocketHandler extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof WebSocketFrame) { logger.info("Client Channel : {}", ctx.channel()); if (msg instanceof BinaryWebSocketFrame) { logger.info("BinaryWebSocketFrame Received"); } else if (msg instanceof TextWebSocketFrame) { logger.info("TextWebSocketFrame Received"); message = (TextWebSocketFrame) msg; ctx.channel().writeAndFlush(message.text()); logger.info("Received Message : {}", message.text()); } else if (msg instanceof PingWebSocketFrame) { logger.info("PingWebSocketFrame Received"); } else if (msg instanceof PongWebSocketFrame) { logger.info("PongWebSocketFrame Received"); } else if (msg instanceof CloseWebSocketFrame) { logger.info("CloseWebSocketFrame Received"); closeMessage = (CloseWebSocketFrame) msg; logger.info("ReasonText : {}", closeMessage.reasonText()); logger.info("StatusCode : {}", closeMessage.statusCode()); } else { throw new UnsupportedOperationException("Unsupported WebSocketFrame Type " + msg.getClass().getName()); } } }  @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);  }