Search in sources :

Example 11 with ResourceException

use of javax.resource.ResourceException in project wildfly by wildfly.

the class TelnetResourceAdapter method endpointActivation.

@Override
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
    final TelnetActivationSpec telnetActivationSpec = (TelnetActivationSpec) activationSpec;
    final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);
    // This messageEndpoint instance is also castable to the ejbClass of the MDB
    final TelnetListener telnetListener = (TelnetListener) messageEndpoint;
    try {
        final TelnetServer telnetServer = new TelnetServer(telnetActivationSpec, telnetListener, port);
        workManager.scheduleWork(new Work() {

            @Override
            public void release() {
            }

            @Override
            public void run() {
                try {
                    telnetServer.activate();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }, 0, null, null);
        activated.put(port, telnetServer);
    } catch (IOException e) {
        throw new ResourceException(e);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) TelnetListener(org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener) Work(javax.resource.spi.work.Work) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) TelnetServer(org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer)

Example 12 with ResourceException

use of javax.resource.ResourceException in project wildfly by wildfly.

the class SimpleResourceAdapter method endpointActivation.

/**
     * Send a message to the MDB right after the MDB endpoint is activated.
     * Using reflection to pick a method to invoke - see EJB 3.2 spec section 5.4.3
     */
@Override
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
    log.trace("SimpleResourceAdapter activating MDB endpoint and sending a message to it");
    Class<?> endpointClass = messageEndpointFactory.getEndpointClass();
    try {
        Method methodToInvoke = endpointClass.getMethod(((SimpleActivationSpec) activationSpec).getMethodName(), String.class);
        MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
        this.endpoint = endpoint;
        methodToInvoke.invoke(endpoint, "Hello world");
    } catch (Exception e) {
        throw new ResourceException(e);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) ResourceException(javax.resource.ResourceException) Method(java.lang.reflect.Method) ResourceException(javax.resource.ResourceException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException)

Example 13 with ResourceException

use of javax.resource.ResourceException 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 14 with ResourceException

use of javax.resource.ResourceException in project tomee by apache.

the class AutoConnectionTracker method proxyConnection.

private void proxyConnection(final ConnectionTrackingInterceptor interceptor, final ConnectionInfo connectionInfo) throws ResourceException {
    // if this connection already has a proxy no need to create another
    if (connectionInfo.getConnectionProxy() != null) {
        return;
    }
    // DissociatableManagedConnection do not need to be proxied
    if (connectionInfo.getManagedConnectionInfo().getManagedConnection() instanceof DissociatableManagedConnection) {
        return;
    }
    try {
        final Object handle = connectionInfo.getConnectionHandle();
        final ConnectionInvocationHandler invocationHandler = new ConnectionInvocationHandler(handle);
        final Object proxy = newProxy(handle, invocationHandler);
        connectionInfo.setConnectionProxy(proxy);
        final ProxyPhantomReference reference = new ProxyPhantomReference(interceptor, connectionInfo.getManagedConnectionInfo(), invocationHandler, referenceQueue);
        references.put(connectionInfo.getManagedConnectionInfo(), reference);
    } catch (final Throwable e) {
        throw new ResourceException("Unable to construct connection proxy", e);
    }
}
Also used : DissociatableManagedConnection(javax.resource.spi.DissociatableManagedConnection) ResourceException(javax.resource.ResourceException)

Example 15 with ResourceException

use of javax.resource.ResourceException in project tomee by apache.

the class QuartzResourceAdapter method endpointActivation.

@Override
public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
    final Scheduler s = scheduler.get();
    if (null == s) {
        throw new ResourceException("Quartz Scheduler is not available");
    }
    try {
        final JobSpec spec = (JobSpec) activationSpec;
        final MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
        spec.setEndpoint(endpoint);
        final Job job = (Job) endpoint;
        final JobDataMap jobDataMap = spec.getDetail().getJobDataMap();
        jobDataMap.put(Data.class.getName(), new Data(job));
        s.scheduleJob(spec.getDetail(), spec.getTrigger());
    } catch (final SchedulerException e) {
        throw new ResourceException("Failed to schedule job", e);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) JobDataMap(org.apache.openejb.quartz.JobDataMap) SchedulerException(org.apache.openejb.quartz.SchedulerException) Scheduler(org.apache.openejb.quartz.Scheduler) ResourceException(javax.resource.ResourceException) Job(org.apache.openejb.quartz.Job)

Aggregations

ResourceException (javax.resource.ResourceException)21 Connection (javax.resource.cci.Connection)4 LocalTransactionException (javax.resource.spi.LocalTransactionException)4 SystemException (javax.transaction.SystemException)4 ManagedConnection (javax.resource.spi.ManagedConnection)3 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)3 LogWriter (org.apache.geode.LogWriter)3 TXStateProxy (org.apache.geode.internal.cache.TXStateProxy)3 IOException (java.io.IOException)2 RepositoryException (javax.jcr.RepositoryException)2 NotSupportedException (javax.resource.NotSupportedException)2 ActivationSpec (javax.resource.spi.ActivationSpec)2 RollbackException (javax.transaction.RollbackException)2 Transaction (javax.transaction.Transaction)2 XAResource (javax.transaction.xa.XAResource)2 TransactionSystemException (org.springframework.transaction.TransactionSystemException)2 IntrospectionException (java.beans.IntrospectionException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1