public final class ApplicationHandler extends java.lang.Object implements ContainerLifecycleListener
Container implementations use the ApplicationHandler
API to process requests
by invoking the handle(request)
method on a configured application handler instance.
ApplicationHandler
provides two implementations of config
that can be injected
into the application classes. The first is resource config
which implements Configuration
itself and is configured by the user. The resource config is not modified by this application handler so the future reloads of
the application is not disrupted by providers found on a classpath. This config can
be injected only as ResourceConfig
or Application
. The second one can be injected into the
Configuration
parameters / fields and contains info about all the properties / provider classes / provider instances
from the resource config and also about all the providers found during processing classes registered under
server properties
. After the application handler is initialized both configurations are marked as
read-only.
Application handler instance also acts as an aggregate ContainerLifecycleListener
instance
for the associated application. It aggregates all the registered container lifecycle listeners
under a single, umbrella listener, represented by this application handler instance, that delegates all container lifecycle
listener method calls to all the registered listeners. Jersey containers
are expected to invoke
the container lifecycle methods directly on the active ApplicationHandler
instance. The application handler will then
make sure to delegate the lifecycle listener calls further to all the container lifecycle listeners registered within the
application. Additionally, invoking the ContainerLifecycleListener.onShutdown(Container)
method on this application
handler instance will release all the resources associated with the underlying application instance as well as close the
application-specific HK2 ServiceLocator
.
ResourceConfig
,
Configuration
,
ContainerProvider
Modifier and Type | Class and Description |
---|---|
private class |
ApplicationHandler.ApplicationBinder |
private static class |
ApplicationHandler.FutureResponseWriter |
private static class |
ApplicationHandler.WorkersToStringTransform<T> |
Modifier and Type | Field and Description |
---|---|
private javax.ws.rs.core.Application |
application |
private java.lang.Iterable<ContainerLifecycleListener> |
containerLifecycleListeners |
private static javax.ws.rs.core.SecurityContext |
DEFAULT_SECURITY_CONTEXT
Default dummy security context.
|
private org.glassfish.hk2.api.ServiceLocator |
locator |
private static java.util.logging.Logger |
LOGGER |
private MessageBodyWorkers |
msgBodyWorkers |
private ServerRuntime |
runtime |
private ResourceConfig |
runtimeConfig |
Constructor and Description |
---|
ApplicationHandler()
Create a new Jersey application handler using a default configuration.
|
ApplicationHandler(javax.ws.rs.core.Application application)
Create a new Jersey server-side application handler configured by an instance
of a
JAX-RS Application sub-class . |
ApplicationHandler(javax.ws.rs.core.Application application,
org.glassfish.hk2.utilities.Binder customBinder)
Create a new Jersey server-side application handler configured by an instance
of a
ResourceConfig and a custom Binder . |
ApplicationHandler(javax.ws.rs.core.Application application,
org.glassfish.hk2.utilities.Binder customBinder,
org.glassfish.hk2.api.ServiceLocator parent)
Create a new Jersey server-side application handler configured by an instance
of a
ResourceConfig , custom Binder and a parent ServiceLocator . |
ApplicationHandler(java.lang.Class<? extends javax.ws.rs.core.Application> jaxrsApplicationClass)
Create a new Jersey server-side application handler configured by a
JAX-RS Application (sub-)class . |
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.Future<ContainerResponse> |
apply(ContainerRequest requestContext)
Invokes a request and returns the
response future . |
java.util.concurrent.Future<ContainerResponse> |
apply(ContainerRequest request,
java.io.OutputStream outputStream)
Invokes a request and returns the
response future . |
private void |
bindEnhancingResourceClasses(ResourceModel resourceModel,
ResourceBag resourceBag,
java.lang.Iterable<ComponentProvider> componentProviders) |
private void |
bindProvidersAndResources(java.lang.Iterable<ComponentProvider> componentProviders,
ComponentBag componentBag,
java.util.Collection<java.lang.Class<?>> resourceClasses,
java.util.Collection<java.lang.Object> resourceInstances) |
private boolean |
bindWithComponentProvider(java.lang.Class<?> component,
ContractProvider providerModel,
java.lang.Iterable<ComponentProvider> componentProviders) |
private javax.ws.rs.core.Application |
createApplication(java.lang.Class<? extends javax.ws.rs.core.Application> applicationClass,
Value<java.lang.Iterable<ComponentProvider>> componentProvidersValue) |
private static <T> javax.ws.rs.core.MultivaluedMap<java.lang.Class<? extends java.lang.annotation.Annotation>,RankedProvider<T>> |
filterNameBound(java.lang.Iterable<RankedProvider<T>> all,
java.util.Collection<RankedProvider<javax.ws.rs.container.ContainerRequestFilter>> preMatchingFilters,
ComponentBag componentBag,
java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> applicationNameBindings,
javax.ws.rs.core.MultivaluedMap<RankedProvider<T>,java.lang.Class<? extends java.lang.annotation.Annotation>> inverseNameBoundMap)
Takes collection of all filters/interceptors (either request/reader or response/writer)
and separates out all name-bound filters/interceptors, returns them as a separate MultivaluedMap,
mapping the name-bound annotation to the list of name-bound filters/interceptors.
|
ResourceConfig |
getConfiguration()
Get the application configuration.
|
private static LazyValue<java.lang.Iterable<ComponentProvider>> |
getLazyInitializedComponentProviders(org.glassfish.hk2.api.ServiceLocator locator) |
private ProcessingProviders |
getProcessingProviders(ComponentBag componentBag) |
private static java.lang.Iterable<RankedProvider<ComponentProvider>> |
getRankedComponentProviders() |
org.glassfish.hk2.api.ServiceLocator |
getServiceLocator()
Returns
ServiceLocator relevant to current application. |
void |
handle(ContainerRequest request)
The main request/response processing entry point for Jersey container implementations.
|
private ServerRuntime |
initialize(java.lang.Iterable<ComponentProvider> componentProviders)
Assumes the configuration field is initialized with a valid ResourceConfig.
|
private static void |
logApplicationInitConfiguration(org.glassfish.hk2.api.ServiceLocator locator,
ResourceBag resourceBag,
ProcessingProviders processingProviders) |
void |
onReload(Container container)
Invoked when the
container has been reloaded. |
void |
onShutdown(Container container)
Invoke at the
container shut-down. |
void |
onStartup(Container container)
Invoked at the
container start-up. |
private static <T> void |
printNameBoundProviders(java.lang.String title,
java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<RankedProvider<T>>> providers,
java.lang.StringBuilder sb) |
private static <T> void |
printProviders(java.lang.String title,
java.lang.Iterable<T> providers,
java.lang.StringBuilder sb) |
private ResourceModel |
processResourceModel(ResourceModel resourceModel) |
private static final java.util.logging.Logger LOGGER
private static final javax.ws.rs.core.SecurityContext DEFAULT_SECURITY_CONTEXT
private final javax.ws.rs.core.Application application
private final ResourceConfig runtimeConfig
private final org.glassfish.hk2.api.ServiceLocator locator
private final ServerRuntime runtime
private final java.lang.Iterable<ContainerLifecycleListener> containerLifecycleListeners
private MessageBodyWorkers msgBodyWorkers
public ApplicationHandler()
public ApplicationHandler(java.lang.Class<? extends javax.ws.rs.core.Application> jaxrsApplicationClass)
JAX-RS Application (sub-)class
.jaxrsApplicationClass
- JAX-RS Application
(sub-)class that will be
instantiated and used to configure the new Jersey
application handler.public ApplicationHandler(javax.ws.rs.core.Application application)
JAX-RS Application sub-class
.application
- an instance of a JAX-RS Application
(sub-)class that
will be used to configure the new Jersey application handler.public ApplicationHandler(javax.ws.rs.core.Application application, org.glassfish.hk2.utilities.Binder customBinder)
ResourceConfig
and a custom Binder
.application
- an instance of a JAX-RS Application
(sub-)class that
will be used to configure the new Jersey application handler.customBinder
- additional custom bindings used to configure the application's ServiceLocator
.public ApplicationHandler(javax.ws.rs.core.Application application, org.glassfish.hk2.utilities.Binder customBinder, org.glassfish.hk2.api.ServiceLocator parent)
ResourceConfig
, custom Binder
and a parent ServiceLocator
.application
- an instance of a JAX-RS Application
(sub-)class that
will be used to configure the new Jersey application handler.customBinder
- additional custom bindings used during ServiceLocator
creation.parent
- parent ServiceLocator
instance.private javax.ws.rs.core.Application createApplication(java.lang.Class<? extends javax.ws.rs.core.Application> applicationClass, Value<java.lang.Iterable<ComponentProvider>> componentProvidersValue)
private static LazyValue<java.lang.Iterable<ComponentProvider>> getLazyInitializedComponentProviders(org.glassfish.hk2.api.ServiceLocator locator)
private ServerRuntime initialize(java.lang.Iterable<ComponentProvider> componentProviders)
private static void logApplicationInitConfiguration(org.glassfish.hk2.api.ServiceLocator locator, ResourceBag resourceBag, ProcessingProviders processingProviders)
private static <T> void printNameBoundProviders(java.lang.String title, java.util.Map<java.lang.Class<? extends java.lang.annotation.Annotation>,java.util.List<RankedProvider<T>>> providers, java.lang.StringBuilder sb)
private static <T> void printProviders(java.lang.String title, java.lang.Iterable<T> providers, java.lang.StringBuilder sb)
private static java.lang.Iterable<RankedProvider<ComponentProvider>> getRankedComponentProviders() throws ServiceConfigurationError
ServiceConfigurationError
private ProcessingProviders getProcessingProviders(ComponentBag componentBag)
private ResourceModel processResourceModel(ResourceModel resourceModel)
private void bindEnhancingResourceClasses(ResourceModel resourceModel, ResourceBag resourceBag, java.lang.Iterable<ComponentProvider> componentProviders)
private static <T> javax.ws.rs.core.MultivaluedMap<java.lang.Class<? extends java.lang.annotation.Annotation>,RankedProvider<T>> filterNameBound(java.lang.Iterable<RankedProvider<T>> all, java.util.Collection<RankedProvider<javax.ws.rs.container.ContainerRequestFilter>> preMatchingFilters, ComponentBag componentBag, java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> applicationNameBindings, javax.ws.rs.core.MultivaluedMap<RankedProvider<T>,java.lang.Class<? extends java.lang.annotation.Annotation>> inverseNameBoundMap)
inverseNameBoundMap
.
Note, the name-bound filters/interceptors are removed from the original filters/interceptors collection.
If non-null collection is passed in the postMatching parameter (applicable for filters only),
this method also removes all the global
postMatching filters from the original collection and adds them to the collection passed in the postMatching
parameter.all
- Collection of all filters to be processed.preMatchingFilters
- Collection into which pre-matching filters should be added.componentBag
- Component bagapplicationNameBindings
- Collection of name binding annotations attached to the JAX-RS application.inverseNameBoundMap
- Inverse name bound map into which the name bound providers should be inserted. The keys
are providers (filters, interceptor)MultivaluedMap
of all name-bound filters.private void bindProvidersAndResources(java.lang.Iterable<ComponentProvider> componentProviders, ComponentBag componentBag, java.util.Collection<java.lang.Class<?>> resourceClasses, java.util.Collection<java.lang.Object> resourceInstances)
private boolean bindWithComponentProvider(java.lang.Class<?> component, ContractProvider providerModel, java.lang.Iterable<ComponentProvider> componentProviders)
public java.util.concurrent.Future<ContainerResponse> apply(ContainerRequest requestContext)
response future
.requestContext
- request data.public java.util.concurrent.Future<ContainerResponse> apply(ContainerRequest request, java.io.OutputStream outputStream)
response future
.request
- request data.outputStream
- response output stream.public void handle(ContainerRequest request)
The method invokes the request processing of the provided
container request context
and uses the
container response writer
to suspend & resume the processing
as well as write the response back to the container.
The the security context
stored in the container request context
is bound as an injectable instance in the scope of the processed request context.
Also, any custom scope injections
are initialized in the current request scope.
request
- container request context of the current request.public org.glassfish.hk2.api.ServiceLocator getServiceLocator()
ServiceLocator
relevant to current application.ServiceLocator
instance.public ResourceConfig getConfiguration()
public void onStartup(Container container)
ContainerLifecycleListener
container
start-up. This method is invoked even
when application is reloaded and new instance of application has started.onStartup
in interface ContainerLifecycleListener
container
- container that has been started.public void onReload(Container container)
ContainerLifecycleListener
container
has been reloaded.onReload
in interface ContainerLifecycleListener
container
- container that has been reloaded.public void onShutdown(Container container)
ContainerLifecycleListener
container
shut-down. This method is invoked even before
the application is being stopped as a part of reload.onShutdown
in interface ContainerLifecycleListener
container
- container that has been shut down.