Package io.netty.handler.codec.http.websocketx

Examples of io.netty.handler.codec.http.websocketx.TextWebSocketFrame


    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof CloseWebSocketFrame) {
            ctx.channel().close();
            ((CloseWebSocketFrame)msg).release();
        } else if (msg instanceof TextWebSocketFrame) {
            TextWebSocketFrame frame = (TextWebSocketFrame) msg;
            WebSocketClient client = channelId2Client.get(ctx.channel());
            if (client == null) {
                log.debug("Client with was already disconnected. Channel closed!");
                ctx.channel().close();
                frame.release();
                return;
            }

            ctx.pipeline().fireChannelRead(new PacketsMessage(client, frame.content()));
            frame.release();
        } else if (msg instanceof FullHttpRequest) {
            FullHttpRequest req = (FullHttpRequest) msg;
            QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri());
            String path = queryDecoder.path();
            if (path.startsWith(this.path)) {
View Full Code Here


        assertThat(decode[0], equalTo("x"));
    }

    @Test
    public void decodeTextWebSocketFrameSimpleString() throws Exception {
        final TextWebSocketFrame frame = new TextWebSocketFrame("\"test\"");
        final String[] decode = JsonUtil.decode(frame);
        assertThat(decode.length, is(1));
        assertThat(decode[0], equalTo("test"));
        frame.release();
    }
View Full Code Here

        frame.release();
    }

    @Test
    public void decodeTextWebSocketFrameArray() throws Exception {
        final TextWebSocketFrame frame = new TextWebSocketFrame("[\"test\"]");
        final String[] decode = JsonUtil.decode(frame);
        assertThat(decode.length, is(1));
        assertThat(decode[0], equalTo("test"));
        frame.release();
    }
View Full Code Here

        frame.release();
    }

    @Test
    public void decodeTextWebSocketFrameObject() throws Exception {
        final TextWebSocketFrame frame = new TextWebSocketFrame("{\"firstName\":\"Fletch\"}");
        final String[] decode = JsonUtil.decode(frame);
        assertThat(decode.length, is(1));
        assertThat(decode[0], equalTo("{\"firstName\":\"Fletch\"}"));
        frame.release();
    }
View Full Code Here

            final Channel ch = b.connect(uri.getHost(), uri.getPort()).sync().channel();
            handler.handshakeFuture().sync();

            final String uaid = UUIDUtil.newUAID();
            final String json = JsonUtil.toJson(new HelloMessageImpl(uaid.toString()));
            final ChannelFuture future = ch.writeAndFlush(new TextWebSocketFrame(json));
            future.sync();
            final TextWebSocketFrame textFrame = handler.getTextFrame();
            final HelloResponse fromJson = JsonUtil.fromJson(textFrame.text(), HelloResponseImpl.class);
            assertThat(fromJson.getMessageType(), equalTo(MessageType.Type.HELLO));
            assertThat(fromJson.getUAID(), equalTo(uaid));
            textFrame.release();

            final String channelId = UUID.randomUUID().toString();
            final String register = JsonUtil.toJson(new RegisterMessageImpl(channelId));
            final ChannelFuture registerFuture = ch.writeAndFlush(new TextWebSocketFrame(register));
            registerFuture.sync();
            final TextWebSocketFrame registerFrame = handler.getTextFrame();
            final RegisterResponseImpl registerResponse = JsonUtil.fromJson(registerFrame.text(), RegisterResponseImpl.class);
            assertThat(registerResponse.getMessageType(), equalTo(MessageType.Type.REGISTER));
            assertThat(registerResponse.getChannelId(), equalTo(channelId));

            ch.writeAndFlush(new CloseWebSocketFrame());
View Full Code Here

            final Channel ch = b.connect(uri.getHost(), uri.getPort()).sync().channel();
            handler.handshakeFuture().sync();

            final String uaid = UUIDUtil.newUAID();
            final String json = JsonUtil.toJson(new HelloMessageImpl(uaid.toString()));
            final ChannelFuture future = ch.writeAndFlush(new TextWebSocketFrame(json));
            future.sync();
            final TextWebSocketFrame textFrame = handler.getTextFrame();
            final HelloResponse fromJson = JsonUtil.fromJson(textFrame.text(), HelloResponseImpl.class);
            assertThat(fromJson.getMessageType(), equalTo(MessageType.Type.HELLO));
            assertThat(fromJson.getUAID(), equalTo(uaid));
            textFrame.release();

            Thread.sleep(3000);
            final String channelId = UUID.randomUUID().toString();
            final String register = JsonUtil.toJson(new RegisterMessageImpl(channelId));
            final ChannelFuture registerFuture = ch.writeAndFlush(new TextWebSocketFrame(register));
            registerFuture.sync();
            ch.writeAndFlush(new CloseWebSocketFrame());
            ch.closeFuture().sync();
        } finally {
            group.shutdownGracefully();
View Full Code Here

    public static String helloFrameAsJson(final String uaid, final String... channelIds) {
        return toJson(new HelloMessageImpl(uaid.toString(), new HashSet<String>(Arrays.asList(channelIds))));
    }

    public static TextWebSocketFrame helloWebSocketFrame(final String uaid, final String... channelIds) {
        return new TextWebSocketFrame(helloFrameAsJson(uaid.toString(), channelIds));
    }
View Full Code Here

        return asSockjsMessage(toJson(new RegisterMessageImpl(channelId)));
    }

    public static TextWebSocketFrame registerChannelIdWebSocketFrame(final String channelId) {
        final String json = toJson(new RegisterMessageImpl(channelId));
        return new TextWebSocketFrame(json);
    }
View Full Code Here

        final String json = toJson(new RegisterMessageImpl(channelId));
        return new TextWebSocketFrame(json);
    }

    public static TextWebSocketFrame pingWebSocketFrame() {
        return new TextWebSocketFrame(toJson(new PingMessageImpl()));
    }
View Full Code Here

        return new TextWebSocketFrame(toJson(new PingMessageImpl()));
    }

    public static TextWebSocketFrame unregisterChannelIdWebSocketFrame(final String channelId) {
        final String json = toJson(new UnregisterMessageImpl(channelId));
        return new TextWebSocketFrame(json);
    }
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.http.websocketx.TextWebSocketFrame

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.