Chapter 14. Using WebSockets with EJB 3

 

This chapter covers

  • The basics of WebSockets
  • Integrating WebSockets with Java EE
  • Using annotated and programmatic endpoints

In this chapter we’ll delve into an exciting new technology that was added to Java EE 7 to support HTML5: WebSockets. WebSockets are raw sockets that support true full-duplex communication between the web browser and back-end server. With WebSockets, you can push data to the web browser from the server without depending on hacks or having the client poll the server.

14.1. Limits of request–response

In the traditional HTTP model, the client browser opens a connection to an HTTP server and requests an operation to be performed, such as GET, POST, PUT, DELETE, and so on. The HTTP server performs the operation and returns a result, usually HTML content. The connection to the server may be kept open for additional requests so that if multiple resources from the server are being retrieved, each request doesn’t require an additional socket to open and close. If you look at the complexity of some of the current web pages, this makes sense—pages with lots of content, such as eBay.com, would be extremely slow if each image had to endure a full socket opening and closing. In each case, however, the client is the initiator—the client makes a request and the server responds. The server never pushes data back to the client without the client making a request.

14.2. Introducing WebSockets

14.3. WebSockets and Java EE

14.4. WebSockets in ActionBazaar

14.5. Using WebSockets effectively

14.6. Summary