adapt JAX-RS Streaming Output (or similar) to vert.x HttpServerReaponse

92 views
Skip to first unread message

domi

unread,
Apr 26, 2018, 5:13:25 PM4/26/18
to vert.x
In a JAX-RS application, I hand a StreamingOutput to the Response object, in order to efficiently write to the OutputStream of the HTTP connection as the data (which can be hundreds of megabytes) is produced, thereby avoiding memory allocation.

StreamingOutput is an interface that defines just "write(OutputStream)". I failed to find a solution to create a ReadStream<Buffer> that would wrap the StreamingOutput (the implementations of which produce the various reponse bodies by implementing said "write") and be used with a Pump.

Has anyone found this approach useful and found a solution and is willing to share? Hints are highly appreciated.

Kind regards
Dominique

Thomas SEGISMONT

unread,
Apr 27, 2018, 4:21:53 AM4/27/18
to ve...@googlegroups.com
It's not clear to me what you want to achieve. Are you using Vert.x inside a JAX-RS application ?


--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/34c757fa-44e2-43e1-a5a2-ad1d62efa915%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

domi

unread,
May 4, 2018, 5:27:53 AM5/4/18
to vert.x
Hi Thomas

I'm really sorry for the late reply, I missed your response. I'm migrating a JAX-RS application to Vert.x, starting with the web frontend. My first goal is to deploy without web container (currently Tomcat, Wildfly). After that I can start using Vert.x concepts within the application.

In the mean time, I have been able to solve the problem I mentioned:

I created the class "AsyncOutputStream" which adapts the JAX-RX StreamingOutput to Vert.x ReadStream:
  public class AsyncOutputStream extends OutputStream implements ReadStream<Buffer>{
    public AsyncOutputStream(final Vertx vertx, final StreamingOutput output) {...}
    ...
  }

I'm using: (where "output" is an implementation of "StreamingOutput")
  final AsyncOutputStream readStream = new AsyncOutputStream(vertx, output);
  final Pump pump = Pump.pump(readStream, response);

I'm willing to share the implementation of AsyncOutputStream if anyone is interested (about 200 LoC).

Kind regards
Dominique

On Friday, 27 April 2018 10:21:53 UTC+2, Thomas Segismont wrote:
It's not clear to me what you want to achieve. Are you using Vert.x inside a JAX-RS application ?
2018-04-26 23:13 GMT+02:00 domi <domi....@gmail.com>:
In a JAX-RS application, I hand a StreamingOutput to the Response object, in order to efficiently write to the OutputStream of the HTTP connection as the data (which can be hundreds of megabytes) is produced, thereby avoiding memory allocation.

StreamingOutput is an interface that defines just "write(OutputStream)". I failed to find a solution to create a ReadStream<Buffer> that would wrap the StreamingOutput (the implementations of which produce the various reponse bodies by implementing said "write") and be used with a Pump.

Has anyone found this approach useful and found a solution and is willing to share? Hints are highly appreciated.

Kind regards
Dominique

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Thomas SEGISMONT

unread,
May 7, 2018, 3:10:12 PM5/7/18
to ve...@googlegroups.com
Thanks for the update

To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages