You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

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, 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.

Out-of-the-Box Implementations

The following section describes the Apache Wink providers that are an addition to the JAX-RS requirements.

Scoping

The JAX-RS specification defines that by default, 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 (section‎0) 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.

@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.

@Scope(ScopeType.SINGELTON)
@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.

@Provider
public class MyProvider implements MessageBodyReader<String>{
    ...
}

Priority

Apache Wink provides a method for setting a priority for a provider.

Reference

Refer to chapter 3, section ‎3.4.2 TBD for more information on Provider Priorities.

  • No labels