Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

REST easy with the JavaBeans Activation Framework

Use JAF for seamless data exchange in RESTful systems

  • Print
  • Feedback

Page 3 of 7

Resources and data elements in REST

Most distributed systems offer an architect only three options for exposing the data of a resource:

  1. Render the data where it is located and send a fixed-format image to the recipient.
  2. Encapsulate the data with a rendering engine and send both to the recipient.
  3. Send the raw data to the recipient along with metadata that describes the data type, so the recipient can choose his or her own rendering engine.

According to Fielding, REST provides a hybrid of these three data-rendering options by "focusing on a shared understanding of data types with metadata, but limiting the scope of what is revealed to a standardized interface."

Data elements in REST are summarized as:

  • Resources
  • Resource identifiers
  • Representations
  • Representation metadata
  • Resource metadata
  • Control data

REST components act on a resource by using a URI-based representation to acquire a snapshot of the current state of the resource and transmitting that snapshot between components. A representation in REST is defined as a sequence of bytes, plus representation metadata describing those bytes. The format of a resource representation is defined by its MIME or media type. It is this key aspect of REST that makes JAF and the MIME-defined aspects of JAF such great facilitators of a REST data-element implementation.

Now that you've learned a bit about REST and JAF, we'll look at a sample Web application that tracks REST-based requests and responses through a simple Java servlet-based system.

Implementing REST with JAF

In the next sections I will develop a REST implementation using JAF. I'll start by modeling a simple system of components around the primary entities defined by REST, after which I'll construct a Java application using servlets and JAF. For now, consider the class diagram in Figure 3, which offers a high-level view of the Java classes and interfaces that make up the JAF-based REST implementation for the sample application.

Java classes and interfaces comprising the JAF-based REST implementation.

Figure 3. Classes and interfaces of a JAF-based REST implementation

As the class diagram shows, a FrontController servlet interacts with most of the primary REST entities, which are represented as Java interfaces. The following sections discuss each of the primary REST entities and the Java components that represent them.

  • Print
  • Feedback

Resources