|
|
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
Page 4 of 7
REST components are entities that are defined by the role they play in a given enterprise system. Typical components in a REST system are as follows:
In Java, you might represent a component using a marker interface, like so:
public interface Component
{
}
A server component in Java can expose the properties and methods by which resource contexts are managed, as illustrated in Listing 1.
public abstract class ServerComponent
implements Component
{
private java.util.HashMap<String, Context> contexts =
new java.util.HashMap<String, Context>();
abstract public Context addContext(String contextRootPath, String contextPath);
public java.util.Iterator<String> getContextPaths()
{
return contexts.keySet().iterator();
}
public Context getContext(String contextPath)
{
return contexts.get(contextPath);
}
protected java.util.HashMap<String, Context> getContexts()
{
return contexts;
}
}
An HTTP-specific server component can expose HTTP-specific contexts, as shown in Listing 2.
public Context addContext(String contextRootPath, String contextPath)
{
Context context = getContexts().get(contextPath);
if (context == null)
{
context = new HTTPContext(contextRootPath, contextPath);
getContexts().put(contextPath, context);
}
return context;
}
An HTTP-specific context implements the Context interface, where each HTTP method is handled and resource representations are manipulated and accessed. Listing 3 shows a
REST implementation representing the HTTP GET method. Note that the details of business logic for a particular vertical domain are encapsulated within individual business
services.
public Representation handleGet(Request request)
throws ContextRequestException
{
String uri = ((HTTPRequest)request).getRequest().getRequestURI();
if (uri.startsWith(contextPath))
{
uri = reqURI.substring(contextPath.length());
}
BusinessService businessService =
ServiceLocator.locateService(contextRootPath, contextPath, uri);
Representation representation = null;
try
{
representation = businessService.read(request);
}
catch (ServiceExecutionException e)
{
e.printStackTrace();
throw new ContextRequestException(e);
}
return representation;
}
REST components use connectors to interact with each other.