1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.example.http.websocketx.server;
17
18 import io.netty5.channel.ChannelHandlerContext;
19 import io.netty5.channel.SimpleChannelInboundHandler;
20 import io.netty5.handler.codec.http.websocketx.TextWebSocketFrame;
21 import io.netty5.handler.codec.http.websocketx.WebSocketFrame;
22
23 import java.util.Locale;
24
25
26
27
28 public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
29
30 @Override
31 protected void messageReceived(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
32
33
34 if (frame instanceof TextWebSocketFrame) {
35
36 String request = ((TextWebSocketFrame) frame).text();
37 ctx.channel().writeAndFlush(new TextWebSocketFrame(ctx.bufferAllocator(), request.toUpperCase(Locale.US)));
38 } else {
39 String message = "unsupported frame type: " + frame.getClass().getName();
40 throw new UnsupportedOperationException(message);
41 }
42 }
43 }