use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class SaxParserFactoryInjectionProviderTest method createInjectionManager.
public static InjectionManager createInjectionManager(Binder... customBinders) {
Binder[] binders = new Binder[customBinders.length + 2];
binders[0] = new AbstractBinder() {
@Override
protected void configure() {
bindFactory(() -> EMPTY_CONFIG).to(Configuration.class);
bindFactory(SaxParserFactoryInjectionProvider.class, Singleton.class).to(SAXParserFactory.class).in(PerThread.class);
bindAsContract(MySPFProvider.class).in(Singleton.class);
}
};
System.arraycopy(customBinders, 0, binders, 2, customBinders.length);
return Injections.createInjectionManager(binders);
}
use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class CustomInjectablesApplicationTest method plainHK2DynamicTest.
@Test
public void plainHK2DynamicTest() throws Exception {
InjectionManager injectionManager = Injections.createInjectionManager(new RequestScope.Binder());
Binder binder = new AbstractBinder() {
@Override
protected void configure() {
bindAsContract(MyInjectablePerRequest.class).in(RequestScoped.class);
bindAsContract(MyInjectableSingleton.class).in(Singleton.class);
}
};
injectionManager.register(binder);
final RequestScope requestScope = injectionManager.getInstance(RequestScope.class);
final MyInjectableSingleton myInjectableSingleton = injectionManager.getInstance(MyInjectableSingleton.class);
assertEquals(myInjectableSingleton, injectionManager.getInstance(MyInjectableSingleton.class));
final MyInjectablePerRequest myInjectablePerRequest = requestScope.runInScope(new Callable<MyInjectablePerRequest>() {
@Override
public MyInjectablePerRequest call() throws Exception {
final MyInjectablePerRequest myInjectablePerRequest = injectionManager.getInstance(MyInjectablePerRequest.class);
assertEquals(myInjectablePerRequest, injectionManager.getInstance(MyInjectablePerRequest.class));
return myInjectablePerRequest;
}
});
requestScope.runInScope(new Runnable() {
@Override
public void run() {
assertNotSame(myInjectablePerRequest, injectionManager.getInstance(MyInjectablePerRequest.class));
}
});
}
use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class CustomInjectablesApplicationTest method plainHK2Test.
@Test
public void plainHK2Test() throws Exception {
final InjectionManager locator = Injections.createInjectionManager(new RequestScope.Binder(), new AbstractBinder() {
@Override
protected void configure() {
bindAsContract(MyInjectablePerRequest.class).in(RequestScoped.class);
bindAsContract(MyInjectableSingleton.class).in(Singleton.class);
}
});
final RequestScope requestScope = locator.getInstance(RequestScope.class);
final MyInjectableSingleton myInjectableSingleton = locator.getInstance(MyInjectableSingleton.class);
assertEquals(myInjectableSingleton, locator.getInstance(MyInjectableSingleton.class));
final MyInjectablePerRequest myInjectablePerRequest = requestScope.runInScope(new Callable<MyInjectablePerRequest>() {
@Override
public MyInjectablePerRequest call() throws Exception {
final MyInjectablePerRequest myInjectablePerRequest = locator.getInstance(MyInjectablePerRequest.class);
assertEquals(myInjectablePerRequest, locator.getInstance(MyInjectablePerRequest.class));
return myInjectablePerRequest;
}
});
requestScope.runInScope(new Runnable() {
@Override
public void run() {
assertNotSame(myInjectablePerRequest, locator.getInstance(MyInjectablePerRequest.class));
}
});
}
use of org.glassfish.jersey.internal.inject.AbstractBinder in project jersey by jersey.
the class AbstractBinderTest method testWithInstall.
@Test
public void testWithInstall() {
AbstractBinder internalBinder = new AbstractBinder() {
@Override
protected void configure() {
bind(MediaTypeProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
bind(NewCookieProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
bind(StringHeaderProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
bind(UriProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
}
};
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);
install(internalBinder);
}
};
List<Binding> bindings = new ArrayList<>(binder.getBindings());
assertEquals(9, bindings.size());
// Keep ordering.
assertEquals(MediaTypeProvider.class, ((ClassBinding) bindings.get(0)).getService());
assertEquals(NewCookieProvider.class, ((ClassBinding) bindings.get(1)).getService());
assertEquals(StringHeaderProvider.class, ((ClassBinding) bindings.get(2)).getService());
assertEquals(UriProvider.class, ((ClassBinding) bindings.get(3)).getService());
assertEquals(CacheControlProvider.class, ((ClassBinding) bindings.get(4)).getService());
assertEquals(CookieProvider.class, ((ClassBinding) bindings.get(5)).getService());
assertEquals(DateProvider.class, ((ClassBinding) bindings.get(6)).getService());
assertEquals(EntityTagProvider.class, ((ClassBinding) bindings.get(7)).getService());
assertEquals(LinkProvider.class, ((ClassBinding) bindings.get(8)).getService());
}
use of org.glassfish.jersey.internal.inject.AbstractBinder in project dropwizard by dropwizard.
the class DropwizardResourceConfigTest method logEndpointBinder.
@Test
void logEndpointBinder() {
rc.register(ResourceInterface.class);
rc.register(new AbstractBinder() {
@Override
protected void configure() {
bind(ImplementingResource.class).to(ResourceInterface.class);
}
});
runJersey();
final String expectedLog = String.format("The following paths were found for the configured resources:%n" + "%n" + " GET /another (io.dropwizard.jersey.DropwizardResourceConfigTest.ResourceInterface)");
assertThat(rc.getEndpointsInfo()).contains(expectedLog);
}
Aggregations