Search in sources :

Example 1 with ActivationSpec

use of javax.resource.spi.ActivationSpec in project wildfly by wildfly.

the class EJBUtilities method createActivationSpecs.

public ActivationSpec createActivationSpecs(final String resourceAdapterName, final Class<?> messageListenerInterface, final Properties activationConfigProperties, final ClassLoader classLoader) {
    try {
        // first get the ra "identifier" (with which it is registered in the resource adapter repository) for the
        // ra name
        final String raIdentifier = ConnectorServices.getRegisteredResourceAdapterIdentifier(resourceAdapterName);
        if (raIdentifier == null) {
            throw EjbLogger.ROOT_LOGGER.unknownResourceAdapter(resourceAdapterName);
        }
        final ResourceAdapterRepository resourceAdapterRepository = getResourceAdapterRepository();
        if (resourceAdapterRepository == null) {
            throw EjbLogger.ROOT_LOGGER.resourceAdapterRepositoryUnAvailable();
        }
        // now get the message listeners for this specific ra identifier
        final List<MessageListener> messageListeners = resourceAdapterRepository.getMessageListeners(raIdentifier);
        if (messageListeners == null || messageListeners.isEmpty()) {
            throw EjbLogger.ROOT_LOGGER.unknownMessageListenerType(messageListenerInterface.getName(), resourceAdapterName);
        }
        MessageListener requiredMessageListener = null;
        // now find the expected message listener from the list of message listeners for this resource adapter
        for (final MessageListener messageListener : messageListeners) {
            if (messageListenerInterface.equals(messageListener.getType())) {
                requiredMessageListener = messageListener;
                break;
            }
        }
        if (requiredMessageListener == null) {
            throw EjbLogger.ROOT_LOGGER.unknownMessageListenerType(messageListenerInterface.getName(), resourceAdapterName);
        }
        // found the message listener, now finally create the activation spec
        final Activation activation = requiredMessageListener.getActivation();
        // filter out the activation config properties, specified on the MDB, which aren't accepted by the resource
        // adaptor
        final Properties validActivationConfigProps = this.filterUnknownActivationConfigProperties(resourceAdapterName, activation, activationConfigProperties);
        // now set the activation config properties on the ActivationSpec
        final ActivationSpec activationSpec = activation.createInstance();
        BeanUtils.mapJavaBeanProperties(activationSpec, validActivationConfigProps);
        return activationSpec;
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (ResourceException e) {
        throw new RuntimeException(e);
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    }
}
Also used : MessageListener(org.jboss.jca.core.spi.rar.MessageListener) IntrospectionException(java.beans.IntrospectionException) NotFoundException(org.jboss.jca.core.spi.rar.NotFoundException) Activation(org.jboss.jca.core.spi.rar.Activation) Properties(java.util.Properties) ActivationSpec(javax.resource.spi.ActivationSpec) ResourceAdapterRepository(org.jboss.jca.core.spi.rar.ResourceAdapterRepository) ResourceException(javax.resource.ResourceException)

Example 2 with ActivationSpec

use of javax.resource.spi.ActivationSpec in project wildfly by wildfly.

the class MessageDrivenComponentCreateService method createActivationSpecs.

private ActivationSpec createActivationSpecs(final String resourceAdapterName, final Class<?> messageListenerInterface, final Properties activationConfigProperties, final ClassLoader classLoader) {
    try {
        // first get the ra "identifier" (with which it is registered in the resource adapter repository) for the
        // ra name
        final String raIdentifier = ConnectorServices.getRegisteredResourceAdapterIdentifier(resourceAdapterName);
        if (raIdentifier == null) {
            throw EjbLogger.ROOT_LOGGER.unknownResourceAdapter(resourceAdapterName);
        }
        final ResourceAdapterRepository resourceAdapterRepository = resourceAdapterRepositoryInjectedValue.getValue();
        if (resourceAdapterRepository == null) {
            throw EjbLogger.ROOT_LOGGER.resourceAdapterRepositoryUnAvailable();
        }
        // now get the message listeners for this specific ra identifier
        final List<MessageListener> messageListeners = resourceAdapterRepository.getMessageListeners(raIdentifier);
        if (messageListeners == null || messageListeners.isEmpty()) {
            throw EjbLogger.ROOT_LOGGER.unknownMessageListenerType(messageListenerInterface.getName(), resourceAdapterName);
        }
        MessageListener requiredMessageListener = null;
        // now find the expected message listener from the list of message listeners for this resource adapter
        for (final MessageListener messageListener : messageListeners) {
            if (messageListenerInterface.equals(messageListener.getType())) {
                requiredMessageListener = messageListener;
                break;
            }
        }
        if (requiredMessageListener == null) {
            throw EjbLogger.ROOT_LOGGER.unknownMessageListenerType(messageListenerInterface.getName(), resourceAdapterName);
        }
        // found the message listener, now finally create the activation spec
        final Activation activation = requiredMessageListener.getActivation();
        // filter out the activation config properties, specified on the MDB, which aren't accepted by the resource
        // adaptor
        final Properties validActivationConfigProps = this.filterUnknownActivationConfigProperties(resourceAdapterName, activation, activationConfigProperties);
        // now set the activation config properties on the ActivationSpec
        final ActivationSpec activationSpec = activation.createInstance();
        BeanUtils.mapJavaBeanProperties(activationSpec, validActivationConfigProps);
        return activationSpec;
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (ResourceException e) {
        throw new RuntimeException(e);
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (NotFoundException e) {
        throw new RuntimeException(e);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    }
}
Also used : MessageListener(org.jboss.jca.core.spi.rar.MessageListener) IntrospectionException(java.beans.IntrospectionException) NotFoundException(org.jboss.jca.core.spi.rar.NotFoundException) Activation(org.jboss.jca.core.spi.rar.Activation) Properties(java.util.Properties) ActivationSpec(javax.resource.spi.ActivationSpec) ResourceAdapterRepository(org.jboss.jca.core.spi.rar.ResourceAdapterRepository) ResourceException(javax.resource.ResourceException)

Example 3 with ActivationSpec

use of javax.resource.spi.ActivationSpec in project wildfly by wildfly.

the class NoRaAnnoTestCase method testActivation.

/**
 * Test activation
 *
 * @param clazz class name
 * @throws Throwable Thrown if case of an error
 */
public void testActivation(Class clazz) throws Throwable {
    ServiceController<?> controller = serviceContainer.getService(ConnectorServices.RA_REPOSITORY_SERVICE);
    assertNotNull(controller);
    ResourceAdapterRepository raRepository = (ResourceAdapterRepository) controller.getValue();
    Set<String> ids = raRepository.getResourceAdapters(clazz);
    assertNotNull(ids);
    assertEquals(1, ids.size());
    String piId = ids.iterator().next();
    assertNotNull(piId);
    Endpoint endpoint = raRepository.getEndpoint(piId);
    assertNotNull(endpoint);
    List<MessageListener> listeners = raRepository.getMessageListeners(piId);
    assertNotNull(listeners);
    assertEquals(2, listeners.size());
    MessageListener listener = listeners.get(0);
    MessageListener listener1 = listeners.get(1);
    ActivationSpec as = listener.getActivation().createInstance();
    ActivationSpec as1 = listener1.getActivation().createInstance();
    assertNotNull(as);
    assertNotNull(as.getResourceAdapter());
    assertNotNull(as1);
    assertNotNull(as1.getResourceAdapter());
    AnnoActivationSpec tas = (AnnoActivationSpec) as;
    log.trace("AS:" + tas + "//1//" + tas.getFirst() + "//2//" + tas.getSecond());
    assertEquals(new Character('C'), tas.getFirst());
    assertEquals(new Double(0.5), tas.getSecond());
    assertTrue(tas.getResourceAdapter() instanceof AnnoResourceAdapter);
    AnnoResourceAdapter tra = (AnnoResourceAdapter) tas.getResourceAdapter();
    log.trace("RA:" + tra + "//1//" + tra.getFirst() + "//2//" + tra.getSecond());
    assertEquals("A", tra.getFirst());
    assertEquals(new Integer(5), tra.getSecond());
}
Also used : AnnoActivationSpec(org.jboss.as.test.integration.jca.annorar.AnnoActivationSpec) AnnoMessageListener(org.jboss.as.test.integration.jca.annorar.AnnoMessageListener) MessageListener(org.jboss.jca.core.spi.rar.MessageListener) Endpoint(org.jboss.jca.core.spi.rar.Endpoint) AnnoResourceAdapter(org.jboss.as.test.integration.jca.annorar.AnnoResourceAdapter) AnnoActivationSpec(org.jboss.as.test.integration.jca.annorar.AnnoActivationSpec) ActivationSpec(javax.resource.spi.ActivationSpec) ResourceAdapterRepository(org.jboss.jca.core.spi.rar.ResourceAdapterRepository)

Example 4 with ActivationSpec

use of javax.resource.spi.ActivationSpec in project wildfly by wildfly.

the class InflowTestCase method testRegistryConfiguration.

/**
 * Test configuration
 *
 * @throws Throwable Thrown if case of an error
 */
@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);
    int pureInflowListener = 0;
    for (String id : ids) {
        if (id.indexOf("PureInflow") != -1) {
            pureInflowListener++;
        }
    }
    assertEquals(1, pureInflowListener);
    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());
}
Also used : Endpoint(org.jboss.jca.core.spi.rar.Endpoint) ActivationSpec(javax.resource.spi.ActivationSpec) MessageListener(org.jboss.jca.core.spi.rar.MessageListener) ResourceAdapterRepository(org.jboss.jca.core.spi.rar.ResourceAdapterRepository) Endpoint(org.jboss.jca.core.spi.rar.Endpoint) Test(org.junit.Test)

