Search in sources :

Example 6 with JsonObjectDecoder

use of io.netty.handler.codec.json.JsonObjectDecoder in project reactor-netty by reactor.

the class HttpClientOperationsTest method addNamedEncoderReplaysLastHttp.

@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"));
    Object content = channel.readInbound();
    assertThat(content, instanceOf(ByteBuf.class));
    ((ByteBuf) content).release();
    content = channel.readInbound();
    assertThat(content, instanceOf(LastHttpContent.class));
    ((LastHttpContent) content).release();
    assertThat(channel.readInbound(), nullValue());
}
Also used : DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) JsonObjectDecoder(io.netty.handler.codec.json.JsonObjectDecoder) ByteBuf(io.netty.buffer.ByteBuf) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)6 JsonObjectDecoder (io.netty.handler.codec.json.JsonObjectDecoder)6 Test (org.junit.Test)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)5 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Unpooled (io.netty.buffer.Unpooled)1 ChannelHandler (io.netty.channel.ChannelHandler)1 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)1 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)1 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 SslContext (io.netty.handler.ssl.SslContext)1 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)1 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)1 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1 NetUtil (io.netty.util.NetUtil)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1