Appendix E. Mapping REST, HTTP, and the Restlet API

This appendix is meant as a reference guide for the developer of Restlet applications. The first section lists key classes, properties, and constants used by the Restlet API and explains how they map to REST concepts, HTTP concepts, and headers.

Then we list all client and server connectors as well as the automatic representation converters available in Restlet Framework version 2.1. And we discuss the supported security challenge schemes and the authorities specific to the RIAP and CLAP pseudoprotocols.

E.1. Mapping REST concepts to Restlet classes

Table E.1 lists the main concepts of the REST architecture style and indicates the classes or interfaces of the Restlet API that materialize them.

Table E.1. Mapping REST concepts to Restlet classes

REST concept

Restlet class or interface

Description

Client org.restlet.Client Connector acting as a generic client. It internally uses one of the available connector helpers registered with the Restlet Engine.
Component org.restlet.Component Restlet managing a set of connectors, virtual hosts, services, and applications. Applications are expected to be directly attached to virtual hosts or to the internal router. Components also expose several services: access logging and status setting.
Connector org.restlet.Connector Restlet enabling communication between components. It can be either a client or server.
Metadata org.restlet.data.Metadata Representation metadata for content negotiation such as media type, language, character set, and encoding.
Representation org.restlet.representation.Representation Current or intended state of a resource. The content of a representation can be retrieved several times if there’s a stable and accessible source, like a local file or a string. When the representation is obtained via a temporary source like a network socket, its content can be retrieved only once.
Resource org.restlet.resource.Resource Base resource class exposing the uniform REST interface. Intended conceptual target of a hypertext reference. A uniform resource encapsulates a context, a request, and a response, corresponding to a specific target resource.
Server org.restlet.Server Connector acting as a generic server. It internally uses one of the available connector helpers registered with the Restlet Engine.
Uniform interface org.restlet.Uniform Uniform REST interface that defines the standard way to communicate between components via connectors. It corresponds to standard HTTP methods and to standard representation media types such as HTML, RDF, and Atom/AtomPub.

E.2. Mapping HTTP concepts to Restlet classes

Table E.2 describes the mapping between HTTP concepts and Restlet classes or interfaces.

Table E.2. Mapping HTTP concepts to Restlet classes

HTTP concept

Restlet class or interface

Definition from dissertation

Message org.restlet.Message Generic message exchanged between components, either a request or a response.
Request org.restlet.Request Generic request sent by client connectors. It’s received by server connectors and processed by Restlet. Requests are uniform across all types of connectors, protocols, and components.
Response org.restlet.Response Generic response sent by server connectors and received by client connectors. Responses are uniform across all types of connectors, protocols, and components.
Variant org.restlet.representation.Variant Descriptor for available representations of a resource. It contains all the important metadata about a representation but isn’t able to serve the representation’s content itself.

E.3. Mapping HTTP headers to Restlet properties

The HTTP protocol is the main source of inspiration for the Restlet API, which was designed as a high-level abstraction of the HTTP protocol. On the other hand, many developers refer to HTTP headers and need a tool to help them map the Restlet API properties to those HTTP headers. Providing that tool is the aim of table E.3.

Table E.3. Mapping HTTP headers to Restlet properties

Header

Restlet property name

Restlet property class

Description

