O'Reilly logo

Java 9 Programming Blueprints by Jason Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting updates

So far, we can see all of the conversations, view individual messages in a conversation, and send new messages. What we can't do yet is get updates when new messages arrive on the device, so let's implement that now, starting with the server piece this time.

To get a constant stream of events, we'll use a feature called Server-Sent Events, a W3C specification for receiving push notifications from the server. We enabled this feature in Jersey by registering the SseFeature in both the client and server setup steps. To create an SSE endpoint, we specify that the method returns the media type SERVER_SENT_EVENTS, and we return an EventOutput as the payload:

 @GET @Path("status") @Produces(SseFeature.SERVER_SENT_EVENTS) @Secure ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required