Class JerseyBinding
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.installer.util.JerseyBinding
-
public final class JerseyBinding extends java.lang.Object
Jersey binding utilities. SupplementJerseyInstaller
.- Since:
- 21.11.2014
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
bindComponent(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<?> type, boolean jerseyManaged, boolean singleton)
Binds component into jersey context.static <T> void
bindFactory(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<?> type, boolean jerseyManaged, boolean singleton)
Binds jerseySupplier
.static <T> com.google.inject.binder.ScopedBindingBuilder
bindJerseyComponent(com.google.inject.Binder binder, javax.inject.Provider<com.google.inject.Injector> provider, java.lang.Class<T> type)
Used to bind jersey beans in guice context (lazily).static void
bindSpecificComponent(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<?> type, java.lang.Class<?> specificType, boolean jerseyManaged, boolean singleton, boolean autoQualify, boolean instanceGuiceBinding)
Binds jersey specific component (component implements jersey interface or extends class).static boolean
isBridgeAvailable()
static boolean
isJerseyManaged(java.lang.Class<?> type, boolean guiceFirstMode)
When guice-first mode used (default) all jersey extensions are instantiated by guice and only if JerseyManaged annotation set on bean - it will be instantiated by jersey.
-
-
-
Method Detail
-
isBridgeAvailable
public static boolean isBridgeAvailable()
- Returns:
- true if HK2 bridge is available in classpath, false otherwise
-
isJerseyManaged
public static boolean isJerseyManaged(java.lang.Class<?> type, boolean guiceFirstMode)
When guice-first mode used (default) all jersey extensions are instantiated by guice and only if JerseyManaged annotation set on bean - it will be instantiated by jersey.When jersey-first mode used (InstallersOptions.JerseyExtensionsManagedByGuice) all jersey extensions are instantiated by jersey and only if GuiceManaged annotation set on bean - it will be instantiated by guice.
- Parameters:
type
- type to checkguiceFirstMode
- true when guice used by default for jersey extensions management, false when jersey used by default- Returns:
- true if type should be managed by jersey, false when type should managed by guice.
- See Also:
InstallersOptions.JerseyExtensionsManagedByGuice
,JerseyManaged
,GuiceManaged
-
bindComponent
public static void bindComponent(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<?> type, boolean jerseyManaged, boolean singleton)
Binds component into jersey context. If component is annotated withJerseyManaged
, then registers type, otherwise register guice "bridge" factory around component.- Parameters:
binder
- jersey binderinjector
- guice injectortype
- component typejerseyManaged
- true if bean must be managed by jersey, false to bind guice managed instancesingleton
- true to force singleton scope- See Also:
GuiceComponentFactory
-
bindFactory
public static <T> void bindFactory(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<?> type, boolean jerseyManaged, boolean singleton)
Binds jerseySupplier
. If bean isJerseyManaged
then registered directly as factory. Otherwise, register factory through special "lazy bridge" to delay guice factory bean instantiation. Also registers factory directly (through wrapper to be able to inject factory by its type).NOTE: since jersey 2.26 jersey don't use hk2 directly and so all HK interfaces replaced by java 8 interfaces.
- Type Parameters:
T
- actual type (used to workaround type checks)- Parameters:
binder
- jersey binderinjector
- guice injectortype
- factory to bindjerseyManaged
- true if bean must be managed by jersey, false to bind guice managed instancesingleton
- true to force singleton scope- See Also:
LazyGuiceFactory
,GuiceComponentFactory
-
bindSpecificComponent
public static void bindSpecificComponent(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<?> type, java.lang.Class<?> specificType, boolean jerseyManaged, boolean singleton, boolean autoQualify, boolean instanceGuiceBinding)
Binds jersey specific component (component implements jersey interface or extends class). Specific binding is required for types directly supported by jersey (e.g. ExceptionMapper). Such types must be bound to target interface directly, otherwise jersey would not be able to resolve them.If type is
JerseyManaged
, binds directly. Otherwise, use guice "bridge" factory to lazily bind type.- Parameters:
binder
- jersey binderinjector
- guice injectortype
- type which implements specific jersey interface or extends classspecificType
- specific jersey type (interface or abstract class)jerseyManaged
- true if bean must be managed by jersey, false to bind guice managed instancesingleton
- true to force singleton scopeautoQualify
- mimic default jersey behaviour by qualifying user providers with @CustominstanceGuiceBinding
- true to bind by instance instead of factory "wrapper" (required forModelProcessor
extensions due to initialization specifics)
-
bindJerseyComponent
public static <T> com.google.inject.binder.ScopedBindingBuilder bindJerseyComponent(com.google.inject.Binder binder, javax.inject.Provider<com.google.inject.Injector> provider, java.lang.Class<T> type)
Used to bind jersey beans in guice context (lazily). Guice context is started first, so there is no way to bind instances. Instead, "lazy bridge" installed, which will resolve target type on first call. Guice is not completely started and direct injector lookup is impossible here, so lazy injector provider used.- Type Parameters:
T
- type- Parameters:
binder
- guice binderprovider
- provider for guice injectortype
- jersey type to register- Returns:
- scoped binder object to optionally define binding scope.
- See Also:
InjectorProvider
-
-