use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class WadlGeneratorLoaderTest method testLoadStream.
@Test
public void testLoadStream() throws Exception {
final InjectionManager injectionManager = InjectionManagerFactory.createInjectionManager();
final Properties props = new Properties();
final String path = getClass().getPackage().getName().replaceAll("\\.", "/") + "/testfile.xml";
props.put("testStream", path);
final WadlGeneratorDescription description = new WadlGeneratorDescription(MyWadlGenerator2.class, props);
final WadlGenerator wadlGenerator = WadlGeneratorLoader.loadWadlGeneratorDescriptions(injectionManager, description);
Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
final URL resource = getClass().getResource("testfile.xml");
Assert.assertEquals(new File(resource.toURI()).length(), ((MyWadlGenerator2) wadlGenerator).getTestStreamContent().length());
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ValidatorTest method createInjectionManager.
private InjectionManager createInjectionManager() {
InjectionManager injectionManager = InjectionManagerFactory.createInjectionManager();
injectionManager.register(new AbstractBinder() {
@Override
protected void configure() {
bind(new CommonConfig(RuntimeType.SERVER, ComponentBag.EXCLUDE_EMPTY)).to(Configuration.class);
}
});
return injectionManager;
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ResourceMethodDispatcherFactoryTest method setupApplication.
@Before
public void setupApplication() {
InjectionManager locator = InjectionManagerFactory.createInjectionManager();
rmdf = locator.getInstance(ResourceMethodDispatcherFactory.class);
rmihf = locator.getInstance(ResourceMethodInvocationHandlerFactory.class);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class JettyContainerTest method testParentServiceLocator.
/**
* Test that defined ServiceLocator becomes a parent of the newly created service locator.
*/
@Test
public void testParentServiceLocator() {
final ServiceLocator locator = new ServiceLocatorImpl("MyServiceLocator", null);
final Server server = JettyHttpContainerFactory.createServer(URI.create("http://localhost:9876"), new ResourceConfig(Resource.class), false, locator);
JettyHttpContainer container = (JettyHttpContainer) server.getHandler();
InjectionManager injectionManager = container.getApplicationHandler().getInjectionManager();
HK2InjectionManager hk2InjectionManager = (HK2InjectionManager) injectionManager;
ServiceLocator serviceLocator = hk2InjectionManager.getServiceLocator();
assertTrue("Application injection manager was expected to have defined parent locator", serviceLocator.getParent() == locator);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class ParameterValueHelper method createValueProviders.
/**
* Create list of parameter value providers for the given {@link Parameterized
* parameterized} resource model component.
*
* @param injectionManager injection manager.
* @param parameterized parameterized resource model component.
* @return list of parameter value providers for the parameterized component.
*/
public static List<ParamValueFactoryWithSource<?>> createValueProviders(InjectionManager injectionManager, Parameterized parameterized) {
if ((null == parameterized.getParameters()) || (0 == parameterized.getParameters().size())) {
return Collections.emptyList();
}
List<ValueSupplierProvider> valueSupplierProviders = Providers.getProviders(injectionManager, ValueSupplierProvider.class).stream().sorted((o1, o2) -> o2.getPriority().getWeight() - o1.getPriority().getWeight()).collect(Collectors.toList());
boolean entityParamFound = false;
final List<ParamValueFactoryWithSource<?>> providers = new ArrayList<>(parameterized.getParameters().size());
for (final Parameter parameter : parameterized.getParameters()) {
final Parameter.Source parameterSource = parameter.getSource();
entityParamFound = entityParamFound || Parameter.Source.ENTITY == parameterSource;
final Supplier<?> valueSupplier = getParamValueSupplier(valueSupplierProviders, parameter);
if (valueSupplier != null) {
providers.add(wrapParamValueSupplier(valueSupplier, parameterSource));
} else {
providers.add(null);
}
}
if (!entityParamFound && Collections.frequency(providers, null) == 1) {
// Try to find entity if there is one unresolved parameter and the annotations are unknown
final int entityParamIndex = providers.lastIndexOf(null);
final Parameter parameter = parameterized.getParameters().get(entityParamIndex);
if (Parameter.Source.UNKNOWN == parameter.getSource() && !parameter.isQualified()) {
final Parameter overriddenParameter = Parameter.overrideSource(parameter, Parameter.Source.ENTITY);
final Supplier<?> valueSupplier = getParamValueSupplier(valueSupplierProviders, overriddenParameter);
if (valueSupplier != null) {
providers.set(entityParamIndex, wrapParamValueSupplier(valueSupplier, overriddenParameter.getSource()));
} else {
providers.set(entityParamIndex, null);
}
}
}
return providers;
}
Aggregations