Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Jersey SSE Capability in GlassFish 4.0.1

DZone's Guide to

Jersey SSE Capability in GlassFish 4.0.1

· Java Zone
Free Resource

Build vs Buy a Data Quality Solution: Which is Best for You? Gain insights on a hybrid approach. Download white paper now!

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

  1. Download the latest Glass Fish build from here

12. 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

2

jdk8_1

jdk8_2

3. Make sure you include the highlighted JARS ( below ) in your class path. These are available under GF_INSTALL/glassfish/modules

3

4

Now, the sample code for Jersey SSE feature demonstration. Its relatively simple.

There are three primary classes involved

AResource.java

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.

AResource

ATestServlet.java

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

ATestServlet

RESTConfig.java

As commonly the case with JAX-RS, this serves as bootstrap class

RESTConfig

To test the SSE functionality from server ( producer ) to client ( consumer ), deploy your application and just access the Servlet onhttp://you_gfish_ip:port/JerseySSE/SSETest. You should see the following logs

logs

fishcat

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 ;-)

Build vs Buy a Data Quality Solution: Which is Best for You? Maintaining high quality data is essential for operational efficiency, meaningful analytics and good long-term customer relationships. But, when dealing with multiple sources of data, data quality becomes complex, so you need to know when you should build a custom data quality tools effort over canned solutions. Download our whitepaper for more insights into a hybrid approach.

Topics:

Published at DZone with permission of Abhishek Gupta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}