Jersey SSE capability in Glass Fish 4.0.1

jerseylogo
sse
logo-glassfishGlass Fish 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
  2.  
    1

  3. 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.
  4.  
    2

     

    jdk8_11

     

    jdk8_2

     

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

     

    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.

restconfig1

 
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:

 
logs1

fishcat1

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!

Cheers!!!

Reference: Jersey SSE capability in Glass Fish 4.0.1 from our JCG partner Abhishek Gupta at the Object Oriented.. blog.
Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

Leave a Reply


7 − three =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books