Search in sources :

Example 11 with ActivationSpec

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);
}
Also used : ValidActivationSpec(org.jboss.as.test.integration.jca.beanvalidation.ra.ValidActivationSpec) ValidMessageEndpoint(org.jboss.as.test.integration.jca.beanvalidation.ra.ValidMessageEndpoint) Endpoint(org.jboss.jca.core.spi.rar.Endpoint) ValidActivationSpec(org.jboss.as.test.integration.jca.beanvalidation.ra.ValidActivationSpec) ActivationSpec(javax.resource.spi.ActivationSpec) MessageListener(org.jboss.jca.core.spi.rar.MessageListener) ResourceAdapterRepository(org.jboss.jca.core.spi.rar.ResourceAdapterRepository) ValidMessageEndpointFactory(org.jboss.as.test.integration.jca.beanvalidation.ra.ValidMessageEndpointFactory) ValidMessageEndpoint(org.jboss.as.test.integration.jca.beanvalidation.ra.ValidMessageEndpoint) Test(org.junit.Test)

Example 12 with ActivationSpec

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);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) Set(java.util.Set) TreeSet(java.util.TreeSet) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) UnavailableException(javax.resource.spi.UnavailableException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.apache.openejb.SystemException) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) ApplicationException(org.apache.openejb.ApplicationException) ConstraintViolationException(javax.validation.ConstraintViolationException) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) TreeSet(java.util.TreeSet) ActivationSpec(javax.resource.spi.ActivationSpec) ConstraintViolationException(javax.validation.ConstraintViolationException) NamingException(javax.naming.NamingException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Validator(javax.validation.Validator)

Aggregations

ActivationSpec (javax.resource.spi.ActivationSpec)12 Endpoint (org.jboss.jca.core.spi.rar.Endpoint)8 MessageListener (org.jboss.jca.core.spi.rar.MessageListener)8 ResourceAdapterRepository (org.jboss.jca.core.spi.rar.ResourceAdapterRepository)8 Test (org.junit.Test)5 ResourceException (javax.resource.ResourceException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NamingException (javax.naming.NamingException)2 UnavailableException (javax.resource.spi.UnavailableException)2 ConstraintViolationException (javax.validation.ConstraintViolationException)2 ApplicationException (org.apache.openejb.ApplicationException)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 SystemException (org.apache.openejb.SystemException)2 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)2 EjbTransactionUtil.handleSystemException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException)2 AnnoActivationSpec (org.jboss.as.test.integration.jca.annorar.AnnoActivationSpec)2 AnnoMessageListener (org.jboss.as.test.integration.jca.annorar.AnnoMessageListener)2 AnnoResourceAdapter (org.jboss.as.test.integration.jca.annorar.AnnoResourceAdapter)2 ValidActivationSpec (org.jboss.as.test.integration.jca.beanvalidation.ra.ValidActivationSpec)2 ValidMessageEndpoint (org.jboss.as.test.integration.jca.beanvalidation.ra.ValidMessageEndpoint)2