Class ApplicationHandler
- java.lang.Object
-
- org.glassfish.jersey.server.ApplicationHandler
-
- All Implemented Interfaces:
ContainerLifecycleListener
public final class ApplicationHandler extends java.lang.Object implements ContainerLifecycleListener
Jersey server-side application handler.Container implementations use the
ApplicationHandler
API to process requests by invoking thehandle(request)
method on a configured application handler instance.ApplicationHandler
provides two implementations ofconfig
that can be injected into the application classes. The first isresource config
which implementsConfiguration
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 asResourceConfig
orApplication
. The second one can be injected into theConfiguration
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 underserver 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. Jerseycontainers
are expected to invoke the container lifecycle methods directly on the activeApplicationHandler
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 theContainerLifecycleListener.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-specificinjection manager
.- See Also:
ResourceConfig
,Configuration
,ContainerProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ApplicationHandler.FutureResponseWriter
private class
ApplicationHandler.RuntimeConfigConfigurator
Configurator which initializes and registerApplicationHandler
andConfiguration
instances intoInjectionManager
andBootstrapBag
.private static class
ApplicationHandler.WorkersToStringTransform<T>
-
Field Summary
Fields Modifier and Type Field 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 InjectionManager
injectionManager
private static java.util.logging.Logger
LOGGER
private ManagedObjectsFinalizer
managedObjectsFinalizer
private MessageBodyWorkers
msgBodyWorkers
private ServerRuntime
runtime
private ResourceConfig
runtimeConfig
-
Constructor Summary
Constructors Constructor Description ApplicationHandler()
Create a new Jersey application handler using a default configuration.ApplicationHandler(java.lang.Class<? extends javax.ws.rs.core.Application> jaxrsApplicationClass)
Create a new Jersey server-side application handler configured by aJAX-RS Application (sub-)class
.ApplicationHandler(javax.ws.rs.core.Application application)
Create a new Jersey server-side application handler configured by an instance of aJAX-RS Application sub-class
.ApplicationHandler(javax.ws.rs.core.Application application, Binder customBinder)
Create a new Jersey server-side application handler configured by an instance of aResourceConfig
and a customBinder
.ApplicationHandler(javax.ws.rs.core.Application application, Binder customBinder, java.lang.Object parentManager)
Create a new Jersey server-side application handler configured by an instance of aResourceConfig
, customBinder
and a parent used byInjectionManager
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.Future<ContainerResponse>
apply(ContainerRequest requestContext)
Invokes a request and returns theresponse future
.java.util.concurrent.Future<ContainerResponse>
apply(ContainerRequest request, java.io.OutputStream outputStream)
Invokes a request and returns theresponse future
.private boolean
disableValidation()
ResourceConfig
getConfiguration()
Get the application configuration.InjectionManager
getInjectionManager()
ReturnsInjectionManager
relevant to current application.void
handle(ContainerRequest request)
The main request/response processing entry point for Jersey container implementations.private boolean
ignoreValidationError()
private ServerRuntime
initialize(InjectionManager injectionManager, java.util.List<BootstrapConfigurator> bootstrapConfigurators, ServerBootstrapBag bootstrapBag)
Assumes the configuration field is initialized with a valid ResourceConfig.private void
initialize(ApplicationConfigurator applicationConfigurator, InjectionManager injectionManager, Binder customBinder)
private static void
logApplicationInitConfiguration(InjectionManager injectionManager, ResourceBag resourceBag, ProcessingProviders processingProviders)
void
onReload(Container container)
Invoked when thecontainer
has been reloaded.void
onShutdown(Container container)
Invoke at thecontainer
shut-down.void
onStartup(Container container)
Invoked at thecontainer
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)
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
DEFAULT_SECURITY_CONTEXT
private static final javax.ws.rs.core.SecurityContext DEFAULT_SECURITY_CONTEXT
Default dummy security context.
-
application
private javax.ws.rs.core.Application application
-
runtimeConfig
private ResourceConfig runtimeConfig
-
runtime
private ServerRuntime runtime
-
containerLifecycleListeners
private java.lang.Iterable<ContainerLifecycleListener> containerLifecycleListeners
-
injectionManager
private InjectionManager injectionManager
-
msgBodyWorkers
private MessageBodyWorkers msgBodyWorkers
-
managedObjectsFinalizer
private ManagedObjectsFinalizer managedObjectsFinalizer
-
-
Constructor Detail
-
ApplicationHandler
public ApplicationHandler()
Create a new Jersey application handler using a default configuration.
-
ApplicationHandler
public ApplicationHandler(java.lang.Class<? extends javax.ws.rs.core.Application> jaxrsApplicationClass)
Create a new Jersey server-side application handler configured by aJAX-RS Application (sub-)class
.- Parameters:
jaxrsApplicationClass
- JAX-RSApplication
(sub-)class that will be instantiated and used to configure the new Jersey application handler.
-
ApplicationHandler
public ApplicationHandler(javax.ws.rs.core.Application application)
Create a new Jersey server-side application handler configured by an instance of aJAX-RS Application sub-class
.- Parameters:
application
- an instance of a JAX-RSApplication
(sub-)class that will be used to configure the new Jersey application handler.
-
ApplicationHandler
public ApplicationHandler(javax.ws.rs.core.Application application, Binder customBinder)
Create a new Jersey server-side application handler configured by an instance of aResourceConfig
and a customBinder
.- Parameters:
application
- an instance of a JAX-RSApplication
(sub-)class that will be used to configure the new Jersey application handler.customBinder
- additional custom bindings used to configure the application's.
-
ApplicationHandler
public ApplicationHandler(javax.ws.rs.core.Application application, Binder customBinder, java.lang.Object parentManager)
Create a new Jersey server-side application handler configured by an instance of aResourceConfig
, customBinder
and a parent used byInjectionManager
.- Parameters:
application
- an instance of a JAX-RSApplication
(sub-)class that will be used to configure the new Jersey application handler.customBinder
- additional custom bindings used duringInjectionManager
creation.parentManager
- parent used inInjectionManager
for a specific DI provider.
-
-
Method Detail
-
initialize
private void initialize(ApplicationConfigurator applicationConfigurator, InjectionManager injectionManager, Binder customBinder)
-
initialize
private ServerRuntime initialize(InjectionManager injectionManager, java.util.List<BootstrapConfigurator> bootstrapConfigurators, ServerBootstrapBag bootstrapBag)
Assumes the configuration field is initialized with a valid ResourceConfig.
-
ignoreValidationError
private boolean ignoreValidationError()
-
disableValidation
private boolean disableValidation()
-
logApplicationInitConfiguration
private static void logApplicationInitConfiguration(InjectionManager injectionManager, ResourceBag resourceBag, ProcessingProviders processingProviders)
-
printNameBoundProviders
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)
-
printProviders
private static <T> void printProviders(java.lang.String title, java.lang.Iterable<T> providers, java.lang.StringBuilder sb)
-
apply
public java.util.concurrent.Future<ContainerResponse> apply(ContainerRequest requestContext)
Invokes a request and returns theresponse future
.- Parameters:
requestContext
- request data.- Returns:
- response future.
-
apply
public java.util.concurrent.Future<ContainerResponse> apply(ContainerRequest request, java.io.OutputStream outputStream)
Invokes a request and returns theresponse future
.- Parameters:
request
- request data.outputStream
- response output stream.- Returns:
- response future.
-
handle
public void handle(ContainerRequest request)
The main request/response processing entry point for Jersey container implementations.The method invokes the request processing of the provided
container request context
and uses thecontainer 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, anycustom scope injections
are initialized in the current request scope.- Parameters:
request
- container request context of the current request.
-
getInjectionManager
public InjectionManager getInjectionManager()
ReturnsInjectionManager
relevant to current application.- Returns:
InjectionManager
instance.- Since:
- 2.26
-
getConfiguration
public ResourceConfig getConfiguration()
Get the application configuration.- Returns:
- application configuration.
-
onStartup
public void onStartup(Container container)
Description copied from interface:ContainerLifecycleListener
Invoked at thecontainer
start-up. This method is invoked even when application is reloaded and new instance of application has started.- Specified by:
onStartup
in interfaceContainerLifecycleListener
- Parameters:
container
- container that has been started.
-
onReload
public void onReload(Container container)
Description copied from interface:ContainerLifecycleListener
Invoked when thecontainer
has been reloaded.- Specified by:
onReload
in interfaceContainerLifecycleListener
- Parameters:
container
- container that has been reloaded.
-
onShutdown
public void onShutdown(Container container)
Description copied from interface:ContainerLifecycleListener
Invoke at thecontainer
shut-down. This method is invoked even before the application is being stopped as a part of reload.- Specified by:
onShutdown
in interfaceContainerLifecycleListener
- Parameters:
container
- container that has been shut down.
-
-