Java Reference
In-Depth Information
Chapter 8
Building RESTful Web Services
The Java EE 6 platform introduced the Java API for RESTful Web Services (JAX-RS), enabling developers to easily
develop powerful web services. RESTful web services are those that support the Representational State Transfer
(REST) architectural style, which is an architecture for producing web services that focus on a system's resources,
specifically on how states are transferred over HTTP. JAX-RS web services are stateless, and they utilize HTTP methods
explicitly by mapping methods of web service classes to HTTP protocols ( GET , POST , PUT , DELETE ) via annotations.
A RESTful web service provides custom URIs for access to web service resources, allowing web service methods to be
invoked and passing zero or more parameters via a simple URI call from a web service client. RESTful web services
can send responses that are in XML, JavaScript Object Notation (JSON), or other formats. The JAX-RS stack provides
an annotation-rich architecture for designing web services, which makes it much easier for developers to produce
powerful web services without XML configuration.
Although JAX-RS was first introduced in the Java EE platform with the release of EE 6, the concept of RESTful web
services has been around for a number of years. The reference implementation for JAX-RS is a project named Jersey,
which is hosted on ( ) . As such, new features for the development of RESTful web
services are first available in the reference implementation, so those who want to be on the bleeding edge of REST for
Java enterprise applications can utilize the Jersey project within their applications.
Java EE 7 introduces the next evolution in JAX-RS, which is the release of JAX-RS 2.0. This release is considered
a major release, because it greatly enhances the functionality of JAX-RS in a number of areas. For instance, in Java EE
6, there was no standard way to produce a JAX-RS client. Developers had to utilize different means for testing web
services, provide nonstandard implementations for reading and processing web service data, and so on. With the
release of JAX-RS 2.0, a new client API is being introduced to fill the gap in this area. The new release also provides
asynchronous processing capabilities, the ability to filter and/or intercept requests, and many more enhancements to
make JAX-RS even more attractive for web service development.
This chapter will first provide a brief overview of how to utilize JAX-RS, demonstrating how to produce a web
service to produce and consume data. It will then delve into coverage of each new feature, providing examples of
each. Although you are expected to be familiar with the Java EE concepts, this chapter will appeal to those who are
new to JAX-RS as well, since the brief overview should be enough information to get started utilizing the API.
Overview of JAX-RS
For years, some developers have cringed over the idea of developing web services because they entailed lots of XML
configuration and coding. However, even though web services were historically time-consuming to create, they have
proven to be a major benefit to enterprise technology. The Java EE 6 platform introduced JAX-RS for the development
of web service resources, which makes it much easier to develop such resources using annotations and little or
no XML configuration. JAX-RS provides the ability to create web services that have the capability of producing or
consuming content by annotating Plain Old Java Object (POJO) classes with a special set of annotations according to
the service you want to provide. In this section, you'll take a brief look at how to develop web services using JAX-RS,
along with an overview of the different concepts. If you are new to JAX-RS, this section will provide you with enough
Search WWH ::

Custom Search