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

SSE Item Store Jersey Example

An example demonstrating how Server Sent Events (SSE) Jersey support 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-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-jersey-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>