use of javax.resource.spi.ActivationSpec in project wildfly by wildfly.
the class PositiveValidationTestCase method testRegistryConfiguration.
@Test
public void testRegistryConfiguration() throws Throwable {
ServiceController<?> controller = serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE);
assertNotNull(controller);
ResourceAdapterRepository repository = (ResourceAdapterRepository) controller.getValue();
assertNotNull(repository);
Set<String> ids = repository.getResourceAdapters(javax.jms.MessageListener.class);
assertNotNull(ids);
String piId = ids.iterator().next();
assertNotNull(piId);
Endpoint endpoint = repository.getEndpoint(piId);
assertNotNull(endpoint);
List<MessageListener> listeners = repository.getMessageListeners(piId);
assertNotNull(listeners);
assertEquals(1, listeners.size());
MessageListener listener = listeners.get(0);
ActivationSpec as = listener.getActivation().createInstance();
assertNotNull(as);
assertNotNull(as.getResourceAdapter());
ValidActivationSpec vas = (ValidActivationSpec) as;
ValidMessageEndpoint me = new ValidMessageEndpoint();
ValidMessageEndpointFactory mef = new ValidMessageEndpointFactory(me);
endpoint.activate(mef, vas);
endpoint.deactivate(mef, vas);
}
use of javax.resource.spi.ActivationSpec in project tomee by apache.
the class MdbContainer method createActivationSpec.
private ActivationSpec createActivationSpec(final BeanContext beanContext) throws OpenEJBException {
try {
// initialize the object recipe
final ObjectRecipe objectRecipe = new ObjectRecipe(activationSpecClass);
objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
objectRecipe.disallow(Option.FIELD_INJECTION);
final Map<String, String> beanContextActivationProperties = beanContext.getActivationProperties();
final Map<String, String> activationProperties = beanContextActivationProperties;
for (final Map.Entry<String, String> entry : activationProperties.entrySet()) {
objectRecipe.setMethodProperty(entry.getKey(), entry.getValue());
}
objectRecipe.setMethodProperty("beanClass", beanContext.getBeanClass());
// create the activationSpec
final ActivationSpec activationSpec = (ActivationSpec) objectRecipe.create(activationSpecClass.getClassLoader());
// verify all properties except "destination" and "destinationType" were consumed
final Set<String> unusedProperties = new TreeSet<String>(objectRecipe.getUnsetProperties().keySet());
unusedProperties.remove("destination");
unusedProperties.remove("destinationType");
unusedProperties.remove("destinationLookup");
unusedProperties.remove("connectionFactoryLookup");
unusedProperties.remove("beanClass");
if (!unusedProperties.isEmpty()) {
final String text = "No setter found for the activation spec properties: " + unusedProperties;
if (failOnUnknowActivationSpec) {
throw new IllegalArgumentException(text);
} else {
logger.warning(text);
}
}
// validate the activation spec
try {
activationSpec.validate();
} catch (final UnsupportedOperationException uoe) {
logger.info("ActivationSpec does not support validate. Implementation of validate is optional");
}
// also try validating using Bean Validation if there is a Validator available in the context.
try {
final Validator validator = (Validator) beanContext.getJndiContext().lookup("comp/Validator");
final Set generalSet = validator.validate(activationSpec);
if (!generalSet.isEmpty()) {
throw new ConstraintViolationException("Constraint violation for ActivationSpec " + activationSpecClass.getName(), generalSet);
}
} catch (final NamingException e) {
logger.debug("No Validator bound to JNDI context");
}
// set the resource adapter into the activation spec
activationSpec.setResourceAdapter(resourceAdapter);
return activationSpec;
} catch (final Exception e) {
throw new OpenEJBException("Unable to create activation spec", e);
}
}
Aggregations