Source:
<code>public void testSelectiveResponseAggregation() { HttpObjectAggregator myTextAggregator = new HttpObjectAggregator(1024 * 1024) { @Override protected boolean isStartMessage(HttpObject msg) throws Exception { if (msg instanceof HttpResponse) { HttpResponse response = (HttpResponse) msg; HttpHeaders headers = response.headers(); String contentType = headers.get(HttpHeaderNames.CONTENT_TYPE); if (AsciiString.contentEqualsIgnoreCase(contentType, HttpHeaderValues.TEXT_PLAIN)) { return true; } } return false; } }; EmbeddedChannel channel = new EmbeddedChannel(myTextAggregator); HttpResponse response1 = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); HttpContent content1 = new DefaultHttpContent(Unpooled.copiedBuffer("Hello, World!", CharsetUtil.UTF_8)); response1.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.TEXT_PLAIN); channel.writeInbound(response1, content1, LastHttpContent.EMPTY_LAST_CONTENT); Object msg1 = channel.readInbound(); assertTrue(msg1 instanceof FullHttpResponse); HttpResponse response2 = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); HttpContent content2 = new DefaultHttpContent(Unpooled.copiedBuffer("{hello: 'world!'}", CharsetUtil.UTF_8)); response2.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON); channel.writeInbound(response2, content2, LastHttpContent.EMPTY_LAST_CONTENT); assertSame(response2, channel.readInbound()); assertSame(content2, channel.readInbound()); <START> assertSame(LastHttpContent.EMPTY_LAST_CONTENT, channel.readInbound()); <END> }</code><technical_language>call channel.finish() assert return</technical_language>

Target:
public void testSelectiveResponseAggregation() { HttpObjectAggregator myTextAggregator = new HttpObjectAggregator(1024 * 1024) { @Override protected boolean isStartMessage(HttpObject msg) throws Exception { if (msg instanceof HttpResponse) { HttpResponse response = (HttpResponse) msg; HttpHeaders headers = response.headers(); String contentType = headers.get(HttpHeaderNames.CONTENT_TYPE); if (AsciiString.contentEqualsIgnoreCase(contentType, HttpHeaderValues.TEXT_PLAIN)) { return true; } } return false; } }; EmbeddedChannel channel = new EmbeddedChannel(myTextAggregator); try { HttpResponse response1 = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); HttpContent content1 = new DefaultHttpContent(Unpooled.copiedBuffer("Hello, World!", CharsetUtil.UTF_8)); response1.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.TEXT_PLAIN); assertTrue(channel.writeInbound(response1, content1, LastHttpContent.EMPTY_LAST_CONTENT)); Object msg1 = channel.readInbound(); try { assertTrue(msg1 instanceof FullHttpResponse); } finally { ReferenceCountUtil.release(msg1); } HttpResponse response2 = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); HttpContent content2 = new DefaultHttpContent(Unpooled.copiedBuffer("{key: 'value'}", CharsetUtil.UTF_8)); response2.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON); try { assertTrue(channel.writeInbound(response2, content2, LastHttpContent.EMPTY_LAST_CONTENT)); assertSame(response2, channel.readInbound()); assertSame(content2, channel.readInbound()); assertSame(LastHttpContent.EMPTY_LAST_CONTENT, channel.readInbound()); } finally { ReferenceCountUtil.release(response2); ReferenceCountUtil.release(content2); } assertFalse(channel.finish()); } finally { channel.close(); } }