use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class MonitoringFeature method configure.
@Override
public boolean configure(FeatureContext context) {
final Boolean monitoringEnabledProperty = ServerProperties.getValue(context.getConfiguration().getProperties(), ServerProperties.MONITORING_ENABLED, null, Boolean.class);
final Boolean statisticsEnabledProperty = ServerProperties.getValue(context.getConfiguration().getProperties(), ServerProperties.MONITORING_STATISTICS_ENABLED, null, Boolean.class);
final Boolean mbeansEnabledProperty = ServerProperties.getValue(context.getConfiguration().getProperties(), ServerProperties.MONITORING_STATISTICS_MBEANS_ENABLED, null, Boolean.class);
if (monitoringEnabledProperty != null) {
monitoringEnabled = monitoringEnabledProperty;
// monitoring statistics are enabled by default if monitoring is enabled
statisticsEnabled = monitoringEnabled;
}
if (statisticsEnabledProperty != null) {
monitoringEnabled = monitoringEnabled || statisticsEnabledProperty;
statisticsEnabled = statisticsEnabledProperty;
}
if (mbeansEnabledProperty != null) {
monitoringEnabled = monitoringEnabled || mbeansEnabledProperty;
statisticsEnabled = statisticsEnabled || mbeansEnabledProperty;
mBeansEnabled = mbeansEnabledProperty;
}
if (statisticsEnabledProperty != null && !statisticsEnabledProperty) {
if (mbeansEnabledProperty != null && mBeansEnabled) {
LOGGER.log(Level.WARNING, LocalizationMessages.WARNING_MONITORING_FEATURE_ENABLED(ServerProperties.MONITORING_STATISTICS_ENABLED));
} else {
LOGGER.log(Level.WARNING, LocalizationMessages.WARNING_MONITORING_FEATURE_DISABLED(ServerProperties.MONITORING_STATISTICS_ENABLED));
}
}
if (monitoringEnabled) {
context.register(ApplicationInfoListener.class);
context.register(new AbstractBinder() {
@Override
protected void configure() {
bindFactory(ReferencingFactory.<ApplicationInfo>referenceFactory()).to(new GenericType<Ref<ApplicationInfo>>() {
}).in(Singleton.class);
bindFactory(ApplicationInfoInjectionFactory.class).to(ApplicationInfo.class);
}
});
}
if (statisticsEnabled) {
context.register(MonitoringEventListener.class);
context.register(new AbstractBinder() {
@Override
protected void configure() {
bindFactory(ReferencingFactory.<MonitoringStatistics>referenceFactory()).to(new GenericType<Ref<MonitoringStatistics>>() {
}).in(Singleton.class);
bindFactory(StatisticsInjectionFactory.class).to(MonitoringStatistics.class);
bind(StatisticsListener.class).to(MonitoringStatisticsListener.class).in(Singleton.class);
}
});
}
if (mBeansEnabled) {
// instance registration is needed here as MBeanExposer needs to be a singleton so that
// one instance handles listening to events of MonitoringStatisticsListener and ContainerLifecycleListener
context.register(new MBeanExposer());
}
return monitoringEnabled;
}
use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class CommonConfigTest method testFeatureInjections.
@Test
public void testFeatureInjections() throws Exception {
config.register(InjectIntoFeatureClass.class).register(new InjectIntoFeatureInstance()).register(new AbstractBinder() {
@Override
protected void configure() {
bind(new InjectMe());
}
});
final InjectionManager injectionManager = Injections.createInjectionManager();
config.configureMetaProviders(injectionManager);
assertThat("Feature instance not injected", config.getProperty("instance-injected").toString(), is("true"));
assertThat("Feature class not injected", config.getProperty("class-injected").toString(), is("true"));
}
use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class AbstractBinderTest method testFirstLayer.
@Test
public void testFirstLayer() {
AbstractBinder binder = new AbstractBinder() {
@Override
protected void configure() {
bind(CacheControlProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
bind(CookieProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
bind(DateProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
bind(EntityTagProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
bind(LinkProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
}
};
List<Binding> bindings = new ArrayList<>(binder.getBindings());
assertEquals(5, bindings.size());
// Keep ordering.
assertEquals(CacheControlProvider.class, ((ClassBinding) bindings.get(0)).getService());
assertEquals(CookieProvider.class, ((ClassBinding) bindings.get(1)).getService());
assertEquals(DateProvider.class, ((ClassBinding) bindings.get(2)).getService());
assertEquals(EntityTagProvider.class, ((ClassBinding) bindings.get(3)).getService());
assertEquals(LinkProvider.class, ((ClassBinding) bindings.get(4)).getService());
}
use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class SpringComponentProvider method initialize.
@Override
public void initialize(InjectionManager injectionManager) {
this.injectionManager = injectionManager;
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(LocalizationMessages.CTX_LOOKUP_STARTED());
}
ServletContext sc = injectionManager.getInstance(ServletContext.class);
if (sc != null) {
// servlet container
ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
} else {
// non-servlet container
ctx = createSpringContext();
}
if (ctx == null) {
LOGGER.severe(LocalizationMessages.CTX_LOOKUP_FAILED());
return;
}
LOGGER.config(LocalizationMessages.CTX_LOOKUP_SUCESSFUL());
// initialize HK2 spring-bridge
HK2InjectionManager hk2InjectionManager = (HK2InjectionManager) injectionManager;
SpringBridge.getSpringBridge().initializeSpringBridge(hk2InjectionManager.getServiceLocator());
SpringIntoHK2Bridge springBridge = injectionManager.getInstance(SpringIntoHK2Bridge.class);
springBridge.bridgeSpringBeanFactory(ctx);
// register Spring @Autowired annotation handler with HK2 ServiceLocator
Binder binder = new AbstractBinder() {
@Override
protected void configure() {
bind(new AutowiredInjectResolver(ctx)).to(InjectionResolver.class);
bind(ctx).to(ApplicationContext.class).named("SpringContext");
}
};
injectionManager.register(binder);
LOGGER.config(LocalizationMessages.SPRING_COMPONENT_PROVIDER_INITIALIZED());
}
use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class MetaInfServicesAutoDiscoverable method configure.
@Override
public void configure(final FeatureContext context) {
final Map<String, Object> properties = context.getConfiguration().getProperties();
final RuntimeType runtimeType = context.getConfiguration().getRuntimeType();
context.register(new AbstractBinder() {
@Override
protected void configure() {
// Message Body providers.
install(new ServiceFinderBinder<MessageBodyReader>(MessageBodyReader.class, properties, runtimeType));
install(new ServiceFinderBinder<MessageBodyWriter>(MessageBodyWriter.class, properties, runtimeType));
// Exception Mappers.
install(new ServiceFinderBinder<ExceptionMapper>(ExceptionMapper.class, properties, runtimeType));
}
});
}
Aggregations