You are previewing Developing RESTful Services with JAX-RS 2.0, WebSockets, and JSON.
O'Reilly logo
Developing RESTful Services with JAX-RS 2.0, WebSockets, and JSON

Book Description

A complete and practical guide to building RESTful Web Services with the latest Java EE7 API

  • Learning about different client/server communication models including but not limited to client polling, Server-Sent Events and WebSockets.

  • Efficiently use WebSockets, Server-Sent Events, and JSON in Java EE applications

  • Learn about JAX-RS 2.0 new features and enhancements

  • Improve scalability with asynchronous processing

In Detail

As the technology landscape moves focus towards smaller devices, the need for building scalable, flexible, lightweight, and real-time communications-based applications grows. HTML 5 and Java EE 7 provide a new synthesis of technologies that demonstrate tremendous scope and potential in areas of device independence, asynchronous communication, interoperability, and portability.

Developing RESTful Services with JAX-RS 2.0, WebSockets, and JSON is a practical, hands-on guide that provides you with clear and pragmatic information to take advantage of the real power behind HTML5 and Java EE technologies. This book also gives you a good foundation for using them in your applications.

Developing RESTful Services with JAX-RS 2.0, WebSockets, and JSON looks at the different HTML5-based Java EE 7 API, and takes a deep dive into the individual areas of technologies to cover basic to advanced concepts, and also provides best practices for each API. You will also learn how to build a REST-based Event Notification Application using the Twitter API, tying all the different technologies together that we will cover. You will also take a look at integrating different Java EE APIs to build a Library Application. If you want to take advantage of using the new HTML5 technologies and Java EE 7 platform, then this is the book for you. You will learn everything you need to know to build portable RESTful Web Services with JAX-RS 2.0, Web Sockets, JSON, and Server-Sent Events.

Table of Contents

  1. Developing RESTful Services with JAX-RS 2.0, WebSockets, and JSON
    1. Table of Contents
    2. Developing RESTful Services with JAX-RS 2.0, WebSockets, and JSON
    3. Credits
    4. About the Authors
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
        3. Instant Updates on New Packt Books
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Building RESTful Web Services Using JAX-RS
      1. Understanding REST
      2. RESTful Web Services
      3. Verbs in REST
        1. Safety and idempotence
      4. Introduction to JAX-RS
        1. Converting POJOs to RESTful resources
          1. Defining a root resource as identified by a URI
          2. Defining the methods for the resource
          3. Defining the MIME types
          4. Defining the Application subclass
          5. Defining the subresources
        2. More on JAX-RS annotations
        3. The Client API for JAX-RS
        4. Entities in JAX-RS
        5. Custom entity providers in JAX-RS
          1. MessageBodyReader
          2. MessageBodyWriter
        6. Using the Bean Validation API with JAX-RS
          1. Enabling validation in the application
          2. Reading validation errors from the response
      5. Summary
    9. 2. WebSockets and Server-sent Events
      1. The programming models
        1. Polling
        2. Long polling
          1. Long polling clients and XMLHttpRequest
          2. Chunked transfer encoding
      2. Emerging standards
        1. Server-sent Events
          1. The SSE anatomy
        2. Associating an ID with an event
          1. Connection loss and reconnecting retries
          2. Associating event names with events
          3. Server-sent Events and JavaScript
        3. WebSockets
          1. WebSocket handshake
          2. Browser and JavaScript support for WebSockets
      3. Java EE and the emerging standards
        1. Java EE and Server-sent Events
        2. Java EE and WebSockets
      4. Comparison and use cases of different programming models and standards
      5. Summary
    10. 3. Understanding WebSockets and Server-sent Events in Detail
      1. Encoders and decoders in Java API for WebSockets
      2. The Java WebSocket Client API
      3. Sending different kinds of message data: blob/binary
      4. Security and WebSockets
      5. Best practices for WebSockets based applications
        1. Throttling the rate of sending data
        2. Controlling the maximum size of the message
        3. Working with proxy servers and WebSockets
      6. Server-sent Events
        1. Developing a Server-sent Event client using Jersey API
      7. Best practices for applications based on Server-sent Events
        1. Checking if the event source's origin is as expected
        2. Working with proxy servers and Server-sent Events
        3. Handling fault tolerance for Server-sent Events
      8. Summary
    11. 4. JSON and Asynchronous Processing
      1. Producing and parsing JSON documents
        1. An overview of JSON API
        2. Manipulating JSON documents using the event-based API
        3. Producing JSON documents
        4. Parsing JSON documents
        5. Manipulating JSON documents using the JSON object model
          1. Generating JSON documents
          2. Parsing JSON documents
        6. When to use the streaming versus the object API
      2. Introducing Servlet 3.1
        1. NIO API and Servlet 3.1
        2. Introducing ReadListener and WriteListener
        3. Changes in the Servlet API interfaces
          1. More changes in Servlet 3.1
      3. New features in JAX-RS 2.0
        1. Asynchronous request and response processing
        2. Filters and interceptors
      4. Asynchronous processing in EJB 3.1 and 3.2
        1. Developing an asynchronous session bean
        2. Developing a client servlet for the async session bean
      5. Summary
    12. 5. RESTful Web Services by Example
      1. Event notification application
        1. The project's layout
        2. The event notification GUI
        3. A detailed look at the event notification application
          1. The web.xml
          2. The implementation of the Application class
          3. The JAX-RS resource used by the application
          4. The Asynchronous Servlet client used by the application
          5. The EJB that interacts with the Twitter Search API
      2. The library application
        1. How the application is deployed
        2. The project's layout
        3. The library application GUI
        4. Application interaction monitoring
        5. A detailed look at the library application
          1. The web.xml
          2. The Application subclass
          3. JAX-RS Entity Provider: BookCollectionWriter
          4. The HTML page
          5. Browsing the collection of books
            1. Using JavaScript
            2. The JAX-RS resource method for the GET request
          6. Searching for a book
            1. Using JavaScript
            2. The WebSockets endpoint
          7. Checking out a book
            1. Using JavaScript
            2. The JAX-RS resource method for the DELETE request
          8. Returning a book
            1. Using JavaScript
            2. The JAX-RS resource method for the POST request
          9. Placing a hold on a book
            1. Using JavaScript
            2. The JAX-RS resource method for the asynchronous POST request
          10. The Singleton EJB BookService
      3. Summary
    13. Index