Search in sources :

Example 81 with ResourceException

use of javax.resource.ResourceException in project jaybird by FirebirdSQL.

the class FBDriver method connect.

public FirebirdConnection connect(FirebirdConnectionProperties properties) throws SQLException {
    GDSType type = GDSType.getType(properties.getType());
    if (type == null)
        type = GDSFactory.getDefaultGDSType();
    try {
        FBManagedConnectionFactory mcf = new FBManagedConnectionFactory(type);
        mcf = mcf.canonicalize();
        FBDataSource dataSource = createDataSource(mcf);
        return (FirebirdConnection) dataSource.getConnection(mcf.getUserName(), mcf.getPassword());
    } catch (ResourceException ex) {
        throw new FBSQLException(ex);
    }
}
Also used : FBManagedConnectionFactory(org.firebirdsql.jca.FBManagedConnectionFactory) ResourceException(javax.resource.ResourceException) GDSType(org.firebirdsql.gds.impl.GDSType)

Example 82 with ResourceException

use of javax.resource.ResourceException in project jaybird by FirebirdSQL.

the class FBDataSource method getConnection.

/**
 * <p>Attempt to establish a database connection.
 *
 * @param username
 *         the database user on whose behalf the Connection is
 *         being made
 * @param password
 *         the user's password
 * @return a Connection to the database
 * @throws SQLException
 *         if a database-access error occurs.
 */
@SuppressWarnings("deprecation")
public Connection getConnection(String username, String password) throws SQLException {
    try {
        // mcf makes a copy for us.
        FBConnectionRequestInfo subjectCri = mcf.getDefaultConnectionRequestInfo();
        subjectCri.setUserName(username);
        subjectCri.setPassword(password);
        return (Connection) cm.allocateConnection(mcf, subjectCri);
    } catch (ResourceException re) {
        if (re.getCause() instanceof SQLException) {
            throw (SQLException) re.getCause();
        }
        if (re.getLinkedException() instanceof SQLException) {
            throw (SQLException) re.getLinkedException();
        }
        throw new FBSQLException(re);
    }
}
Also used : SQLException(java.sql.SQLException) FBConnectionRequestInfo(org.firebirdsql.jca.FBConnectionRequestInfo) Connection(java.sql.Connection) ResourceException(javax.resource.ResourceException)

Example 83 with ResourceException

use of javax.resource.ResourceException in project activemq-artemis by apache.

the class ActiveMQMessageHandler method onMessage.

@Override
public void onMessage(final ClientMessage message) {
    if (logger.isTraceEnabled()) {
        logger.trace("onMessage(" + message + ")");
    }
    ActiveMQMessage msg = ActiveMQMessage.createMessage(message, session, options);
    boolean beforeDelivery = false;
    try {
        if (activation.getActivationSpec().getTransactionTimeout() > 0 && tm != null) {
            tm.setTransactionTimeout(activation.getActivationSpec().getTransactionTimeout());
        }
        if (logger.isTraceEnabled()) {
            logger.trace("HornetQMessageHandler::calling beforeDelivery on message " + message);
        }
        endpoint.beforeDelivery(ActiveMQActivation.ONMESSAGE);
        beforeDelivery = true;
        msg.doBeforeReceive();
        if (transacted) {
            message.individualAcknowledge();
        }
        ((MessageListener) endpoint).onMessage(msg);
        if (!transacted) {
            message.individualAcknowledge();
        }
        if (logger.isTraceEnabled()) {
            logger.trace("HornetQMessageHandler::calling afterDelivery on message " + message);
        }
        try {
            endpoint.afterDelivery();
        } catch (ResourceException e) {
            ActiveMQRALogger.LOGGER.unableToCallAfterDelivery(e);
            // If we get here, The TX was already rolled back
            // However we must do some stuff now to make sure the client message buffer is cleared
            // so we mark this as rollbackonly
            session.markRollbackOnly();
            return;
        }
        if (useLocalTx) {
            session.commit();
        }
        if (logger.isTraceEnabled()) {
            logger.trace("finished onMessage on " + message);
        }
    } catch (Throwable e) {
        ActiveMQRALogger.LOGGER.errorDeliveringMessage(e);
        // we need to call before/afterDelivery as a pair
        if (beforeDelivery) {
            if (useXA && tm != null) {
                // this is to avoid a scenario where afterDelivery would kick in
                try {
                    Transaction tx = tm.getTransaction();
                    if (tx != null) {
                        tx.setRollbackOnly();
                    }
                } catch (Exception e1) {
                    ActiveMQRALogger.LOGGER.unableToClearTheTransaction(e1);
                }
            }
            MessageEndpoint endToUse = endpoint;
            try {
                // to avoid a NPE that would happen while the RA is in tearDown
                if (endToUse != null) {
                    endToUse.afterDelivery();
                }
            } catch (ResourceException e1) {
                ActiveMQRALogger.LOGGER.unableToCallAfterDelivery(e1);
            }
        }
        if (useLocalTx || !activation.isDeliveryTransacted()) {
            try {
                session.rollback(true);
            } catch (ActiveMQException e1) {
                ActiveMQRALogger.LOGGER.unableToRollbackTX();
            }
        }
        // This is to make sure we will issue a rollback after failures
        // so that would cleanup consumer buffers among other things
        session.markRollbackOnly();
    } finally {
        try {
            session.resetIfNeeded();
        } catch (ActiveMQException e) {
            ActiveMQRALogger.LOGGER.unableToResetSession(activation.toString(), e);
            activation.startReconnectThread("Reset MessageHandler after Failure Thread");
        }
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) Transaction(javax.transaction.Transaction) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) MessageListener(javax.jms.MessageListener) ResourceException(javax.resource.ResourceException) ResourceException(javax.resource.ResourceException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage)

