All Implemented Interfaces:
FeatureInstaller, BindingInstaller, JerseyInstaller<Object>, WebInstaller, WithOptions

public class JerseyProviderInstaller extends AbstractJerseyInstaller<Object> implements BindingInstaller
Jersey provider installer. Looks for jersey extension classes and classes annotated with Provider and register bindings in HK context.

Registration by extension type might be disabled using InstallersOptions.JerseyExtensionsRecognizedByType option (for legacy behaviour - register classed only annotated with Provider).

By default, user providers are prioritized (with Custom qualifier). This is the default dropwizard behaviour for direct provider registration with environment.jersey().register(provider) and so installer behaves the same. Without it ambiguous situations are possible when dropwizard default providers used instead (e.g. user provided ExceptionMapper<Throwable> not used at all because of dropwizard's one). Auto qualification may be disabled with InstallersOptions.PrioritizeJerseyExtensions (to mimic older guicey versions behaviour). When auto prioritization disabled, Custom annotation may be used directly (to prioritize exact providers).

Priority may be used to order providers (see Priorities for the default priority constants).

If provider is annotated with JerseyManaged it's instance will be created by HK2, not guice. This is important when extensions directly depends on HK beans (no way to wrap with Provider or if it's eager extension, which instantiated by HK immediately (when hk-guice contexts not linked yet).

In some cases LazyBinding could be an alternative to JerseyManaged

Force singleton scope for extensions, but not for beans having explicit scope annotation. See InstallersOptions.ForceSingletonForJerseyExtensions. Prototype annotation may be used on guice beans to declare bean in prototype scope (prevent forced singleton).

Since:
10.10.2014
See Also:
  • Constructor Details

    • JerseyProviderInstaller

      public JerseyProviderInstaller()
  • Method Details

    • matches

      public boolean matches(Class<?> type)
      Description copied from interface: FeatureInstaller
      NOTE: consider using ru.vyarus.dropwizard.guice.module.installer.util.FeatureUtils to simplify checks (for example, types most likely must be checks to be not abstract).

      When type accepted by any extension it's registered in guice module.

      Specified by:
      matches in interface FeatureInstaller
      Parameters:
      type - type to check
      Returns:
      true if extension recognized, false otherwise
    • bind

      public void bind(com.google.inject.Binder binder, Class<?> type, boolean lazyMarker)
      Description copied from interface: BindingInstaller
      Called to apply custom binding for installed feature. By default, all found extensions are installed as binder.bind(type). This method will be called instead of default registration.

      Called only for non binding extensions (extensions that are not already bound in guice module.

      WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.

      Specified by:
      bind in interface BindingInstaller
      Parameters:
      binder - guice binder
      type - extension class
      lazyMarker - true if extension is annotated with LazyBinding
    • manualBinding

      public <T> void manualBinding(com.google.inject.Binder binder, Class<T> type, com.google.inject.Binding<T> binding)
      Description copied from interface: BindingInstaller
      Called for extensions, resolved from guice bindings (in user modules). May be used to validate binding or do some additional bindings with existing binding. Binding is detected primarily by main key Binding.getKey(), but linked bindings (LinkedKeyBinding) are also checked for target key (LinkedKeyBinding.getLinkedKey()).

      LazyBinding flag is not used here because guicey will automatically throw an error if existing binding is annotated as lazy binding (which don't makes any sense).

      WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.

      Specified by:
      manualBinding in interface BindingInstaller
      Type Parameters:
      T - extension type, used to connect extension class with binding
      Parameters:
      binder - guice binder
      type - extension class
      binding - binding declaration from guice module
      See Also:
    • extensionBound

      public void extensionBound(com.google.inject.Stage stage, Class<?> type)
      Description copied from interface: BindingInstaller
      Called after execution of one of above methods. Useful for reporting. Binder is not provided here to avoid confusion with BindingInstaller.bind(Binder, Class, boolean).

      WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.

      Specified by:
      extensionBound in interface BindingInstaller
      Parameters:
      stage - stage (useful for differentiation between normal run (Stage.PRODUCTION) and report rendering (Stage.TOOL)
      type - extension class
    • install

      public void install(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, Class<Object> type)
      Description copied from interface: JerseyInstaller
      Called on jersey start to inject extensions into HK context. Use JerseyBinding utility for proper types binding: it provide utilities for various jersey extensions and use special "bridges" for registration to respect guice scopes (most of the time we not register ready instance, but factory which delegates creation to guice).
      Specified by:
      install in interface JerseyInstaller<Object>
      Parameters:
      binder - hk binder
      injector - guice injector
      type - extension type to register
      See Also:
    • report

      public void report()
      Description copied from interface: FeatureInstaller
      Called to log registered endpoints in dropwizard log fashion. It's important to naturally show all dynamically resolved classes to easily catch errors. Use Reporter to simplify reporting.

      Method may do nothing if reporting not required

      Specified by:
      report in interface FeatureInstaller
    • getRecognizableSigns

      public List<String> getRecognizableSigns()
      Description copied from interface: FeatureInstaller
      Method used by extensions help report (GuiceBundle.Builder.printExtensionsHelp()) to show what signs this exact installer recognize so user could better understand extensions support specifics.
      Specified by:
      getRecognizableSigns in interface FeatureInstaller
      Returns:
      list of extension signs installer recognize