Class JerseyResourceContext
- java.lang.Object
-
- org.glassfish.jersey.server.internal.JerseyResourceContext
-
- All Implemented Interfaces:
javax.ws.rs.container.ResourceContext
,ExtendedResourceContext
public class JerseyResourceContext extends java.lang.Object implements ExtendedResourceContext
Jersey implementation of JAX-RSresource context
.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.Class<?>>
bindingCache
private java.lang.Object
bindingCacheLock
private java.util.function.Function<java.lang.Class<?>,?>
getOrCreateInstance
private java.util.function.Consumer<java.lang.Object>
injectInstance
private java.util.function.Consumer<Binding>
registerBinding
private ResourceModel
resourceModel
-
Constructor Summary
Constructors Constructor Description JerseyResourceContext(java.util.function.Function<java.lang.Class<?>,?> getOrCreateInstance, java.util.function.Consumer<java.lang.Object> injectInstance, java.util.function.Consumer<Binding> registerBinding)
Creates a new JerseyResourceContext.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> void
bindResource(java.lang.Class<T> resourceClass)
BindsresourceClass
into HK2 context as singleton.<T> void
bindResourceIfSingleton(T resource)
BindsresourceClass
into HK2 context as singleton.<T> T
getResource(java.lang.Class<T> resourceClass)
ResourceModel
getResourceModel()
Returnresource model
from which the current jersey application is built.private static java.lang.Class<? extends java.lang.annotation.Annotation>
getScope(java.lang.Class<?> resourceClass)
<T> T
initResource(T resource)
void
setResourceModel(ResourceModel resourceModel)
Set theresource mode
of the application associated with this context.<T> void
unsafeBindResource(java.lang.Class<T> resourceClass, ContractProvider providerModel)
Bind a resource class in a HK2 context.void
unsafeBindResource(java.lang.Object resource, ContractProvider providerModel)
Bind a resource instance in a InjectionManager.
-
-
-
Field Detail
-
getOrCreateInstance
private final java.util.function.Function<java.lang.Class<?>,?> getOrCreateInstance
-
injectInstance
private final java.util.function.Consumer<java.lang.Object> injectInstance
-
registerBinding
private final java.util.function.Consumer<Binding> registerBinding
-
bindingCache
private final java.util.Set<java.lang.Class<?>> bindingCache
-
bindingCacheLock
private final java.lang.Object bindingCacheLock
-
resourceModel
private volatile ResourceModel resourceModel
-
-
Constructor Detail
-
JerseyResourceContext
public JerseyResourceContext(java.util.function.Function<java.lang.Class<?>,?> getOrCreateInstance, java.util.function.Consumer<java.lang.Object> injectInstance, java.util.function.Consumer<Binding> registerBinding)
Creates a new JerseyResourceContext.- Parameters:
getOrCreateInstance
- function to create or get existing instance.injectInstance
- consumer to inject instances into an unmanaged instance.registerBinding
- consumer to register a new binding into injection manager.
-
-
Method Detail
-
getResource
public <T> T getResource(java.lang.Class<T> resourceClass)
- Specified by:
getResource
in interfacejavax.ws.rs.container.ResourceContext
-
initResource
public <T> T initResource(T resource)
- Specified by:
initResource
in interfacejavax.ws.rs.container.ResourceContext
-
bindResource
public <T> void bindResource(java.lang.Class<T> resourceClass)
BindsresourceClass
into HK2 context as singleton. The bound class is then cached internally so that any sub-sequent attempt to bind that class as a singleton is silently ignored.- Type Parameters:
T
- type of the resource class.- Parameters:
resourceClass
- resource class that should be bound. If the class is not annotated withSingleton annotation
it will be ignored by this method.
-
bindResourceIfSingleton
public <T> void bindResourceIfSingleton(T resource)
BindsresourceClass
into HK2 context as singleton. The bound class is then cached internally so that any sub-sequent attempt to bind that class as a singleton is silently ignored.- Parameters:
resource
- singleton resource instance that should be bound as singleton. If the class is not annotated withSingleton annotation
it will be ignored by this method.
-
unsafeBindResource
public void unsafeBindResource(java.lang.Object resource, ContractProvider providerModel)
Bind a resource instance in a InjectionManager. The bound resource instance is internally cached to make sure any sub-sequent attempts to service the class are silently ignored.WARNING: This version of method is not synchronized as well as the cache is not checked for existing bindings before the resource is bound and cached.
- Parameters:
resource
- resource instance to be bound.providerModel
- provider model for the resource class. If notnull
, the class wil be bound as a contract provider too.
-
getScope
private static java.lang.Class<? extends java.lang.annotation.Annotation> getScope(java.lang.Class<?> resourceClass)
-
unsafeBindResource
public <T> void unsafeBindResource(java.lang.Class<T> resourceClass, ContractProvider providerModel)
Bind a resource class in a HK2 context. The bound resource class is internally cached to make sure any sub-sequent attempts to bind the class are silently ignored.WARNING: This version of method is not synchronized as well as the cache is not checked for existing bindings before the resource is bound and cached.
- Type Parameters:
T
- resource class type.- Parameters:
resourceClass
- resource class to be bound.providerModel
- provider model for the class. If notnull
, the class wil be bound as a contract provider too.
-
getResourceModel
public ResourceModel getResourceModel()
Description copied from interface:ExtendedResourceContext
Returnresource model
from which the current jersey application is built.- Specified by:
getResourceModel
in interfaceExtendedResourceContext
- Returns:
- Resource model with all resources including resources created
by
resource processor
.
-
setResourceModel
public void setResourceModel(ResourceModel resourceModel)
Set theresource mode
of the application associated with this context.- Parameters:
resourceModel
- Resource model on which theapplication
is based.
-
-