Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Dropwizard Support Servlet 3 Asynchronous Servlets?

Does Dropwizard support Servlet 3 asynchronous servlets? If not, is it on the roadmap at any time in the near future?

like image 280
EngineerBetter_DJ Avatar asked Dec 15 '22 20:12

EngineerBetter_DJ


2 Answers

It uses Jetty 8, which supports Servlet 3.0. Jersey (and JAX-RS) doesn't have any support for this, but it's forthcoming in JAX-RS 2.0 (and Jersey 2.0). Dropwizard doesn't add anything special, but when Jersey 2.0 ships, the next major Dropwizard release will very likely include it.

like image 188
Coda Hale Avatar answered Mar 30 '23 01:03

Coda Hale


You can use https://github.com/jetty-project/jetty-eventsource-servlet. Read wiki for how to impl Servlet and EventSource

In your DW Service implementation you add your SSE servlet

environment.addServlet(new MySseEventSourceServlet(), "/sse");

Then add this to your DW config

http:
    connectorType: NONBLOCKING

now you can start listening for Server-sent Event's on

<host>:<port>/sse

ex.

curl localhost:8080/sse -H"Accept: text/event-stream"

See working example @ GitHub, https://github.com/andershedstrom/dropwizard-with-sse

like image 43
anders Avatar answered Mar 30 '23 00:03

anders