I have a ServerResource which responds to GET requests by sending binary data back. The issue is that the source of the binary data will be downloaded asynchronously via a separate REST call (probably via HttpAsyncClient). Is it possible to create a Representation that I can feed data to as it arrives from the async download? I need to be able to do it without blocking any threads, so some sort of NIO solution is required.
I suspect I can do this with WriteableRepresetation, but I’m not exactly sure how as the documentation says
For this you just need to create a subclass and override the abstract Representation.write(WritableByteChannel) method. This method will later be called back by the connectors when the actual representation’s content is needed.
implying that when the method is called, all of the content must already be available.
I’m using v2.1.
After playing around with it for a bit, it looks like this is possible using a ReadableRepresentation. I dont know if there is a better way to create the ReadableByteChannel than using a Pipe or not, but that’s the only way I saw without having to implement my own Channel.