Hi,
At the end of the email are proposed interfaces for resource filtering.
Resource filtering will reuse the ContainerRequestFilter and
ContainerResponseFilter interfaces.
There are two ways resource filters can be registered:
1) Via @ResourceFilters by declaring an array of classes that
implement ResourceFilter.
This annotation may occur on a resource class, resource method,
sub-resource method or sub-resource locator.
2) Via a registered ResourceFilterFactory instance. A
ResourceFilterFactory will be applied to the abstract model of
a resource class, resource method, sub-resource method or sub-
resource locator. This is a mechanism to provide
general resource filters dependent on the specifics of a
resource. A list of ResourceFilterFactory can be registered
with the application.
Filter processing will occur in the following order:
- list of system-based ResourceFilter, in order, obtained from list
of system ResourceFilterFactory
- list of ResourceFilter, in order, obtained from list of
ResourceFilterFactory.
- array of ResourceFilter, in order, declared by @ResourceFilters.
Issues:
- It is not intended that response filters will be processed if an
exception is thrown before the response filters are to be processed, for
example by client filters or by the application. Part of the reason
is that there may not be any response information to be processed.
Exceptions are mapped to responses way up the call stack in the
WebApplication and thus requiring no logic in the call stack to
handle error conditions.
Paul.
/**
* A resource filter factory responsible for creating {_at_link
ResourceFilter}
* instances that match elements of the abstract resource model.
*
* @author Paul.Sandoz_at_Sun.Com
*/
public interface ResourceFilterFactory {
/**
* Create a {_at_link ResourceFilter} instance given an element
* of the abstract resource model.
*
* @param aae the abstract annotated element. This may be an
instance
* of the following: {_at_link AbstractResource}, {_at_link
AbstractResourceMethod},
* {_at_link AbstractSubResourceMethod} or {_at_link
AbstractSubResourceLocator}.
* @return the resource filter, otherwise null if no resource
filter is
* associated with the annotated element.
*/
ResourceFilter create(AbstractAnnotatedElement aae);
}
/**
* A resource filter to be used to filter a resource class, a
resource method,
* a sub-resource method, or a sub-resource locator.
*
* @author Paul.Sandoz_at_Sun.Com
*/
public interface ResourceFilter {
/**
* Get the request filter.
*
* @return the request filter, otherwise null if request filtering
* is not supported.
*/
ContainerRequestFilter getRequestFilter();
/**
* Get the response filter.
*
* @return the response filter, otherwise null if response
filtering
* is not supported.
*/
ContainerResponseFilter getResponseFilter();
}
/**
* Defines the list of application-declared {_at_link ResourceFilter}
* associated with a a resource class, a resource method,
* a sub-resource method, or a sub-resource locator.
*
* @author Paul.Sandoz_at_Sun.Com
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ResourceFilters {
Class<ResourceFilter>[] value();
}