REST easy with the JavaBeans Activation Framework

Use JAF for seamless data exchange in RESTful systems

Find out what makes the JavaBeans Activation Framework a perfect vehicle for RESTful data transmission, then put JAF to work in a sample Web application that tracks requests and responses through a Java Servlet-based system.

Representational State Transfer, also known as REST, is a style of software architecture defined by a collection of architectural principles. REST is applied specifically to such distributed systems as the Web, and stipulates mechanisms for defining and accessing resources. The term, originally described in a dissertation by Roy Fielding, often is used to describe any framework that transmits data over a protocol, such as HTTP, without additional semantic layers or session management.

The goal of REST is to simplify the implementation of actors in a client/server system by maintaining a strict separation of concerns. REST also seeks to simplify communication semantics, thereby improving performance and increasing the scalability of server components. REST relies on stateless interaction between requests, in which various media types are exchanged using standard message verbs.

REST can be implemented for the HTTP protocol using the Java programming language and JAF. In this article I introduce the basics of REST and JAF, then walk you through a REST implementation using JAF.

Note that Sun provides binaries of a  JAF reference implementation that can be used to develop JAF components and clients on any Java 2 Standard Edition platform Version 1.4 or later.

REST for beginners

In a REST implementation, resources, such as items in a shopping cart, are addressed via uniform resource identifiers (URI). A given URI is used to access the representational state of a resource, and also to modify that resource. For example, let's say a widget manufacturer uses REST to make its widgets available for consumption. At any given time, the manufacturer can present Web URLs containing descriptive information about the widgets. Widget consumers then need to know only a widget's URL to read the information. If authorized, the consumer also could modify the information as needed. The following illustrates a typical REST URI:

Notice how the URI defines the location of the "foobar" widget without stipulating an action to take. This is the goal of a URI in REST -- to represent a resource with a URI and to leave action semantics up to the underlying protocol.

One of the defining principles of REST is to exploit already existing technologies and Web protocols, in particular, HTTP. This makes REST simpler to use than other Web-based message processes, such as Simple Object Access Protocol (SOAP). A REST implementation requires no additional overhead to provide or consume information. According to Fielding, a REST-based conversation is stateless between requests, thereby supporting such subscription-based technologies as RSS, in which Web-site content is described and delivered to interested clients.

Entities of a REST implementation

REST is an abstraction of fundamental architectural entities within a distributed system. REST defines these entities as follows:

  • Data elements: Resources, resource identifiers (URIs and URLs), and resource representations, such as HTML documents, images and XML documents.
  • Components: Origin servers, gateways, proxies and user agents.
  • Connectors: Clients, servers, caches, and so forth.

Figure 1 illustrates some of the entities of REST and how they might participate within a simple enterprise system.

Entities of REST
Figure 1. REST in a simple enterprise system

In a system like the one above, connectors would be embodied as ports to enable communication among the components over each given protocol. Also note that any component can have multiple client and server connectors to handle communication between itself and other client or server components.

1 2 3 4 5 6 7 Page 1
Page 1 of 7