use of com.google.inject.ProvisionException in project OpenAM by OpenRock.
the class ConfigLoader method validateClass.
/**
* Validates that the specified class can be loaded and implements the proper interface so that we don't have to do
* that for every request.
*
* @param cfg
* @return the class of the RequestHandler to be used for this client config, or null if the class is invalid.
*/
@SuppressWarnings("unchecked")
private Class validateClass(ClientConfig cfg) {
Class clazz = null;
try {
clazz = Class.forName(cfg.getAccessRequestHandlerClassname());
} catch (final ClassNotFoundException e) {
LOG.error("Unable to load Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
Object inst = null;
try {
inst = InjectorHolder.getInstance(clazz);
} catch (ConfigurationException | ProvisionException e) {
LOG.error("Unable to instantiate Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
AccessRequestHandler handler = null;
try {
handler = (AccessRequestHandler) inst;
} catch (final ClassCastException e) {
LOG.error("Unable to use Handler Class '" + cfg.getAccessRequestHandlerClassname() + "' for RADIUS client '" + cfg.getName() + "'. Requests from this client will be ignored.", e);
return null;
}
return clazz;
}
use of com.google.inject.ProvisionException in project metacat by Netflix.
the class SNSNotificationServiceImplProvider method get.
/**
* {@inheritDoc}
*/
@Override
public NotificationService get() {
if (this.config.isSnsNotificationEnabled()) {
final String tableArn = this.config.getSnsTopicTableArn();
if (StringUtils.isEmpty(tableArn)) {
throw new ProvisionException("SNS Notifications are enabled but no table ARN provided. Unable to configure.");
}
final String partitionArn = this.config.getSnsTopicPartitionArn();
if (StringUtils.isEmpty(partitionArn)) {
throw new ProvisionException("SNS Notifications are enabled but no partition ARN provided. Unable to configure.");
}
log.info("SNS notifications are enabled. Providing SNSNotificationServiceImpl implementation.");
return new SNSNotificationServiceImpl(new AmazonSNSClient(), tableArn, partitionArn, this.mapper, registry);
} else {
log.info("SNS notifications are not enabled. Ignoring and providing default implementation.");
return new DefaultNotificationServiceImpl();
}
}
use of com.google.inject.ProvisionException in project roboguice by roboguice.
the class MultibinderTest method testConcurrentMutation_bindingsDiffentAtInjectorCreation.
/*
* Verify through gratuitous mutation that key hashCode snapshots and whatnot happens at the right
* times, by binding two lists that are different at injector creation, but compare equal when the
* module is configured *and* when the set is instantiated.
*/
public void testConcurrentMutation_bindingsDiffentAtInjectorCreation() {
// We initially bind two equal lists
final List<String> list1 = Lists.newArrayList();
final List<String> list2 = Lists.newArrayList();
Module module = new AbstractModule() {
@Override
protected void configure() {
Multibinder<List<String>> multibinder = Multibinder.newSetBinder(binder(), listOfStrings);
multibinder.addBinding().toInstance(list1);
multibinder.addBinding().toInstance(list2);
}
};
List<Element> elements = Elements.getElements(module);
// Now we change the lists so they no longer match, and create the injector.
list1.add("A");
list2.add("B");
Injector injector = Guice.createInjector(Elements.getModule(elements));
// Now we change the lists so they compare equal again, and create the set.
list1.add(1, "B");
list2.add(0, "A");
try {
injector.getInstance(Key.get(setOfListOfStrings));
fail();
} catch (ProvisionException e) {
assertEquals(1, e.getErrorMessages().size());
assertContains(Iterables.getOnlyElement(e.getErrorMessages()).getMessage().toString(), "Set injection failed due to duplicated element \"[A, B]\"");
}
// Finally, we change the lists again so they are once more different, and ensure the set
// contains both.
list1.remove("A");
list2.remove("B");
Set<List<String>> set = injector.getInstance(Key.get(setOfListOfStrings));
assertEquals(ImmutableSet.of(ImmutableList.of("A"), ImmutableList.of("B")), set);
}
use of com.google.inject.ProvisionException in project roboguice by roboguice.
the class MultibinderTest method testMultibinderSetForbidsDuplicateElements.
public void testMultibinderSetForbidsDuplicateElements() {
Module module1 = new AbstractModule() {
protected void configure() {
final Multibinder<String> multibinder = Multibinder.newSetBinder(binder(), String.class);
multibinder.addBinding().toProvider(Providers.of("A"));
}
};
Module module2 = new AbstractModule() {
protected void configure() {
final Multibinder<String> multibinder = Multibinder.newSetBinder(binder(), String.class);
multibinder.addBinding().toInstance("A");
}
};
Injector injector = Guice.createInjector(module1, module2);
try {
injector.getInstance(Key.get(setOfString));
fail();
} catch (ProvisionException expected) {
assertContains(expected.getMessage(), "1) Set injection failed due to duplicated element \"A\"", "Bound at " + module1.getClass().getName(), "Bound at " + module2.getClass().getName());
}
// But we can still visit the module!
assertSetVisitor(Key.get(setOfString), Key.get(collectionOfProvidersOfStrings), stringType, setOf(module1, module2), MODULE, false, 0, instance("A"), instance("A"));
}
use of com.google.inject.ProvisionException in project roboguice by roboguice.
the class ScopeRequestIntegrationTest method testNullReplacement.
public final void testNullReplacement() throws Exception {
Injector injector = Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
bindConstant().annotatedWith(Names.named(SomeObject.INVALID)).to(SHOULDNEVERBESEEN);
bind(SomeObject.class).in(RequestScoped.class);
}
});
Callable<SomeObject> callable = injector.getInstance(Caller.class);
try {
assertNotNull(callable.call());
fail();
} catch (ProvisionException pe) {
assertTrue(pe.getCause() instanceof OutOfScopeException);
}
// Validate that an actual null entry in the map results in a null injected object.
Map<Key<?>, Object> map = Maps.newHashMap();
map.put(Key.get(SomeObject.class), null);
callable = ServletScopes.scopeRequest(injector.getInstance(Caller.class), map);
assertNull(callable.call());
}
Aggregations