tree: 3a2118a5fc4ad522a0d8c4129a9b2e9d197c72c8 [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.MD
examples/sse-item-store-jaxrs-webapp/README.MD

JAX-RS SSE Item Store Jersey Example

An example demonstrating how new Server Sent Events (SSE) JAX-RS API can be used to notify clients about changes in server-side managed data (collection of items). The example also outlines how SSE events can be consumed using javascript browser-based clients.

Contents

The example consists of a web-based client application and a server-side application deployed on a Jetty servlet container.

The server side part of the application consists of a JAX-RS resource managing collection of string items and a simple HTML page that includes a browser SSE client written in Javascript as well as a basic CSS stylesheet. The SSE Javascript client connects to the JAX-RS resource and transforms the streamed messages into HTML code that is rendered by the browser. The javascript client also demonstrates how named and unnamed SSE events are handled by HTML5 EventSource component. The mapping of the URI path space of the server-side part of the application is presented in the following table:

URI pathResource classHTTP methods
/resources/itemsItemStoreResourceGET, POST
/resources/items/eventsItemStoreResourceGET (SSE)

Application is configured to run using Jetty maven plugin under base path sse-item-store-jaxrs-webapp.

Running the Example

mvn clean compile jetty:run

The command above deploys the current example. After successful deployment, you should be able to access the browser SSE client page at http://localhost:8080/sse-item-store-jaxrs-webapp/index.html. To see the raw SSE event stream, you may also point your browser directly at the ItemStoreResource.

Deploying the example to another servlet container.

mvn clean package

The command above creates a Servlet 3.x compliant WAR located in the target directory. The WAR can be then deployed to your Servlet 3.x compliant container.

Running Test Client

After deploying the application into a Servlet 3.x compliant container, you can run the attached test by executing:

mvn test -Djersey.config.test.container.factory=org.glassfish.jersey.test.external.ExternalTestContainerFactory -Djersey.config.test.container.port=<port>