Book Image

Developing RESTful Web Services with Jersey 2.0

By : Sunil Gulabani
Book Image

Developing RESTful Web Services with Jersey 2.0

By: Sunil Gulabani

Overview of this book

<p>JAX-RS 2.0 is an enhanced framework based on RESTful architecture. It provides support for both the client and the server. Jersey 2.0 is the reference implementation of JAX-RS 2.0 (JSR 339 specification). This framework has undergone major revisions. The enhanced framework helps developers to use a low-level and simplified API.</p> <p>This practical, hands-on guide will help you to create RESTful web services easily with individual aspects of the application requests. It will enable you to learn and implement RESTful web services using the new features included in JAX-RS 2.0. It’s a jump start for those who want to try their hand at the new API. It aims to provide practical knowledge of the API along with detailed understanding.</p> <p>This book covers the new features of JAX-RS 2.0. It covers the complete lifecycle of a web service, that is, from server side to client side. The book focuses on the server API and the client API.</p> <p>You will learn how to use the server API in order to create web services that will be deployed on the server. This has all different implementations of HTTP methods and media representations. You will also get acquainted with the client API which specifies how to consume the deployed application’s web services. This includes how to handle different HTTP methods and media representations in response to the web services.</p> <p>You will also get to know Server Sent Events (SSE), which the server uses to push the data event directly to the client. The book will finally take you through the WADL specification. By the end of the book, you will be well equipped to implement Jersey 2.0 and JAX-RS.</p>
Table of Contents (13 chapters)

XML


XML is a standard way to process data in the client/server architecture. Jersey provides different ways to use XML for data traversing over the client/server.

Low-level XML support

Low-level XML support consists of:

  • StreamSource

  • SAXSource

  • DOMSource

  • Document

Let's look at the following example:

  • Server side:

    @Path("/userResource")
    public class UserResource {
    
        @POST
        @Path("usingStreamSource")
        public StreamSource getStreamSource(StreamSource streamSource) {
            return streamSource;
        }
    
        @POST
        @Path("usingSAXSource")
        public SAXSource getSAXSource(SAXSource saxSource) {
            return saxSource;
        }
    
        @POST
        @Path("usingDOMSource")
        public DOMSource getDOMSource(DOMSource domSource) {
            return domSource;
        }
    
        @POST
        @Path("usingDocument")
        public Document getDocument(Document document) {
            return document;
        }
    }

    StreamSource, SAXSource, DOMSource, and Document are different types of XML formats. These low-level formats are used to read...