Example 84 with ResourceException

use of javax.resource.ResourceException in project camunda-bpm-platform by camunda.

the class JcaExecutorServiceConnector method endpointActivation.

// JobHandler activation / deactivation ///////////////////////////
public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) throws ResourceException {
    if (jobHandlerActivation != null) {
        throw new ResourceException("The camunda BPM job executor can only service a single MessageEndpoint for job execution. " + "Make sure not to deploy more than one MDB implementing the '" + JobExecutionHandler.class.getName() + "' interface.");
    }
    JobExecutionHandlerActivation activation = new JobExecutionHandlerActivation(this, endpointFactory, (JobExecutionHandlerActivationSpec) spec);
    activation.start();
    jobHandlerActivation = activation;
}
Also used : ResourceException(javax.resource.ResourceException) JobExecutionHandler(org.camunda.bpm.container.impl.threading.ra.inflow.JobExecutionHandler) JobExecutionHandlerActivation(org.camunda.bpm.container.impl.threading.ra.inflow.JobExecutionHandlerActivation)

Example 85 with ResourceException

use of javax.resource.ResourceException in project camunda-bpm-platform by camunda.

the class JcaInflowExecuteJobsRunnable method executeJob.

@Override
protected void executeJob(String nextJobId, CommandExecutor commandExecutor) {
    JobExecutionHandlerActivation jobHandlerActivation = ra.getJobHandlerActivation();
    if (jobHandlerActivation == null) {
        // TODO: stop acquisition / only activate acquisition if MDB active?
        log.warning("Cannot execute acquired job, no JobExecutionHandler MDB deployed.");
        return;
    }
    MessageEndpoint endpoint = null;
    try {
        endpoint = jobHandlerActivation.getMessageEndpointFactory().createEndpoint(null);
        try {
            endpoint.beforeDelivery(method);
        } catch (NoSuchMethodException e) {
            log.log(Level.WARNING, "NoSuchMethodException while invoking beforeDelivery() on MessageEndpoint '" + endpoint + "'", e);
        } catch (ResourceException e) {
            log.log(Level.WARNING, "ResourceException while invoking beforeDelivery() on MessageEndpoint '" + endpoint + "'", e);
        }
        try {
            ((JobExecutionHandler) endpoint).executeJob(nextJobId, commandExecutor);
        } catch (Exception e) {
            log.log(Level.WARNING, "Exception while executing job with id '" + nextJobId + "'.", e);
        }
        try {
            endpoint.afterDelivery();
        } catch (ResourceException e) {
            log.log(Level.WARNING, "ResourceException while invoking afterDelivery() on MessageEndpoint '" + endpoint + "'", e);
        }
    } catch (UnavailableException e) {
        log.log(Level.SEVERE, "UnavailableException while attempting to create messaging endpoint for executing job", e);
    } finally {
        if (endpoint != null) {
            endpoint.release();
        }
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) UnavailableException(javax.resource.spi.UnavailableException) ResourceException(javax.resource.ResourceException) ResourceException(javax.resource.ResourceException) UnavailableException(javax.resource.spi.UnavailableException)

Aggregations

ResourceException (javax.resource.ResourceException)163 TranslatorException (org.teiid.translator.TranslatorException)26 SQLException (java.sql.SQLException)18 IOException (java.io.IOException)17 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)14 ManagedConnection (javax.resource.spi.ManagedConnection)13 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)13 NamingException (javax.naming.NamingException)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 SObject (com.sforce.soap.partner.sobject.SObject)9 ConnectionException (com.sforce.ws.ConnectionException)9 UnexpectedErrorFault (com.sforce.soap.partner.fault.UnexpectedErrorFault)8 ArrayList (java.util.ArrayList)8 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)7 InvalidSObjectFault (com.sforce.soap.partner.fault.InvalidSObjectFault)6 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)6 Set (java.util.Set)6 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)6 XAResource (javax.transaction.xa.XAResource)6 InvalidFieldFault (com.sforce.soap.partner.fault.InvalidFieldFault)5