Example 5 with ActivationSpec

use of javax.resource.spi.ActivationSpec in project tomee by apache.

the class MdbPoolContainer 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> activationProperties = beanContext.getActivationProperties();
        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<>(objectRecipe.getUnsetProperties().keySet());
        unusedProperties.remove("destination");
        unusedProperties.remove("destinationType");
        unusedProperties.remove("destinationLookup");
        unusedProperties.remove("connectionFactoryLookup");
        unusedProperties.remove("beanClass");
        unusedProperties.remove("MdbActiveOnStartup");
        unusedProperties.remove("MdbJMXControl");
        unusedProperties.remove("DeliveryActive");
        if (!unusedProperties.isEmpty()) {
            final String text = "No setter found for the activation spec properties: " + unusedProperties;
            if (failOnUnknownActivationSpec) {
                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) TreeSet(java.util.TreeSet) Set(java.util.Set) ResourceException(javax.resource.ResourceException) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) NamingException(javax.naming.NamingException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConstraintViolationException(javax.validation.ConstraintViolationException) SystemException(org.apache.openejb.SystemException) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) TreeSet(java.util.TreeSet) ActivationSpec(javax.resource.spi.ActivationSpec) ConstraintViolationException(javax.validation.ConstraintViolationException) NamingException(javax.naming.NamingException) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Validator(javax.validation.Validator)

Aggregations

ActivationSpec (javax.resource.spi.ActivationSpec)17 MessageListener (org.jboss.jca.core.spi.rar.MessageListener)9 ResourceAdapterRepository (org.jboss.jca.core.spi.rar.ResourceAdapterRepository)9 Endpoint (org.jboss.jca.core.spi.rar.Endpoint)8 ResourceException (javax.resource.ResourceException)5 Set (java.util.Set)4 OpenEJBException (org.apache.openejb.OpenEJBException)4 Test (org.junit.Test)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Map (java.util.Map)3 NamingException (javax.naming.NamingException)3 UnavailableException (javax.resource.spi.UnavailableException)3 ConstraintViolationException (javax.validation.ConstraintViolationException)3 ApplicationException (org.apache.openejb.ApplicationException)3 SystemException (org.apache.openejb.SystemException)3 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)3 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 SetMethodAction (com.sun.enterprise.connectors.util.SetMethodAction)2 IntrospectionException (java.beans.IntrospectionException)2 Properties (java.util.Properties)2