Reading an HttpContent that has PooledUnsafeDirectByteBuf

I have a Reactor-Netty HttpServer to which I send data that contains more than 1024 bytes from HttpClient.

In the client, I get different parts of the request in Flux with the idea of ​​concatenating the data into a string, which I can ultimately parse. I thought this could be done by the HttpObjectAggregator, but alas not.

When a customer receives content, he comes as

DefaultHttpContent (data: PooledSlicedByteBuf (ridx: 1024, widx: 1024, cap: 1024/1024, deployed: PooledUnsafeDirectByteBuf (ridx: 1024, widx: 1024, cap: 1024)), decoderResult: success)

and

DefaultLastHttpContent (data: PooledSlicedByteBuf (ridx: 98, widx: 98, cap: 98/98, unwrapped: PooledUnsafeDirectByteBuf (ridx: 98, widx: 98, cap: 1024)), decoderResult: success)

If I try to "extract" bytes, I find that they are not available.

Server

private void startServer() { HttpServer server = HttpServer.create(opts -> opts.listen(8092).option(ChannelOption.SO_RCVBUF, 1024 * 1024) .option(ChannelOption.SO_SNDBUF, 1024 * 1024).option(ChannelOption.SO_KEEPALIVE, true) .afterChannelInit(channelInit -> { ChannelPipeline pipeline = channelInit.pipeline(); pipeline.addLast("aggregator", new HttpObjectAggregator(64 * 1024)); })); Mono<? extends NettyContext> context = server.newRouter(routes -> { routes.post("/test", postHandler()); routes.put("/test", postHandler()); }); context.subscribe().block(Duration.ofSeconds(30)); } BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> postHandler() { return (req, resp) -> { final String combinedContent = new String(); req.requestHeaders().entries().forEach(entry -> { String key = entry.getKey(); String value = entry.getValue(); if (key.equalsIgnoreCase("content-length")) { contentLength = Integer.parseInt(value); } log.debug(String.format("header [%s=>%s]", key, value)); }); req.receiveContent().doOnNext(request -> { ByteBuf bb = ByteBufUtil.readBytes(request.content().alloc(), request.content(), request.content().readableBytes()); log.debug("HEX DUMP : " + ByteBufUtil.prettyHexDump(request.content())); combinedContent.concat(new String(ByteBufUtil.getBytes(bb))); }).subscribe((what) -> { log.debug("Combined Request = " + combinedContent.toString()); log.debug("what = " + what); }); return Mono.empty(); }; } 

Client

 @Test public void testClientMessage() { HttpClient httpClient; try { httpClient = webClient.connect("localhost", 8092, false); webClient.send(httpClient, "/test", getTestRequest()); } catch (SSLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private String getResponse() { return "Well Done"; } private String getTestRequest() { return ""; } 

Any idea how I can get the data?

Data is written to the console, for example:

12: 08: 16.245 [reactor-http-nio-2] DEBUG r.ipc.netty.http.server.HttpServer - [id: 0xf0f21e64, L: /127.0.0.1: 8092 - R: /127.0.0.1: 52774] RECEIVED: 98B + ---------------------------------------------- --- + | 0 1 2 3 4 5 6 7 8 9 abcdef | + -------- + ---------------------------------------- --------- + ---------------- + | 00000000 | 54 68 61 6e 31 30 32 34 62 79 74 65 73 6d 6f 72 | Than1024bytesmor | | 00000010 | 65 54 68 61 6e 31 30 32 34 62 79 74 65 73 6d 6f | eThan1024bytesmo | | 00000020 | 72 65 54 68 61 6e 31 30 32 34 62 79 74 65 73 6d | reThan1024bytesm | | 00000030 | 6f 72 65 54 68 61 6e 31 30 32 34 62 79 74 65 73 | oreThan1024bytes | | 00000040 | 6d 6f 72 65 54 68 61 6e 31 30 32 34 62 79 74 65 | moreThan1024byte | | 00000050 | 73 6d 6f 72 65 54 68 61 6e 31 30 32 34 62 79 74 | smoreThan1024byt | | 00000060 | 65 73 | es | + -------- + ---------------------------------------- --------- + ---------------- +

thanks

+1
reactor netty reactor-netty
source share

No one has answered this question yet.

See similar questions:

or similar:

4
how to confirm netty tried to read socket
2
In Netty4, why read and write as in OutboundHandler
2
How to pause and resume reading with Netty 4?
0
Reading network source code in trouble
0
How to read from NioSocketChannel?

All Articles