WebSockets and JSON-P
The Java EE 7 platform aims to provide a common ground for developing Java Enterprise solutions that incorporate
HTML5 technology. As such, there are a few core features that have been added to Java EE 7, allowing for better
bi-directional support of HTML5.
This chapter will focus on examples that demonstrate these HTML5 application programming interfaces (APIs).
You will learn how to make use of WebSockets and JSON-P so that your application's client-server communication can
become seamless, whether the user interface is written with HTML5, JSF, or another markup language.
The Java EE 7 platform eases communication between the client and the server via a technology named WebSockets,
enabling more parity with the HTML5 standard. WebSockets are full-duplex communication mechanisms that
allow for both text and binary messages to be sent between clients and servers, without the HTTP request/response
lifecycle. WebSockets allow either the client or the server to send a message at any time, providing an asynchronous
solution for delivering data while the user is performing a task, most often a browser task or event.
To get started, it is useful to familiarize yourself with a few of the most common terms that you may come across
when reading about WebSockets. Here are some terms to know:
Connection : Networking connection between two endpoints that are utilizing the
Endpoint : A Java component that is stationed at one end of a communication between
Client Endpoint : Initiates connections to a peer, but may not accept connections.
Server Endpoint : Accepts WebSocket connections from peers, but cannot initiate
Peer : Represents the opposite participant from an endpoint in a WebSocket
Session : Represents a sequence of WebSocket connections between endpoint and a single peer.
A WebSocket application consists of endpoints that can be created in a couple of different ways. The first way
to create an endpoint is to implement the WebSocket API interfaces, also referred to as a programmatic endpoint.
The second is to utilize annotations from the WebSocket API to decorate a “Plain Old Java Object,” or POJO, also
referred to as an annotated endpoint. If using the second means, the implementation creates the appropriate objects
to deploy the POJO as a WebSocket endpoint at runtime. Endpoints that are designed to listen for incoming
requests are known as ServerEndpoint s. Likewise, endpoints that are designed to initate requests and not to
listen are known as ClientEndpoint s. To see the complete Javadoc for WebSockets, please refer to it online at: