Jersey SSE Capability in GlassFish 4.0.1
Join the DZone community and get the full member experience.Join For Free
glassfish bundles different reference implementations for various java ee specifications e.g. weld for cdi, mojarra for jsf, tyrus for websocket, jersey for jax-rs. glass fish 4.0.1 is in the pipeline and slated to cover updates for many of the components/modules which both include new features and bug fixes of course.
server sent events feature in jersey will be supported with glass fish 4.0.1. let’s try and test out this feature
- download the latest glass fish build from here
2. unzip the contents of the zip installer and configure the same in your ide ( i am using netbeans ). note : i am using using jdk 8. remember to configure glass fish to use the same
3. make sure you include the highlighted jars ( below ) in your class path. these are available under gf_install/glassfish/modules
now, the sample code for jersey sse feature demonstration. its relatively simple.
there are three primary classes involved
it serves as a producer of stream of events and is modeled as jax-rs resource which emits events when invoked with a get method. the returned event streams are abstracted in the form of org.glassfish.jersey.media.sse.eventoutput on to which a org.glassfish.jersey.media.sse.outboundevent object is written. the outboundevent consists of the actual event data.
this class serves as consumer of the events produced by the aresource.java class. this is a simple jax-rs client which sends a get request to the published jax-rs resource, reads the org.glassfish.jersey.client.chunkedinput and further extracts the actual event data from org.glassfish.jersey.media.sse.inboundevent instance
as commonly the case with jax-rs, this serves as bootstrap class
to test the sse functionality from server ( producer ) to client ( consumer ), deploy your application and just access the servlet on http://you_gfish_ip:port/jerseysse/ssetest . you should see the following logs
about the fishcat – glass fish community acceptance testing program . everyone is welcome to participate!
more on jersey and server sent events here .
this was a rather quick one.. not bad ! now you have time to go and do something more useful ;-)
Published at DZone with permission of Abhishek Gupta, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
How To Use Pandas and Matplotlib To Perform EDA In Python
Database Integration Tests With Spring Boot and Testcontainers
Chaining API Requests With API Gateway