Chapter 9. Using JAX-RS 2.0 in Java EE 7 with RESTEasy

JSR 311 (http://jcp.org/en/jsr/detail?id=311) specifies the Java API for RESTful Web services (JAX-RS) for developing REST (Representational State Transfer) Web services with Java. REST is a protocol independent, loosely coupled, software architecture style for distributed systems. A RESTful Web service exposes a set of resources, which are simply sources of information, identified by URIs (Uniform Resource Identifiers) in HTTP. RESTful Web services follow these RESTful principles:

  • Every resource has a unique base URI
  • For invoking Web service operations, the HTTP protocol methods such as GET, PUT, POST, and DELETE are used
  • A client sends a request to a service, and the service returns a representation of a resource requested to the client
  • Client sessions are not stored on the server, which makes it easier to scale the service with less data to replicate in a clustered environment

JSR 339 (https://www.jcp.org/en/jsr/detail?id=339) develops the JAX-RS 2.0 version. JAX-RS 2.0 provides several new features, such as a Client API, support for validation, filters and interceptors, and asynchronous processing. We will discuss the salient new features in JAX RS 2.0 using the RESTEasy (http://resteasy.jboss.org/) implementation. This chapter has the following sections:

  • Setting up the environment
  • The Client API
  • Filters and interceptors
  • Asynchronous processing
  • Cancelling a request
  • Session bean EJB resource
  • Making an asynchronous call from the client

Setting up the environment

We need to install the following software:

Set the environment variables JAVA_HOME, JBOSS_HOME, and MAVEN_HOME. Add %JAVA_HOME%/bin, %MAVEN_HOME%/bin, and %JBOSS_HOME%/bin to the PATH environment variable.

Create a WildFly 8.1.0 runtime as discussed in Chapter 1, Getting Started with EJB 3.x. Create a MySQL data source with the JNDI name java:jboss/datasources/MySQLDS as explained in Chapter 1, Getting Started with EJB 3.x.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset