Search in sources :

Example 16 with ResourceException

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

the class MdbContainer method deploy.

public void deploy(final BeanContext beanContext) throws OpenEJBException {
    final Object deploymentId = beanContext.getDeploymentID();
    if (!beanContext.getMdbInterface().equals(messageListenerInterface)) {
        throw new OpenEJBException("Deployment '" + deploymentId + "' has message listener interface " + beanContext.getMdbInterface().getName() + " but this MDB container only supports " + messageListenerInterface);
    }
    // create the activation spec
    final ActivationSpec activationSpec = createActivationSpec(beanContext);
    if (inboundRecovery != null) {
        inboundRecovery.recover(resourceAdapter, activationSpec, containerID.toString());
    }
    final Options options = new Options(beanContext.getProperties());
    final int instanceLimit = options.get("InstanceLimit", this.instanceLimit);
    // create the message endpoint
    final MdbInstanceFactory instanceFactory = new MdbInstanceFactory(beanContext, securityService, instanceLimit);
    final EndpointFactory endpointFactory = new EndpointFactory(activationSpec, this, beanContext, instanceFactory, xaResourceWrapper);
    // update the data structures
    // this must be done before activating the endpoint since the ra may immedately begin delivering messages
    beanContext.setContainer(this);
    beanContext.setContainerData(endpointFactory);
    deployments.put(deploymentId, beanContext);
    // Create stats interceptor
    if (StatsInterceptor.isStatsActivated()) {
        final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
        beanContext.addFirstSystemInterceptor(stats);
        final MBeanServer server = LocalMBeanServer.get();
        final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
        jmxName.set("J2EEServer", "openejb");
        jmxName.set("J2EEApplication", null);
        jmxName.set("EJBModule", beanContext.getModuleID());
        jmxName.set("StatelessSessionBean", beanContext.getEjbName());
        jmxName.set("j2eeType", "");
        jmxName.set("name", beanContext.getEjbName());
        // register the invocation stats interceptor
        try {
            final ObjectName objectName = jmxName.set("j2eeType", "Invocations").build();
            if (server.isRegistered(objectName)) {
                server.unregisterMBean(objectName);
            }
            server.registerMBean(new ManagedMBean(stats), objectName);
            endpointFactory.jmxNames.add(objectName);
        } catch (final Exception e) {
            logger.error("Unable to register MBean ", e);
        }
    }
    // activate the endpoint
    CURRENT.set(beanContext);
    try {
        resourceAdapter.endpointActivation(endpointFactory, activationSpec);
    } catch (final ResourceException e) {
        // activation failed... clean up
        beanContext.setContainer(null);
        beanContext.setContainerData(null);
        deployments.remove(deploymentId);
        throw new OpenEJBException(e);
    } finally {
        CURRENT.remove();
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) Options(org.apache.openejb.loader.Options) StatsInterceptor(org.apache.openejb.monitoring.StatsInterceptor) 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) ObjectName(javax.management.ObjectName) ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) ActivationSpec(javax.resource.spi.ActivationSpec) ResourceException(javax.resource.ResourceException) ManagedMBean(org.apache.openejb.monitoring.ManagedMBean) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer)

Example 17 with ResourceException

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

the class LazyAssociationSharableFalseTestCase method verifyDisabledLazyAssociation.

@Test
public void verifyDisabledLazyAssociation() {
    assertNotNull(lcf);
    LazyConnection lc1 = null;
    LazyConnection lc2 = null;
    try {
        lc1 = lcf.getConnection();
        assertTrue(lc1.isManagedConnectionSet());
        try {
            lc2 = lcf.getConnection();
            fail("Exception should have been thrown");
        } catch (ResourceException re) {
        // expected
        }
    } catch (Throwable t) {
        logger.error(t.getMessage(), t);
        fail("Throwable:" + t.getLocalizedMessage());
    } finally {
        if (lc1 != null) {
            lc1.close();
        }
        if (lc2 != null) {
            lc2.close();
        }
    }
}
Also used : LazyConnection(org.jboss.as.test.integration.jca.lazyconnectionmanager.rar.LazyConnection) ResourceException(javax.resource.ResourceException) Test(org.junit.Test)

Example 18 with ResourceException

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

the class JCALocalTransaction method begin.

@Override
public void begin() throws ResourceException {
    try {
        if (!this.initDone || this.cache.isClosed()) {
            this.init();
        }
        LogWriter logger = this.cache.getLogger();
        if (logger.fineEnabled()) {
            logger.fine("JCALocalTransaction::begin:");
        }
        TransactionManager tm = this.cache.getJTATransactionManager();
        if (this.tid != null) {
            throw new LocalTransactionException(" A transaction is already in progress");
        }
        if (tm != null && tm.getTransaction() != null) {
            if (logger.fineEnabled()) {
                logger.fine("JCAManagedConnection: JTA transaction is on");
            }
            // This is having a JTA transaction. Assuming ignore jta flag is true,
            // explicitly being a gemfire transaction.
            TXStateProxy tsp = this.gfTxMgr.getTXState();
            if (tsp == null) {
                this.gfTxMgr.begin();
                tsp = this.gfTxMgr.getTXState();
                tsp.setJCATransaction();
                this.tid = tsp.getTransactionId();
                if (logger.fineEnabled()) {
                    logger.fine("JCALocalTransaction:begun GFE transaction");
                }
            } else {
                throw new LocalTransactionException("GemFire is already associated with a transaction");
            }
        } else {
            if (logger.fineEnabled()) {
                logger.fine("JCAManagedConnection: JTA Transaction does not exist.");
            }
        }
    } catch (SystemException e) {
        throw new ResourceException(e);
    }
}
Also used : LocalTransactionException(javax.resource.spi.LocalTransactionException) SystemException(javax.transaction.SystemException) LogWriter(org.apache.geode.LogWriter) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) TransactionManager(javax.transaction.TransactionManager) ResourceException(javax.resource.ResourceException)

Example 19 with ResourceException

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

the class FacetsJCAConnectionManagerImpl method allocateConnection.

/*
   * allocates a ManagedConnection from the ConnectionPool or creates a new
   * ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
   * 
   * @param javax.resource.spi.ConnectionRequestInfo
   * 
   * @throws ResourceException
   */
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
    if (!isActive) {
        throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
    }
    ManagedConnection conn = null;
    try {
        conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
    } catch (PoolException ex) {
        ex.printStackTrace();
        throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    }
    // Transaction Manager.
    try {
        synchronized (this) {
            if (transManager == null) {
                transManager = JNDIInvoker.getTransactionManager();
            }
        }
        Transaction txn = transManager.getTransaction();
        if (txn != null) {
            // Check if Data Source provides XATransaction
            // if(configs.getTransactionType = "XATransaction")
            XAResource xar = conn.getXAResource();
            txn.enlistResource(xar);
            java.util.List resList = (List) xalistThreadLocal.get();
            if (resList.size() == 0) {
                // facets specific implementation
                // register syschronisation only once
                txn.registerSynchronization(this);
            }
            resList.add(conn);
        // xalistThreadLocal.set(resList);
        // Asif :Add in the Map after successful registration of XAResource
        // xaResourcesMap.put(conn, xar);
        // else throw a resource exception
        }
    } catch (RollbackException ex) {
        String exception = LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_AN_EXCEPTION_WAS_CAUGHT_WHILE_ALLOCATING_A_CONNECTION_DUE_TO_0.toLocalizedString(ex.getMessage());
        throw new ResourceException(exception, ex);
    } catch (SystemException ex) {
        throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
    }
    return conn.getConnection(subject, reqInfo);
}
Also used : XAResource(javax.transaction.xa.XAResource) List(java.util.List) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) ResourceException(javax.resource.ResourceException) ManagedConnection(javax.resource.spi.ManagedConnection) ArrayList(java.util.ArrayList) List(java.util.List) RollbackException(javax.transaction.RollbackException)

Example 20 with ResourceException

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

the class JCAManagedConnectionFactory method createRepository.

/**
     * Create/startup the repository.
     */
@SuppressWarnings("deprecation")
private void createRepository() throws ResourceException {
    if (repository == null) {
        try {
            JCARepositoryManager mgr = JCARepositoryManager.getInstance();
            repository = mgr.createRepository(parameters);
            log("Created repository (" + repository + ")");
        } catch (RepositoryException e) {
            log("Failed to create repository", e);
            ResourceException exception = new ResourceException("Failed to create repository: " + e.getMessage());
            exception.setLinkedException(e);
            throw exception;
        }
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) ResourceException(javax.resource.ResourceException)

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