Example usage for io.netty.handler.codec.json JsonObjectDecoder JsonObjectDecoder

List of usage examples for io.netty.handler.codec.json JsonObjectDecoder JsonObjectDecoder

Introduction

In this page you can find the example usage for io.netty.handler.codec.json JsonObjectDecoder JsonObjectDecoder.

Prototype

public JsonObjectDecoder() 

Source Link

Usage

From source file:com.goide.dlv.DlvVm.java

License:Apache License

public DlvVm(@NotNull DebugEventListener tabListener, @NotNull Channel channel) {
    super(tabListener);

    commandProcessor = new DlvCommandProcessor() {
        @Override//from w  w w .java  2 s.com
        public boolean write(@NotNull Request message) throws IOException {
            ByteBuf content = message.getBuffer();
            LOG.info("OUT: " + content.toString(CharsetToolkit.UTF8_CHARSET));
            return vmHelper.write(content);
        }
    };
    vmHelper = new StandaloneVmHelper(this, commandProcessor, channel);

    channel.pipeline().addLast(new JsonObjectDecoder(), new SimpleChannelInboundHandlerAdapter() {
        @Override
        protected void messageReceived(ChannelHandlerContext context, Object message) throws Exception {
            if (message instanceof ByteBuf) {
                LOG.info("IN: " + ((ByteBuf) message).toString(CharsetToolkit.UTF8_CHARSET));
                CharSequence string = ChannelBufferToString.readChars((ByteBuf) message);
                JsonReaderEx ex = new JsonReaderEx(string);
                getCommandProcessor().processIncomingJson(ex);
            }
        }
    });
}

From source file:de.dentrassi.varlink.internal.ConnectionImpl.java

License:Open Source License

@Override
public CompletableFuture<CallResponse> call(final CallRequest call) {

    final CompletableFuture<CallResponse> result = new CompletableFuture<>();

    final Bootstrap bootstrap = new Bootstrap().group(this.group).channel(EpollDomainSocketChannel.class)
            .handler(new ChannelInitializer<Channel>() {

                @Override/*w ww.ja  v  a 2  s .  c o  m*/
                protected void initChannel(final Channel channel) throws Exception {

                    if (PROTOCOL_LOGGER.isDebugEnabled()) {
                        channel.pipeline().addLast(new LoggingHandler(PROTOCOL_LOGGER_NAME));
                    }

                    channel.pipeline().addLast(new DelimiterBasedFrameDecoder(MAX_FRAME_LENGTH, nulDelimiter()))
                            .addLast(NullByteEncoder.INSTANCE).addLast(new JsonObjectDecoder())
                            .addLast(ConnectionImpl.this.stringEncoder).addLast(new StringDecoder(UTF_8))
                            .addLast(new VarlinkCodec()).addLast(new CallHandler(call, result));

                }
            });

    logger.debug("Connecting: {}", this.address);

    final ChannelFuture future = bootstrap.connect(this.address);

    final Channel channel = future.channel();

    future.addListener(v -> {

        logger.debug("connect complete");

        try {
            future.get();

            logger.debug("connect completed successfully");
        } catch (final Throwable e) {
            logger.debug("connect failed", e);
            channel.close();
            result.completeExceptionally(e);
        }
    });

    return result;
}

From source file:reactor.ipc.netty.http.client.HttpClientOperationsTest.java

License:Open Source License

@Test
public void addDecoderReplaysLastHttp() throws Exception {
    ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
    EmbeddedChannel channel = new EmbeddedChannel();
    HttpClientOperations ops = new HttpClientOperations(channel, (response, request) -> null, handler);

    ops.addHandler(new JsonObjectDecoder());
    channel.writeInbound(new DefaultLastHttpContent(buf));

    assertThat(channel.pipeline().names().iterator().next(), is("JsonObjectDecoder$extractor"));
    assertThat(channel.readInbound(), instanceOf(ByteBuf.class));
    assertThat(channel.readInbound(), instanceOf(LastHttpContent.class));
    assertThat(channel.readInbound(), nullValue());
}

From source file:reactor.ipc.netty.http.client.HttpClientOperationsTest.java

License:Open Source License

@Test
public void addNamedDecoderReplaysLastHttp() throws Exception {
    ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
    EmbeddedChannel channel = new EmbeddedChannel();
    HttpClientOperations ops = new HttpClientOperations(channel, (response, request) -> null, handler);

    ops.addHandler("json", new JsonObjectDecoder());
    channel.writeInbound(new DefaultLastHttpContent(buf));

    assertThat(channel.pipeline().names().iterator().next(), is("json$extractor"));
    assertThat(channel.readInbound(), instanceOf(ByteBuf.class));
    assertThat(channel.readInbound(), instanceOf(LastHttpContent.class));
    assertThat(channel.readInbound(), nullValue());
}

From source file:reactor.ipc.netty.http.client.HttpClientOperationsTest.java

License:Open Source License

@Test
public void addEncoderReplaysLastHttp() throws Exception {
    ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
    EmbeddedChannel channel = new EmbeddedChannel();
    HttpClientOperations ops = new HttpClientOperations(channel, (response, request) -> null, handler);

    ops.addHandler(new JsonObjectDecoder());
    channel.writeInbound(new DefaultLastHttpContent(buf));

    assertThat(channel.pipeline().names().iterator().next(), is("JsonObjectDecoder$extractor"));
    assertThat(channel.readInbound(), instanceOf(ByteBuf.class));
    assertThat(channel.readInbound(), instanceOf(LastHttpContent.class));
    assertThat(channel.readInbound(), nullValue());
}

From source file:reactor.ipc.netty.http.client.HttpClientOperationsTest.java

License:Open Source License

@Test
public void addNamedEncoderReplaysLastHttp() throws Exception {
    ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
    EmbeddedChannel channel = new EmbeddedChannel();
    HttpClientOperations ops = new HttpClientOperations(channel, (response, request) -> null, handler);

    ops.addHandler("json", new JsonObjectDecoder());
    channel.writeInbound(new DefaultLastHttpContent(buf));

    assertThat(channel.pipeline().names().iterator().next(), is("json$extractor"));
    assertThat(channel.readInbound(), instanceOf(ByteBuf.class));
    assertThat(channel.readInbound(), instanceOf(LastHttpContent.class));
    assertThat(channel.readInbound(), nullValue());
}