8 Using Server-Sent Events in WebLogic Server

Oracle WebLogic Server supports server-sent events through the integration of the Jersey 2.x library. The Jersey 2.x library provides the Reference Implementation (RI) of JSR-339 (JAX-RS 2.0: Java API for RESTful Web Services).

Overview of Server-Sent Events (SSE)

Server-sent events enable servers to push data to web pages over standard HTTP or HTTPS through a unidirectional client-server connection. In the server-sent events communication model, the browser client establishes the initial connection, and the server provides the data and sends it to the client. For general information about server-sent events, see the Server-Sent Events W3C Candidate Recommendation.

Server-sent events are part of the HTML 5 specification, which also includes WebSocket technology. Both communication models enable servers to send data to clients unsolicited. However, server-sent events establish one-way communication from server to clients, while a WebSocket connection provides a bidirectional, full-duplex communication channel between servers and clients, promoting user interaction through two-way communication. The following key differences exist between WebSocket and server-sent events technologies:

  • Server-sent events can only push data to the client, while WebSocket technology can both send and receive data from a client.

  • The simpler server-sent events communication model is better suited for server-only updates, while WebSocket technology requires additional programming for server-only updates.

  • Server-sent events are sent over standard HTTP and therefore do not require any special protocol or server implementation to work. WebSocket technology requires the server to understand the WebSocket protocol to successfully upgrade an HTTP connection to a WebSocket connection.

For more information about WebSocket technology, see Using the WebSocket Protocol in WebLogic Server in Developing Applications for Oracle WebLogic Server.

Understanding the WebLogic Server-Sent Events API

WebLogic Server supports server-sent events through the integration of the Jersey 2.x. The use of server-sent events through Jersey 2.x is supported only in JAX-RS resources. For more information about server-sent events in Jersey 2.x, see Server-Sent Events (SSE) Support in the Jersey 2.21 User Guide.

The WebLogic Server Server-Sent Events API is in the package org.glassfish.jersey.media.sse. For information about the interfaces and classes included in this package, see the API documentation for org.glassfish.jersey.media.sse in the Jersey 2.21 API Documentation.

Sample Applications for Server-Sent Events

Sample applications for server-sent events are available through the Jersey project. Refer to the following locations: