java.lang.Object
ru.vyarus.dropwizard.guice.module.installer.util.JerseyBinding

public final class JerseyBinding extends Object
Jersey binding utilities. Supplement JerseyInstaller.
Since:
21.11.2014
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    bindComponent(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, 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, Class<?> type, boolean jerseyManaged, boolean singleton)
    Binds jersey Supplier.
    static <T> com.google.inject.binder.ScopedBindingBuilder
    bindJerseyComponent(com.google.inject.Binder binder, jakarta.inject.Provider<com.google.inject.Injector> provider, 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, Class<?> type, Class<?> specificType, boolean jerseyManaged, boolean singleton, boolean autoQualify, boolean instanceGuiceBinding)
    Binds jersey specific component (component implements jersey interface or extends class).
    static boolean
     
    static boolean
    isJerseyManaged(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isBridgeAvailable

      public static boolean isBridgeAvailable()
      Returns:
      true if HK2 bridge is available in classpath, false otherwise
    • isJerseyManaged

      public static boolean isJerseyManaged(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 check
      guiceFirstMode - 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:
    • bindComponent

      public static void bindComponent(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, Class<?> type, boolean jerseyManaged, boolean singleton)
      Binds component into jersey context. If component is annotated with JerseyManaged, then registers type, otherwise register guice "bridge" factory around component.
      Parameters:
      binder - jersey binder
      injector - guice injector
      type - component type
      jerseyManaged - true if bean must be managed by jersey, false to bind guice managed instance
      singleton - true to force singleton scope
      See Also:
    • bindFactory

      public static <T> void bindFactory(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, Class<?> type, boolean jerseyManaged, boolean singleton)
      Binds jersey Supplier. If bean is JerseyManaged 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 binder
      injector - guice injector
      type - factory to bind
      jerseyManaged - true if bean must be managed by jersey, false to bind guice managed instance
      singleton - true to force singleton scope
      See Also:
    • bindSpecificComponent

      public static void bindSpecificComponent(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, Class<?> type, 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 binder
      injector - guice injector
      type - type which implements specific jersey interface or extends class
      specificType - specific jersey type (interface or abstract class)
      jerseyManaged - true if bean must be managed by jersey, false to bind guice managed instance
      singleton - true to force singleton scope
      autoQualify - mimic default jersey behaviour by qualifying user providers with @Custom
      instanceGuiceBinding - true to bind by instance instead of factory "wrapper" (required for ModelProcessor extensions due to initialization specifics)
    • bindJerseyComponent

      public static <T> com.google.inject.binder.ScopedBindingBuilder bindJerseyComponent(com.google.inject.Binder binder, jakarta.inject.Provider<com.google.inject.Injector> provider, 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 binder
      provider - provider for guice injector
      type - jersey type to register
      Returns:
      scoped binder object to optionally define binding scope.
      See Also: