io.netty.handler.codec.json.JsonObjectDecoder Java Examples
The following examples show how to use
io.netty.handler.codec.json.JsonObjectDecoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientOperationsTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void addDecoderReplaysLastHttp() { ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8); EmbeddedChannel channel = new EmbeddedChannel(); new HttpClientOperations(() -> channel, ConnectionObserver.emptyListener(), ClientCookieEncoder.STRICT, ClientCookieDecoder.STRICT) .addHandler(new JsonObjectDecoder()); channel.writeInbound(new DefaultLastHttpContent(buf)); MatcherAssert.assertThat(channel.pipeline().names().iterator().next(), is("JsonObjectDecoder$extractor")); Object content = channel.readInbound(); MatcherAssert.assertThat(content, instanceOf(ByteBuf.class)); ((ByteBuf) content).release(); content = channel.readInbound(); MatcherAssert.assertThat(content, instanceOf(LastHttpContent.class)); ((LastHttpContent) content).release(); MatcherAssert.assertThat(channel.readInbound(), nullValue()); }
Example #2
Source File: HttpClientOperationsTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void addNamedDecoderReplaysLastHttp() { ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8); EmbeddedChannel channel = new EmbeddedChannel(); new HttpClientOperations(() -> channel, ConnectionObserver.emptyListener(), ClientCookieEncoder.STRICT, ClientCookieDecoder.STRICT) .addHandler("json", new JsonObjectDecoder()); channel.writeInbound(new DefaultLastHttpContent(buf)); MatcherAssert.assertThat(channel.pipeline().names().iterator().next(), is("json$extractor")); Object content = channel.readInbound(); MatcherAssert.assertThat(content, instanceOf(ByteBuf.class)); ((ByteBuf) content).release(); content = channel.readInbound(); MatcherAssert.assertThat(content, instanceOf(LastHttpContent.class)); ((LastHttpContent) content).release(); MatcherAssert.assertThat(channel.readInbound(), nullValue()); }
Example #3
Source File: HttpClientOperationsTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void addEncoderReplaysLastHttp() { ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8); EmbeddedChannel channel = new EmbeddedChannel(); new HttpClientOperations(() -> channel, ConnectionObserver.emptyListener(), ClientCookieEncoder.STRICT, ClientCookieDecoder.STRICT) .addHandler(new JsonObjectDecoder()); channel.writeInbound(new DefaultLastHttpContent(buf)); MatcherAssert.assertThat(channel.pipeline().names().iterator().next(), is("JsonObjectDecoder$extractor")); Object content = channel.readInbound(); MatcherAssert.assertThat(content, instanceOf(ByteBuf.class)); ((ByteBuf) content).release(); content = channel.readInbound(); MatcherAssert.assertThat(content, instanceOf(LastHttpContent.class)); ((LastHttpContent) content).release(); MatcherAssert.assertThat(channel.readInbound(), nullValue()); }
Example #4
Source File: HttpClientOperationsTest.java From reactor-netty with Apache License 2.0 | 6 votes |
@Test public void addNamedEncoderReplaysLastHttp() { ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8); EmbeddedChannel channel = new EmbeddedChannel(); new HttpClientOperations(() -> channel, ConnectionObserver.emptyListener(), ClientCookieEncoder.STRICT, ClientCookieDecoder.STRICT) .addHandler("json", new JsonObjectDecoder()); channel.writeInbound(new DefaultLastHttpContent(buf)); MatcherAssert.assertThat(channel.pipeline().names().iterator().next(), is("json$extractor")); Object content = channel.readInbound(); MatcherAssert.assertThat(content, instanceOf(ByteBuf.class)); ((ByteBuf) content).release(); content = channel.readInbound(); MatcherAssert.assertThat(content, instanceOf(LastHttpContent.class)); ((LastHttpContent) content).release(); MatcherAssert.assertThat(channel.readInbound(), nullValue()); }
Example #5
Source File: CodecSample.java From reactive-ipc-jvm with Apache License 2.0 | 6 votes |
private static void echoJsonStreamDecoding() { TcpServer<Person, Person> transport = Netty4TcpServer.<Person, Person>create( 0, new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel channel) throws Exception { channel.pipeline().addFirst( new JsonObjectDecoder(), new JacksonJsonCodec()); } }); ReactorTcpServer.create(transport) .start(connection -> { connection.log("input") .observeComplete(v -> LOG.info("Connection input complete")) .capacity(1) .consume(person -> { person = new Person(person.getLastName(), person.getFirstName()); Streams.wrap(connection.writeWith(Streams.just(person))).consume(); }); return Streams.never(); }); }
Example #6
Source File: NettyInvocationBuilder.java From docker-java with Apache License 2.0 | 6 votes |
public <T> void post(TypeReference<T> typeReference, ResultCallback<T> resultCallback, InputStream body) { HttpRequestProvider requestProvider = httpPostRequestProvider(null); Channel channel = getChannel(); JsonResponseCallbackHandler<T> jsonResponseHandler = new JsonResponseCallbackHandler<>( objectMapper, typeReference, resultCallback); HttpResponseHandler responseHandler = new HttpResponseHandler(requestProvider, resultCallback); channel.pipeline().addLast(new ChunkedWriteHandler()); channel.pipeline().addLast(responseHandler); channel.pipeline().addLast(new JsonObjectDecoder(3 * 1024 * 1024)); channel.pipeline().addLast(jsonResponseHandler); postChunkedStreamRequest(requestProvider, channel, body); }
Example #7
Source File: NettyInvocationBuilder.java From docker-java with Apache License 2.0 | 4 votes |
public <T> void get(TypeReference<T> typeReference, ResultCallback<T> resultCallback) { HttpRequestProvider requestProvider = httpGetRequestProvider(); Channel channel = getChannel(); JsonResponseCallbackHandler<T> jsonResponseHandler = new JsonResponseCallbackHandler<>( objectMapper, typeReference, resultCallback); HttpResponseHandler responseHandler = new HttpResponseHandler(requestProvider, resultCallback); channel.pipeline().addLast(responseHandler); channel.pipeline().addLast(new JsonObjectDecoder(3 * 1024 * 1024)); channel.pipeline().addLast(jsonResponseHandler); sendRequest(requestProvider, channel); return; }
Example #8
Source File: NettyInvocationBuilder.java From docker-java with Apache License 2.0 | 4 votes |
public <T> void post(final Object entity, TypeReference<T> typeReference, final ResultCallback<T> resultCallback) { HttpRequestProvider requestProvider = httpPostRequestProvider(entity); Channel channel = getChannel(); JsonResponseCallbackHandler<T> jsonResponseHandler = new JsonResponseCallbackHandler<>( objectMapper, typeReference, resultCallback); HttpResponseHandler responseHandler = new HttpResponseHandler(requestProvider, resultCallback); channel.pipeline().addLast(responseHandler); channel.pipeline().addLast(new JsonObjectDecoder(3 * 1024 * 1024)); channel.pipeline().addLast(jsonResponseHandler); sendRequest(requestProvider, channel); return; }