Class ApplicationHandler
- java.lang.Object
-
- org.glassfish.jersey.server.ApplicationHandler
-
- All Implemented Interfaces:
ContainerLifecycleListener
public final class ApplicationHandler extends Object implements ContainerLifecycleListener
Jersey server-side application handler.Container implementations use the
ApplicationHandlerAPI to process requests by invoking thehandle(request)method on a configured application handler instance.ApplicationHandlerprovides two implementations ofconfigthat can be injected into the application classes. The first isresource configwhich implementsConfigurationitself 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 asResourceConfigorApplication. The second one can be injected into theConfigurationparameters / 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
ContainerLifecycleListenerinstance 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. Jerseycontainersare expected to invoke the container lifecycle methods directly on the activeApplicationHandlerinstance. 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.- Author:
- Pavel Bucek, Jakub Podlesak, Marek Potociar, Libor Kramolis
- See Also:
ResourceConfig,Configuration,ContainerProvider
-
-
Constructor Summary
Constructors Constructor Description ApplicationHandler()Create a new Jersey application handler using a default configuration.ApplicationHandler(jakarta.ws.rs.core.Application application)Create a new Jersey server-side application handler configured by an instance of aJAX-RS Application sub-class.ApplicationHandler(jakarta.ws.rs.core.Application application, org.glassfish.jersey.internal.inject.Binder customBinder)Create a new Jersey server-side application handler configured by an instance of aResourceConfigand a customBinder.ApplicationHandler(jakarta.ws.rs.core.Application application, org.glassfish.jersey.internal.inject.Binder customBinder, Object parentManager)Create a new Jersey server-side application handler configured by an instance of aResourceConfig, customBinderand a parent used byInjectionManager.ApplicationHandler(Class<? extends jakarta.ws.rs.core.Application> jaxrsApplicationClass)Create a new Jersey server-side application handler configured by aJAX-RS Application (sub-)class.ApplicationHandler(Class<? extends jakarta.ws.rs.core.Application> applicationClass, org.glassfish.jersey.internal.inject.Binder customBinder)Create a new Jersey server-side application handler configured by aJAX-RS Application (sub-)class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Future<ContainerResponse>apply(ContainerRequest requestContext)Invokes a request and returns theresponse future.Future<ContainerResponse>apply(ContainerRequest request, OutputStream outputStream)Invokes a request and returns theresponse future.ResourceConfiggetConfiguration()Get the application configuration.org.glassfish.jersey.internal.inject.InjectionManagergetInjectionManager()ReturnsInjectionManagerrelevant to current application.voidhandle(ContainerRequest request)The main request/response processing entry point for Jersey container implementations.voidonReload(Container container)Invoked when thecontainerhas been reloaded.voidonShutdown(Container container)Invoke at thecontainershut-down.voidonStartup(Container container)Invoked at thecontainerstart-up.
-
-
-
Constructor Detail
-
ApplicationHandler
public ApplicationHandler()
Create a new Jersey application handler using a default configuration.
-
ApplicationHandler
public ApplicationHandler(Class<? extends jakarta.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(Class<? extends jakarta.ws.rs.core.Application> applicationClass, org.glassfish.jersey.internal.inject.Binder customBinder)
Create a new Jersey server-side application handler configured by aJAX-RS Application (sub-)class.- Parameters:
applicationClass- JAX-RSApplication(sub-)class that will be instantiated and used to configure the new Jersey application handler.customBinder- additional custom bindings used to configure the application's.
-
ApplicationHandler
public ApplicationHandler(jakarta.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(jakarta.ws.rs.core.Application application, org.glassfish.jersey.internal.inject.Binder customBinder)Create a new Jersey server-side application handler configured by an instance of aResourceConfigand 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(jakarta.ws.rs.core.Application application, org.glassfish.jersey.internal.inject.Binder customBinder, Object parentManager)Create a new Jersey server-side application handler configured by an instance of aResourceConfig, customBinderand 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 duringInjectionManagercreation.parentManager- parent used inInjectionManagerfor a specific DI provider.
-
-
Method Detail
-
apply
public Future<ContainerResponse> apply(ContainerRequest requestContext)
Invokes a request and returns theresponse future.- Parameters:
requestContext- request data.- Returns:
- response future.
-
apply
public Future<ContainerResponse> apply(ContainerRequest request, 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 contextand uses thecontainer response writerto suspend & resume the processing as well as write the response back to the container.The the
security contextstored in the container request context is bound as an injectable instance in the scope of the processed request context. Also, anycustom scope injectionsare initialized in the current request scope.- Parameters:
request- container request context of the current request.
-
getInjectionManager
public org.glassfish.jersey.internal.inject.InjectionManager getInjectionManager()
ReturnsInjectionManagerrelevant to current application.- Returns:
InjectionManagerinstance.- Since:
- 2.26
-
getConfiguration
public ResourceConfig getConfiguration()
Get the application configuration.- Returns:
- application configuration.
-
onStartup
public void onStartup(Container container)
Description copied from interface:ContainerLifecycleListenerInvoked at thecontainerstart-up. This method is invoked even when application is reloaded and new instance of application has started.- Specified by:
onStartupin interfaceContainerLifecycleListener- Parameters:
container- container that has been started.
-
onReload
public void onReload(Container container)
Description copied from interface:ContainerLifecycleListenerInvoked when thecontainerhas been reloaded.- Specified by:
onReloadin interfaceContainerLifecycleListener- Parameters:
container- container that has been reloaded.
-
onShutdown
public void onShutdown(Container container)
Description copied from interface:ContainerLifecycleListenerInvoke at thecontainershut-down. This method is invoked even before the application is being stopped as a part of reload.- Specified by:
onShutdownin interfaceContainerLifecycleListener- Parameters:
container- container that has been shut down.
-
-