Apache Wink Representations
In addition to the JAX-RS standard representations Wink provides an expanded set of representations that can be used by an application to expose resources in a rich set of representations. The following section provides information about the representations that are supported by Apache Wink.
Apache Wink Representations Request Flow
The following diagram illustrates the client request flow for a resource.
A resource is an abstract entity and as such can not be transmitted between peers. When a client is required to send or receive a resource it must use a representation of that resource. The resource representation is a specific formatting of the resource data. The diagram illustrates that a request for a resource is in fact a request for a specific representation of that resource.
Apache Wink implements resource representations through the use of providers for java objects as defined by the JAX-RS specification.
Apache Wink Providers
In addition to JAX-RS standard providers (refer to section 4.2 of the JAX-RS specification), Apache Wink provides a set of complementary providers. The purpose of these providers is to provide mapping services between various representations ( for example Atom, APP, RSS, OpenSearch, CSV, JSON and HTML) , and their associated Java data models.
The Apache Wink providers are pre-registered and delivered with the Apache Wink runtime along with the JAX-RS standard providers.
Apache Wink provides an additional method for defining the life cycle of a provider via the use of the @Scope annotation and a way to define the providers priorities.
Scoping
The JAX-RS specification defines that by default, that a singleton instance of each provider class is instantiated for each JAX-RS application. Apache Wink fully supports this requirement and in addition provides a "Prototype" lifecycle, which is an instance per-request lifecycle.
Prototype means that a new instance of a provider class is instantiated for each request. The @Scope annotation (section0) is used on a provider class to specify its lifecycle. The lifecycle of a provider that does not specify the @Scope annotation defaults to the singleton lifecycle.
Prototype Example
The following example shows how to define a provider with a prototype lifecycle.
Code Block | ||||
---|---|---|---|---|
| ||||
@Scope(ScopeType.PROTOTYPE)
@Provider
public class MyProvider implements MessageBodyReader<String>{
...
}
|
Singleton Example 1
The following example shows how to define a provider with a singleton lifecycle.
Code Block | ||||
---|---|---|---|---|
| ||||
@Scope(ScopeType.SINGELTONSINGLETON) @Provider public class MyProvider implements MessageBodyReader<String>{ ... } |
Singleton Example 2
The following example shows that when the @Scope annotation is not used, the provider will be a singleton, as per the JAX-RS specification.
Code Block | ||||
---|---|---|---|---|
| ||||
@Provider
public class MyProvider implements MessageBodyReader<String>{
...
}
|
Priority
Apache Wink provides a method for setting a priority for a provider.
Info | ||
---|---|---|
| ||
Refer to chapter 3, section 3.4.2 TBD for For more information on Provider Priorities . |
Out-of-the-Box Implementations
The following section describes the Apache Wink providers that are an addition to the JAX-RS requirements.
Atom Providers
Apache Wink provides a set of entity providers that are capable of mapping Atom Feed and Atom Entry XML documents to and from an Atom data model.
Info | ||
---|---|---|
| ||
Refer to chapter 9 TBD for more information on Data Models. |
Atom Providers
The following tables list these providers.
AtomFeedProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | application/atom+xml | AtomFeed |
Write | Yes | application/atom+xml | AtomFeed |
AtomFeedSyndFeedProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | application/atom+xml | SyndFeed |
Write | Yes | application/atom+xml | SyndFeed |
AtomFeedJAXBElementProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | application/atom+xml | JAXBElement<AtomFeed> |
Write | Yes | application/atom+xml | JAXBElement<AtomFeed> |
AtomEntryProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | application/atom+xml | AtomEntry |
Write | Yes | application/atom+xml | AtomEntry> |
AtomEntrySyndEntryProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | application/atom+xml | SyndEntry |
Write | Yes | application/atom+xml | SyndEntry> |
AtomEntryJAXBElementProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | Yes | application/atom+xml | JAXBElement<AtomEntry> |
Write | Yes | application/atom+xml | JAXBElement<AtomEntry>> |
APP Providers
Apache Wink provides a set of providers that are capable of mapping APP Service Document and APP Categories data models to their xml representations. The following tables list these providers.
Info | ||
---|---|---|
| ||
Refer to chapter 9, section 9.5 TBD in chapter 9 for more information on the Atom Publishing Protocol. |
AppServiceProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | No | N/A | N/A |
Write | Yes | application/atomsvc+xml | AppService>> |
AppCategoriesProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | No | N/A | N/A |
Write | Yes | application/atomcat+xml | AppCategories>> |
CategoriesProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | No | N/A | N/A |
Write | Yes | application/atomcat+xml | Categories>> |
OpenSearch Provider
Apache Wink provides a single provider that is capable of serializing the OpenSearch data model.
Info | ||
---|---|---|
| ||
Refer to the xml representations chapter 9, section 9.7 TBD for more information on OpenSearch. |
OpenSearchDescriptionProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | No | N/A | N/A |
Write | Yes | application/opensearchdescription+xml | OpenSearchDescription >> |
Json Providers
Apache Wink provides a set providers that are capable of serializing a number of data models (JSONObject, JAXBElement, SyndEntry, SyndFeed) into JSON representations. The following tables list these providers.
JsonProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | No | N/A | N/A |
Write | Yes | application/json , application/javascript | JSONObject >> |
JsonJAXBProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | No | N/A | N/A |
Write | Yes | application/json , application/javascript | JAXB object, |
JsonSyndEntryProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | No | N/A | N/A |
Write | Yes | application/json, application/javascript | SyndEntry>> |
JsonSyndFeedProvider
| Supported | Media Types | Entity |
---|---|---|---|
Read | No | N/A | N/A |
Write | Yes | application/json , application/javascript | SyndFeed>> |
Asset Provider
...
refer to section 5.1 Registration and Configuration. |