This page last changed on Oct 13, 2009 by bluk.

Registration and Configuration

Apache Wink provides several methods for registering resources and providers. This chapter describes registration methods and Wink configuration options.  

Simple Application

Apache Wink provides the "SimpleWinkApplication" class in order to support the loading of resources and providers through a simple text file that contains a list of fully qualified class names of the resource and provider classes. Each line contains a single fully qualified class name that is either a resource or a provider. Empty lines and lines that begin with a number sign (#) are permitted and ignored.

# Providers

# Resources

Specifying the Simple Application File Location

The path to a simple application file is configured via the applicationConfigLocation init-param in the web.xml file. It is possible to specify multiple files by separating them with a semicolon.


Apache Wink Application

Apache Wink extends the class with the org.apache.wink.common.WinkApplication class in order to provide the Dynamic Resources and the Priorities functionality.

An application may provide an instance of the Apache Wink Application to the Apache Wink runtime as specified by the JAX-RS specification.

Dynamic Resources

Dynamic Resources enable the binding of a Resource class to a URI path during runtime instead of by using the @Path annotation. A dynamic resource must implement the DynamicResource interface and must not be annotated with the @Path annotation.


A Dynamic Resource is useful for situations where a resource class must be bound to multiple paths, for example, a sorting resource:

public class SortingResource<E extends Comparable<? super E>> {
    private List<E> list;
    public void sort() {
    public void setList(List<E> list) {
        this.list = list;
    public List<E> getList() {
        return list;

In this example, the SortingResource class can sort any list. If the application manages a library of books and exposes the following resource paths, then the SortingResource class can be used for the implementation of all these resource paths, assuming that it could be bound to more than one path.


A dynamic resource is also useful for situations where the resource path is unknown during development, and is only known during the application startup.


A Dynamic Resource is a resource class that implements the org.apache.wink.server.DynamicResource interface or extends the org.apache.wink.server.AbstractDynamicResource convenience class.

A Dynamic Resource is not registered in Apache Wink through the Application#getClasses() method or the Application#getSignletons() method, since the same class can be used for multiple resources.
In order to register Dynamic Resources in the system, the WinkApplication#getInstances()method must be used.


The scope of a Dynamic Resource is limited to "singleton" as it is initialized prior to its registration, and the system does not have enough information to create it in runtime. This limitation is irrelevant when working with Spring. Refer to chapter ‎0 for more information on Spring integration.


Although JAX-RS defines the algorithm for searching for resources and providers, Apache Wink enables to extend this algorithm by allowing the specification of priorities for them.
Apache Wink extends the JAX-RS search algorithms by providing the ability to specify priorities on the resources and providers. This is achieved by enabling the registration of multiple Application instances with different priorities, rendering the order of their registration irrelevant as long as they have different priorities.

In order to register a prioritized Application, it is necessary to register an instance of a Apache WinkApplication class. Priority values range between 0 and 1. In the event that the priority was not specified, a default priority of 0.5 is used.

Resource Priorities

Priorities on resources are useful for situations where an application registers core resources bound to paths, and allows extensions to register resources on the same paths in order to override the core resources.

The Apache Wink runtime first sorts the resources based on their priority and then based on the JAX-RS specification, thus if two resources have the same path, the one with higher priority is invoked.

Provider Priorities

JAX-RS requires that application-provided providers be used in preference to implementation pre-packaged providers. Apache Wink extends this requirement by allowing applications to specify a priority for providers.

The Apache Wink runtime initially sorts the matching providers according to the JAX-RS specification, and uses the priority as the last sorting key for providers of equal standing.
If two providers have the same priority, the order in which they are registered determines their priority such that the latest addition receives the highest priority.
In order to meet the JAX-RS requirements, the pre-packages providers are registered using a priority of 0.1.

Properties Table

Property Name
Default Value
URI that is used by the Link Builders in case of HTTP
Use the URI from the request
URI used by the Link Builders in case of HTTPS
Use the URI from the request
Context path used by the Link Builders
Use the context path from the request
Indicates if URIs generated by the Link Builders are absolute or relative, valid values: true or false
true - links are relative
Indicates if the "alt" query parameter should be added to URIs generated by the Link Builders. Valid values are: true, false
true - add the alt query parameter
Indicates if continues search is enabled. Valid values: true, false
true - continued search is enabled
Indicates if a root resource with Service Document generation capabilities should be added.
Valid values are: none, atom, atom+html
atom+html --atom and html Service Document generation capabilities
Defines path to a css file that is used in the  html Service Document generation. Relevant only if html Service Document is defined
No css file defined
Defines a org.apache.wink.server
.handlers.HandlersFactory class that defines user handlers
No user handlers defined
Defines a org.apache.wink.server.handlers
.MediaTypeMapperFactory class that defines media type mappers
No media type mappers defined
Loads providers defined in a wink-application file found by the runtime
True, automatically load all wink-application specified classes

Custom Properties File Definition

In order to provide a custom properties file, the application should define the propertiesLocation init-param in the Apache Wink Servlet definition.

# Providers


RegistrationApache Wink provides several APIs for Runtime Registration. The APIs appear in the org.apache.wink.server.utils.RegistrationUtils class. The most important method is the one that registers an instance of the class

# Providers
static void registerApplication(Application application, ServletContext servletContext)
Double Registration
Registration is ignored and a warning is printed to the log if the instance was previously registered

Media-Type Mapping

It is sometimes necessary to override the Content-Type response header based on the client user agent. For example, the Firefox browser cannot handle the application/atom+xml media type for Atom content, unless it is defined as a text/xml.

Apache Wink provides a set of predefined Media-Type mappings for use in such cases by supplying the MediaTypeMapper class. Applications may extend or override the MediaTypeMapper class to define additional mappings.

Customizing Mappings

In order to customize these mappings the application should create a instance of a org.apache.wink.server.handlers.MediaTypeMapperFactory class and set it in a customized Wink properties file.

Refer to section 5.1 Registration and Configuration for more information on Customizing the Default Properties Configuration.

Alternative Shortcuts

Clients specify the requested media type by setting the Http Accept header. Apache Wink provides an alternate method for specifying the requested media type via use of the "alt" request parameter. This functionality is useful for situation where the client has little affect on the accept header, for example when requesting a resource using a browser.

For example, a request to /entry?alt=application/xml  specifies that the requested response media type is application/xml. Apache Wink provides a shortcut mechanism for specifying the media type of the alt query parameter and provides a predefined set of shortcuts for common media types.

Predefined Shortcuts

Media Type

Customizing Shortcuts

The shortcuts table can be customized by overriding the deployment configuration class.

Refer to section 2 Apache Wink Building Blocks for more information on Customizing the Default Deployment Configuration.
Document generated by Confluence on Nov 11, 2009 06:57