Sunday, 18 August 2013

how to stream a response over HTTP with netty

how to stream a response over HTTP with netty

I'm using Netty 3.6.6 and I'd like to send a large response back to the
caller. I can't copy the response body into a ChannelBuffer as in some
cases it will be very large.
I'm migrating a server from CXF to Netty, previously, I could just use the
OutputStream provided by CXF to write the data.
I originally tried to just send the response without content, and then
continued to write data to the Channel in a series of 8k buffers. This
failed as the client seemed to get the original response and see no data
and complain. I tried setting the response as chunked, but this didnt seem
to make a difference, nor did setting the chunked header, the client
always saw an empty stream.
I saw the file server example for 3.6.6, and that's similar to what I want
to do, except the data will not be a file. I saw the ChunkedStream &
NioStream, which seemed close to what I need, except they take
InputStream/ReadableByteChannel whereas I have an OutputStream; I could
try using the PipedInput & OutputStreams, but that seems like it would
introduce an unfortunate bottleneck.
I'm sure there's a way to stream a lot of data back to the client in
response to a request, but I'm just not seeing how to do it unless I have
a file.

No comments:

Post a Comment