Accept request.clientInfo.acceptedMedia-Types List<org.restlet.data.Preference <MediaType>> The list of media types accepted by the client.
Accept-Charset request.clientInfo.acceptedCharacterSets List<org.restlet.data.Preference<CharacterSet>> The list of character sets accepted by the client.
Accept-Encoding request.clientInfo.acceptedEncodings List<org.restlet.data.Preference <Encoding>> The list of encodings accepted by the client.
Accept-Language request.clientInfo.acceptedLanguages List<org.restlet.data.Preference <Language>> The list of languages accepted by the client.
Accept-Ranges response.serverInfo.acceptingRanges boolean Allows the server to indicate its support for range requests.
Age response.age int The estimated amount of time since the response was generated or revalidated by the origin server.
Allow response.allowedMethods Set<org.restlet.data.Method> Indicates the set of allowed methods. Can be retrieved with an OPTIONS call.
Authentication-Info response.authenticationInfo org.restlet.data.AuthenticationInfo Authentication information sent by an origin server to a client after a successful authentication attempt.
Authorization request.challengeResponse org.restlet.data.ChallengeResponse Credentials that contain the authentication information of the user agent for the realm of the resource being requested.
Cache-Control message.cacheDirectives List<org.restlet.data.CacheDirective> List of directives that must be obeyed by all caching mechanisms along the request/ response chain.
Content-Disposition message.entity .disposition org.restlet.data .Disposition Means for the origin server to suggest a default filename if the user requests that the content be saved to a file.
Content-Encoding message.entity.encodings List<org.restlet.data.Encoding> Indicates what additional content encodings have been applied to the entity-body.
Content-Language message.entity.languages List<org.restlet.data.Language> Describes the natural language(s) of the intended audience for the enclosed entity.
Content-Length message.entity .size long The size of the entity-body, in decimal number of OCTETs.
Content-Location message.entity.locationRef org.restlet.data.Reference Indicates the resource location for the entity enclosed in the message.
Content-MD5 message.entity.digest org.restlet.data.Digest Value and algorithm name of the digest associated with a representation.
Content-Range message.entity.range org.restlet.data.Range Indicates where in the full entity-body the partial body should be applied.
Content-Type message.entity.mediaType and characterSet org.restlet.data.MediaType + CharacterSet Indicates the media type of the entity-body.
Cookie request.cookies Series<org.restlet.data.Cookie> List of one or more cookies sent by the client to the server.
Date message.date Date The date and time at which the message originated.
ETag message.entity.tag org.restlet.data.Tag The current value of the entity tag for the requested variant.
Expect request.clientInfo.expectations List<org.restlet.data.Expectation> Indicates that particular server behaviors are required by the client.
Expires message.entity.expirationDate Date The date/time after which the response is considered stale.
From request.clientInfo.from String The email address of the human user controlling the user agent.
Host request.hostRef Reference Specifies the internet host and port number of the resource being requested.
If-Match request.conditions.match List<org.restlet.data.Tag> Used with a method to make it conditional.
If-Modified-Since request.conditions.modifiedSince Date Used with a method to make it conditional.
If-None-Match request.conditions.noneMatch List<org.restlet.data.Tag> Used with a method to make it conditional.
If-Range request.conditions.rangeTag and rangeDate org.restlet.data.Tag + Date Used to conditionally return a part or the entire resource representation.
If-Unmodified-Since request.conditions.unmodifiedSince Date Used with a method to make it conditional.
Last-Modified message.entity.modificationDate Date Indicates the date and time at which the origin server believes the variant was last modified.
Location response.locationRef org.restlet.data.Reference Used to redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource.
Max-Forwards request.maxForwards int Maximum number of proxies or gateways that can forward the request to the next inbound server.
Proxy-Authenticate response.proxyChallenge-Requests List<org.restlet.data.ChallengeRequest> Indicates the authentication scheme(s) and parameters applicable to the proxy.
Proxy-Authorization request.proxyChallenge-Response org.restlet.data.ChallengeResponse Credentials that contain the authentication information of the user agent for the proxy.
Range request.ranges List<org.restlet.data.Range> List of one or more ranges to return from the entity.
Referer request.refererRef Reference The address (URI) of the resource from which the Request-URI was obtained.
Retry-After response.retryAfter Date Indicates how long the service is expected to be unavailable to the requesting client.
Server response.serverInfo.agent String Information about the software used by the origin server to handle the request.
Set-Cookie response.cookieSettings Series<org.restlet.data.CookieSetting> List of one or more cookies sent by the server to the client.
Set-Cookie2 response.cookieSettings Series<org.restlet.data.CookieSetting> List of one or more cookies sent by the server to the client.
User-Agent request.clientInfo.agent String Information about the user agent originating the request.
Vary response.dimensions Set<org.restlet.data.Dimension> Indicates the set of request-header fields that fully determines, while the response is fresh, whether a cache is permitted to use the response to reply to a subsequent request without revalidation.
Via message.recipientsInfo List<org.restlet.data.RecipientInfo> Used by gateways and proxies to indicate the intermediate protocols and recipients between the user agent and the server on requests, and between the origin server and the client on responses.
Warning message.warnings List<org.restlet.data.Warning> Additional warning information.
WWW-Authenticate response.challengeRequests List<org.restlet.data.ChallengeRequest> Indicates the authentication scheme(s) and parameters applicable to the Request-URI.
X-Forwarded-For request.clientInfo.forwarded-Addresses List<String> The list of client IP addresses, including intermediary proxies.
X-HTTP-Method-Override tunnelService.methodHeader org.restlet.data.Method Overrides the HTTP method for limited clients such as browsers.

By convention, the list of property names refers to Restlet classes such as Request, Response, or Message. The “Restlet property name” column contains values such as request.clientInfo.acceptedMediaTypes and response.age, referring to Java properties of the message classes. Those properties are accessible using the getter and setter methods, such as Request.getClientInfo().getAcceptedMediaTypes() and Response.getAge().

E.4. Available connectors

As mentioned in chapter 1, connectors are an essential part of the REST architectural style. They enable communication between components by implementing a particular network protocol.

