Class JerseyProviderInstaller
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.installer.option.InstallerOptionsSupport
-
- ru.vyarus.dropwizard.guice.module.installer.feature.jersey.AbstractJerseyInstaller<java.lang.Object>
-
- ru.vyarus.dropwizard.guice.module.installer.feature.jersey.provider.JerseyProviderInstaller
-
- All Implemented Interfaces:
FeatureInstaller,BindingInstaller,JerseyInstaller<java.lang.Object>,WebInstaller,WithOptions
public class JerseyProviderInstaller extends AbstractJerseyInstaller<java.lang.Object> implements BindingInstaller
Jersey provider installer. Looks for jersey extension classes and classes annotated withProviderand register bindings in HK context.Registration by extension type might be disabled using
InstallersOptions.JerseyExtensionsRecognizedByTypeoption (for legacy behaviour - register classed only annotated withProvider).By default, user providers are prioritized (with
Customqualifier). This is the default dropwizard behaviour for direct provider registration withenvironment.jersey().register(provider)and so installer behaves the same. Without it ambiguous situations are possible when dropwizard default providers used instead (e.g. user providedExceptionMapper<Throwable>not used at all because of dropwizard's one). Auto qualification may be disabled withInstallersOptions.PrioritizeJerseyExtensions(to mimic older guicey versions behaviour). When auto prioritization disabled,Customannotation may be used directly (to prioritize exact providers).Prioritymay be used to order providers (seePrioritiesfor the default priority constants).If provider is annotated with
JerseyManagedit's instance will be created by HK2, not guice. This is important when extensions directly depends on HK beans (no way to wrap withProvideror if it's eager extension, which instantiated by HK immediately (when hk-guice contexts not linked yet).In some cases
LazyBindingcould be an alternative toJerseyManagedForce singleton scope for extensions, but not for beans having explicit scope annotation. See
InstallersOptions.ForceSingletonForJerseyExtensions.Prototypeannotation may be used on guice beans to declare bean in prototype scope (prevent forced singleton).- Since:
- 10.10.2014
- See Also:
JerseyManaged,GuiceManaged,LazyBinding
-
-
Field Summary
-
Fields inherited from class ru.vyarus.dropwizard.guice.module.installer.feature.jersey.AbstractJerseyInstaller
logger
-
-
Constructor Summary
Constructors Constructor Description JerseyProviderInstaller()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(com.google.inject.Binder binder, java.lang.Class<?> type, boolean lazyMarker)Called to apply custom binding for installed feature.voidextensionBound(com.google.inject.Stage stage, java.lang.Class<?> type)Called after execution of one of above methods.java.util.List<java.lang.String>getRecognizableSigns()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.voidinstall(org.glassfish.jersey.internal.inject.AbstractBinder binder, com.google.inject.Injector injector, java.lang.Class<java.lang.Object> type)Called on jersey start to inject extensions into HK context.<T> voidmanualBinding(com.google.inject.Binder binder, java.lang.Class<T> type, com.google.inject.Binding<T> binding)Called for extensions, resolved from guice bindings (in user modules).booleanmatches(java.lang.Class<?> type)NOTE: consider usingru.vyarus.dropwizard.guice.module.installer.util.FeatureUtilsto simplify checks (for example, types most likely must be checks to be not abstract).voidreport()Called to log registered endpoints in dropwizard log fashion.-
Methods inherited from class ru.vyarus.dropwizard.guice.module.installer.feature.jersey.AbstractJerseyInstaller
bindInGuice, isForceSingleton, isJerseyExtension, isLazy
-
Methods inherited from class ru.vyarus.dropwizard.guice.module.installer.option.InstallerOptionsSupport
option, setOptions
-
-
-
-
Method Detail
-
matches
public boolean matches(java.lang.Class<?> type)
Description copied from interface:FeatureInstallerNOTE: consider usingru.vyarus.dropwizard.guice.module.installer.util.FeatureUtilsto 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:
matchesin interfaceFeatureInstaller- Parameters:
type- type to check- Returns:
- true if extension recognized, false otherwise
-
bind
public void bind(com.google.inject.Binder binder, java.lang.Class<?> type, boolean lazyMarker)Description copied from interface:BindingInstallerCalled to apply custom binding for installed feature. By default, all found extensions are installed asbinder.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:
bindin interfaceBindingInstaller- Parameters:
binder- guice bindertype- extension classlazyMarker- true if extension is annotated withLazyBinding
-
manualBinding
public <T> void manualBinding(com.google.inject.Binder binder, java.lang.Class<T> type, com.google.inject.Binding<T> binding)Description copied from interface:BindingInstallerCalled 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 keyBinding.getKey(), but linked bindings (LinkedKeyBinding) are also checked for target key (LinkedKeyBinding.getLinkedKey()).LazyBindingflag 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:
manualBindingin interfaceBindingInstaller- Type Parameters:
T- extension type, used to connect extension class with binding- Parameters:
binder- guice bindertype- extension classbinding- binding declaration from guice module- See Also:
for errors reporting
-
extensionBound
public void extensionBound(com.google.inject.Stage stage, java.lang.Class<?> type)Description copied from interface:BindingInstallerCalled after execution of one of above methods. Useful for reporting.Binderis not provided here to avoid confusion withBindingInstaller.bind(Binder, Class, boolean).WARNING: may be called multiple times due to enabled bindings reporting! Be sure to produce correct logs.
- Specified by:
extensionBoundin interfaceBindingInstaller- 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, java.lang.Class<java.lang.Object> type)Description copied from interface:JerseyInstallerCalled on jersey start to inject extensions into HK context. UseJerseyBindingutility 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:
installin interfaceJerseyInstaller<java.lang.Object>- Parameters:
binder- hk binderinjector- guice injectortype- extension type to register- See Also:
JerseyBinding,JerseyManaged
-
report
public void report()
Description copied from interface:FeatureInstallerCalled to log registered endpoints in dropwizard log fashion. It's important to naturally show all dynamically resolved classes to easily catch errors. UseReporterto simplify reporting.Method may do nothing if reporting not required
- Specified by:
reportin interfaceFeatureInstaller
-
getRecognizableSigns
public java.util.List<java.lang.String> getRecognizableSigns()
Description copied from interface:FeatureInstallerMethod 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:
getRecognizableSignsin interfaceFeatureInstaller- Returns:
- list of extension signs installer recognize
-
-