Search in sources :

Example 76 with EJBException

use of javax.ejb.EJBException in project Payara by payara.

the class ReadOnlyBeanContainer method preInvokeNoTx.

// Called from BaseContainer just before invoking a business method
// whose tx attribute is TX_NEVER / TX_NOT_SUPPORTED / TX_SUPPORTS
// without a client tx.
protected void preInvokeNoTx(EjbInvocation inv) {
    EntityContextImpl context = (EntityContextImpl) inv.context;
    if (context.isInState(BeanState.DESTROYED))
        return;
    if (!inv.invocationInfo.isCreateHomeFinder) {
        // follow EJB2.0 section 12.1.6.1
        EntityBean e = (EntityBean) context.getEJB();
        try {
            callEJBLoad(e, context, false);
        } catch (NoSuchEntityException ex) {
            _logger.log(Level.FINE, "Exception in preInvokeNoTx()", ex);
            // Error during ejbLoad, so discard bean: EJB2.0 18.3.3
            forceDestroyBean(context);
            throw new NoSuchObjectLocalException("NoSuchEntityException thrown by ejbLoad, " + "EJB instance discarded");
        } catch (Exception ex) {
            // Error during ejbLoad, so discard bean: EJB2.0 18.3.3
            forceDestroyBean(context);
            throw new EJBException(ex);
        }
        context.setNewlyActivated(false);
    }
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) EntityBean(javax.ejb.EntityBean) EJBException(javax.ejb.EJBException) NoSuchEntityException(javax.ejb.NoSuchEntityException) FinderException(javax.ejb.FinderException) NoSuchEntityException(javax.ejb.NoSuchEntityException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 77 with EJBException

use of javax.ejb.EJBException in project Payara by payara.

the class JDOEJB11HelperImpl method convertPCToEJBObject.

/**
 * Converts persistence-capable instance to EJBObject.
 * @param pc the persistence-capable instance to be converted as an Object.
 * @param pm the associated instance of PersistenceManager.
 * @return instance of EJBObject.
 */
public EJBObject convertPCToEJBObject(Object pc, PersistenceManager pm) {
    if (pc == null)
        return null;
    Object jdoObjectId = pm.getObjectId(pc);
    Object key = convertObjectIdToPrimaryKey(jdoObjectId);
    try {
        return CMPHelper.getEJBObject(key, getContainer());
    } catch (Exception ex) {
        EJBException e = new EJBException(I18NHelper.getMessage(messages, "EXC_ConvertPCToEJBObject", key.toString()), // NOI18N
        ex);
        // NOI18N
        logger.throwing("JDOEJB11HelperImpl", "convertPCToEJBObject", e);
        throw e;
    }
}
Also used : EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) JDOFatalDataStoreException(com.sun.jdo.api.persistence.support.JDOFatalDataStoreException) JDOObjectNotFoundException(com.sun.jdo.api.persistence.support.JDOObjectNotFoundException) EJBException(javax.ejb.EJBException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 78 with EJBException

use of javax.ejb.EJBException in project Payara by payara.

the class JDOEJB20HelperImpl method convertPCToEJBLocalObject.

/**
 * Converts persistence-capable instance to EJBLocalObject. Returns null if
 * the instance is already removed via cascade-delete operation.
 * @param pc the persistence-capable instance to be converted as an Object.
 * @param pm the associated instance of PersistenceManager.
 * @param context the EJBContext of the calling bean.
 * @return instance of EJBLocalObject.
 */
public EJBLocalObject convertPCToEJBLocalObject(Object pc, PersistenceManager pm, EJBContext context) {
    if (pc == null)
        return null;
    Object jdoObjectId = pm.getObjectId(pc);
    Object key = convertObjectIdToPrimaryKey(jdoObjectId);
    try {
        return CMPHelper.getEJBLocalObject(key, getContainer(), context);
    } catch (Exception ex) {
        EJBException e = new EJBException(I18NHelper.getMessage(messages, "EXC_ConvertPCToEJBLocalObjectCtx", key.toString()), // NOI18N
        ex);
        // NOI18N
        logger.throwing("JDOEJB20HelperImpl", "convertPCToEJBLocalObjectCtx", e);
        throw e;
    }
}
Also used : EJBLocalObject(javax.ejb.EJBLocalObject) EJBException(javax.ejb.EJBException) EJBException(javax.ejb.EJBException)

Example 79 with EJBException

use of javax.ejb.EJBException in project Payara by payara.

the class ActiveTxCache method getEJBWithIncompleteTx.

// getReadyEJB(inv)
// called from releaseContext, afterCompletion
/**
 * Get an EJB instance for this EJBObject and current client Tx
 * Called only from getContext.
 * Return null if there no INCOMPLETE_TX bean for the pkey & tx.
 */
private EntityContextImpl getEJBWithIncompleteTx(EjbInvocation inv) {
    // We need to make sure that two concurrent client
    // invocations with same primary key and same client tx
    // get the SAME EJB instance.
    // So we need to maintain exactly one copy of an EJB's state
    // per transaction.
    JavaEETransaction current = null;
    try {
        current = (JavaEETransaction) transactionManager.getTransaction();
    } catch (SystemException ex) {
        throw new EJBException(ex);
    }
    EntityContextImpl ctx = null;
    if (current != null) {
        ActiveTxCache activeTxCache = (ActiveTxCache) ejbContainerUtilImpl.getActiveTxCache(current);
        ctx = (activeTxCache == null) ? null : activeTxCache.get(this, getInvocationKey(inv));
        inv.foundInTxCache = (ctx != null);
    }
    return ctx;
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) SystemException(javax.transaction.SystemException) EJBException(javax.ejb.EJBException)

Example 80 with EJBException

use of javax.ejb.EJBException in project Payara by payara.

the class MessageBean method onMessage.

public void onMessage(Message message) {
    System.out.println("Got message!!!");
    QueueConnection connection = null;
    try {
        System.out.println("Calling hello1 stateless bean");
        hello1.hello("local ejb3.0 stateless");
        System.out.println("Calling hello2 stateful bean");
        hello2.hello("local ejb3.0 stateful");
        hello2.removeMethod();
        try {
            hello2.hello("this call should not go through");
            throw new Exception("bean should have been removed " + "after removeMethod()");
        } catch (NoSuchEJBException e) {
            System.out.println("Successfully caught EJBException after " + " accessing removed SFSB");
        }
        connection = qcFactory.createQueueConnection();
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender sender = session.createSender(clientQueue);
        TextMessage tmessage = session.createTextMessage();
        tmessage.setText("mdb() invoked");
        System.out.println("Sending message");
        sender.send(tmessage);
        System.out.println("message sent");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage)

Aggregations

EJBException (javax.ejb.EJBException)169 CreateException (javax.ejb.CreateException)51 RemoteException (java.rmi.RemoteException)45 RemoveException (javax.ejb.RemoveException)40 InitialContext (javax.naming.InitialContext)40 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)37 SystemException (javax.transaction.SystemException)37 FinderException (javax.ejb.FinderException)30 InvocationTargetException (java.lang.reflect.InvocationTargetException)24 OpenEJBException (org.apache.openejb.OpenEJBException)24 EJBObject (javax.ejb.EJBObject)18 NoSuchEntityException (javax.ejb.NoSuchEntityException)17 IOException (java.io.IOException)16 Test (org.junit.Test)16 EjbInvocation (com.sun.ejb.EjbInvocation)14 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)14 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)14 NamingException (javax.naming.NamingException)14 NotSerializableException (java.io.NotSerializableException)13 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)13