Because of the distinction between client and server components, this section contains two tables: one for the server connectors and one for client connectors as available in Restlet Framework version 2.1. Table E.4 lists the server connectors ordered by protocol name. Those connectors are available either in the core Restlet module (org.restlet) or in extension modules (org.restlet.ext.<moduleName>).

Table E.4. Server connectors

Protocol

Module

AJP jetty
HTTP core, jetty, simple
HTTPS ssl, jetty, simple
RIAP core
SIP sip
SIPS sip

Table E.5 lists all the client connectors available.

Table E.5. Client connectors

Protocol

Module

CLAP core
FILE core
FTP net
HTTP core, httpclient, net
HTTPS httpclient, net, ssl
JDBC jdbc
POP (v3) javamail
POPS (v3) javamail
RIAP core
SDC sdc
SIP sip
SIPS sip
SMTP javamail
SMTPS javamail
SOLR lucene
ZIP core

E.5. Available converters

As discussed elsewhere in the book, the ConverterService plays a key role in the content negotiation and automatic conversion feature between beans and raw representations.

Table E.6 lists the modules (either the core module or the extensions) that provide automatic serialization from representation beans to raw representations, including the media types and classes or interfaces supported.

Table E.6. Converters that provide automatic serialization

Module

Target media type

Serializable source class

core Any kind, the one computed by the content negotiation java.lang.String
core application/octet-stream java.io.File
core application/octet-stream java.io.InputStream
core application/x-java-serialized-object, application/x-java-serialized-object+xml, application/octet-stream Implements java.io.Serializable
core Text based media types, or text/plain java.io.Reader or subclasses
core application/x-www-form-urlencoded org.restlet.data.Form
atom application/atom+xml org.restlet.ext.atom.Feed
atom application/atomsvc+xml org.restlet.ext.atom.Service
emf application/xmi+xml Implements org.eclipse.emf.core.EObject
emf application/x-ecore+xmi+xml Implements org.eclipse.emf.core.EObject
emf application/xml, text/xml, text_html Implements org.eclipse.emf.core.EObject
freemarker Any kind, the one computed by content negotiation org.freemarker.Template
gwt application/x-java-serialized-object+gwt Implements java.lang.Serializable
html application/x-www-form-urlencoded org.restlet.ext.html.FormDataSet
html multipart/form-data org.restlet.ext.html.FormDataSet
jackson application/json Any class
javamail application/xml javax.mail.Message
jdbc text/xml javax.sql.rowset.WebRowSet
jdbc text/xml Java.sql.RowSet
jdbc text/xml org.restlet.ext.jdbc.JdbcResultSet
jaxb According to content negotiation, one of the following: application/xml, text/xml, application/*+xml Any class annotated with the javax.xml.bind.XmlRootElement
jibx According to content negotiation, one of the following: application/xml, text/xml, application/*+xml Any class, as soon as it’s been bound
json application/json org.json.JSONArray
json application/json org.json.JSONObject
json application/json org.json.JSONTokener
rdf application/*+xml org.restlet.ext.rdf.Graph
rdf text/x-turtle org.restlet.ext.rdf.Graph
rdf text/n-triples org.restlet.ext.rdf.Graph
rdf text/n3 org.restlet.ext.rdf.Graph
rome application/atom+xml com.sun.syndication.feed.synd.SyndFeed
rome application/rss+xml com.sun.syndication.feed.synd.SyndFeed
velocity Any kind of media types org.apache.velocity.Template
wadl application/vnd.sun.wadl+xml org.restlet.ext.wadl.ApplicationInfo
xml application/*+xml, application/xml, text/xml org.w3c.dom.Document
xstream application/json (with jettison library) Any kind of class
xstream application/xml, text/xml, application/*+xml Any kind of class

Note that the order of the converters in your classpath might matter and that each converter can express different scores for each media type or class, depending on their affinity with them.

Table E.7 lists the modules (either the core module or the extensions) that provide automatic deserialization of raw representations into representation beans, including the media types and classes or interfaces supported.

Table E.7. Converters that provides automatic deserialization

Module

Target class

Media type of the request’s entity

core java.lang.String Any kind
core org.rest.representation.StringRepresentation Any kind
core java.io.File Only if the request's entity is an instance of org.restlet.representation.FileRepresentation
core org.restlet.data.Form application/x-www-form-urlencoded
core java.io.InputStream Any kind
core org.restlet.representation.InputRepresentation Any kind
core java.io.Reader Any kind
core org.restlet.representation.ReaderRepresentation Any kind
core Implements java.io.Serializable application/x-java-serialized-object, application/x-java-serialized-object+xml, application/octet-stream
core Java primitive type application/x-java-serialized-object, application/x-java-serialized-object+xml, application/octet-stream
emf Implements org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl application/xmi+xml
emf Implements org.eclipse.emf.ecore.xmi.impl.EMOFResourceImpl application/x-ecore+xmi+xml
emf Implements org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl application/xml, text/xml, text_html
gwt Implements java.lang.Serializable application/x-java-serialized-object+gwt
html org.restlet.ext.html.FormDataSet application/x-www-form-urlencoded
jackson Any class application/json
jaxb Any class annotated with the javax.xml.bind.XmlRootElement According to content negotiation, one of the following: application/xml, text/xml, application/*+xml
jibx Any class, as soon it’s been bound According to content negotiation, one of the following: application/xml, text/xml, application/*+xml
json org.json.JSONArray application/json
json org.json.JSONObject application/json
json org.json.JSONTokener application/json
rdf org.restlet.ext.rdf.Graph application/*+xml
rdf org.restlet.ext.rdf.Graph text/x-turtle
rdf org.restlet.ext.rdf.Graph text/n-triples
rdf org.restlet.ext.rdf.Graph text/n3
rome com.sun.syndication.feed.synd.SyndFeed application/atom+xml
rome com.sun.syndication.feed.synd.SyndFeed application/rss+xml
wadl org.restlet.ext.wadl.ApplicationInfo application/vnd.sun.wadl+xml
xml org.w3c.dom.Document application/*+xml, application/xml, text/xml
xstream Any kind of class application/json (with Jettison library)
xstream Any kind of class application/xml, text/xml, application/*+xml

E.6. Supported security challenge schemes

Table E.8 lists all the security schemes supported by the Restlet Framework and the corresponding extensions (see also chapter 5). It also indicates whether the client and/or server sides of the security scheme are implemented.

Table E.8. Challenge schemes and their implementation

Scheme

Module

Client, server class

Description

FTP_PLAIN net FtpClientHelper (client only) Plain FTP authentication
HTTP_AWS_S3 crypto AwsAuthenticator Amazon S3 HTTP authentication
HTTP_AWS_QUERY crypto HttpAwsQueryHelper (client only) Amazon Query String authentication
HTTP_AZURE_SHAREDKEY crypto HttpAzureSharedKeyHelper (client only) Microsoft Azure Shared Key authorization (authentication)
HTTP_AZURE_SHAREDKEY_LITE crypto HttpAzureSharedKeyLite Helper (client only) Microsoft Azure Shared Key lite authorization (authentication)
HTTP_BASIC core HttpBasicHelper Basic HTTP authentication
HTTP_COOKIE crypto CookieAuthenticator Cookie HTTP authentication
HTTP_DIGEST crypto DigestAuthenticator Digest HTTP authentication
HTTP_OAUTH oauth OAuthAuthorizer, OAuthHelper Open protocol for API authentication
POP_BASIC javamail JavaMailClientHelper (client only) Basic POP authentication (USER/PASS commands)
POP_DIGEST javamail JavaMailClientHelper (client only) Digest POP authentication (APOP command)
SDC net GAE edition (client only) Secure Data Connector authentication (Google)
SDC sdc JavaSE and JavaEE editions (client only) Secure Data Connector authentication (Google)
SMTP_PLAIN javamail Core and JavaMail ClientHelper (client only) Plain SMTP authentication

E.7. Scheme authorities of RIAP and CLAP pseudoprotocols

We’ve introduced the RIAP and CLAP pseudoprotocols in order to complete the vision of a unified way to access resources, even within a Restlet component, and not only from the outside using a network protocol.

Much as HTTP lets you access resources on the Web, RIAP lets you access resources defined in your own Restlet applications and components, whereas CLAP lets you access resources available via Java class loaders.

Such resources are designated as local resources. A special Reference subclass called org.restlet.data.LocalReference facilitates the creation of such references to local resources with several methods, such as createClapReference() and create-RiapReference().

Table E.9 lists all important constants related to those pseudoprotocols and supported by the org.restlet.data.LocalReference class. The table should help you understand which kind of resource can be targeted.

Table E.9. Types defined in the LocalReference class

Authority constant

Value

Description

CLAP_DEFAULT "" or empty string The resources will be resolved from the class loader associated with the local class. This is the same as the CLAP_CLASS authority.
CLAP_CLASS class The resources will be resolved from the class loader associated with the local class. This is the default CLAP authority.
CLAP_SYSTEM system The resources will be resolved from the system’s class loader.
CLAP_THREAD thread The resources will be resolved from the current thread’s class loader.
RIAP_APPLICATION application The resources will be resolved from the current application’s root Restlet.
RIAP_COMPONENT component The resources will be resolved from the current component’s internal (private) router.
RIAP_HOST host The resources will be resolved from the current component’s virtual host.
..................Content has been hidden....................

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