Search in sources :

Example 66 with EJBException

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

the class AsynchronousTask method afterInstanceCreation.

private void afterInstanceCreation(SessionContextImpl context) throws Exception {
    context.setState(BeanState.READY);
    EjbInvocation ejbInv = null;
    boolean inTx = false;
    try {
        // Need to do preInvoke because setSessionContext can access JNDI
        ejbInv = super.createEjbInvocation(context.getEJB(), context);
        invocationManager.preInvoke(ejbInv);
        // PostConstruct must be called after state set to something
        // other than CREATED
        inTx = callLifecycleCallbackInTxIfUsed(ejbInv, context, postConstructInvInfo, CallbackType.POST_CONSTRUCT);
    } catch (Throwable t) {
        EJBException ejbEx = new EJBException();
        ejbEx.initCause(t);
        throw ejbEx;
    } finally {
        if (ejbInv != null) {
            try {
                invocationManager.postInvoke(ejbInv);
                if (inTx) {
                    // Call directly to report exception
                    postInvokeTx(ejbInv);
                }
            } catch (Exception pie) {
                if (ejbInv.exception != null) {
                    _logger.log(Level.FINE, "Exception during SFSB startup postInvoke ", pie);
                } else {
                    ejbInv.exception = pie;
                    CreateException creEx = new CreateException("Initialization failed for Stateful Session Bean " + ejbDescriptor.getName());
                    creEx.initCause(pie);
                    throw creEx;
                }
            } finally {
                context.setInLifeCycleCallback(false);
            }
        }
    }
    ejbProbeNotifier.ejbBeanCreatedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName);
    incrementMethodReadyStat();
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) IllegalLoopbackException(javax.ejb.IllegalLoopbackException) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) RemoveException(javax.ejb.RemoveException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 67 with EJBException

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

the class AsynchronousTask method createRemoteBusinessObjectImpl.

protected EJBObjectImpl createRemoteBusinessObjectImpl() throws CreateException, RemoteException {
    try {
        SessionContextImpl context = createBeanInstance();
        EJBObjectImpl ejbBusinessObjImpl = createRemoteBusinessObjectImpl(context);
        afterInstanceCreation(context);
        return ejbBusinessObjImpl;
    } catch (Exception ex) {
        _logger.log(Level.WARNING, CREATE_EJBOBJECT_EXCEPTION, new Object[] { ejbDescriptor.getName(), ex });
        if (ex instanceof EJBException)
            throw (EJBException) ex;
        else {
            CreateException ce = new CreateException("ERROR creating stateful SessionBean");
            ce.initCause(ex);
            throw ce;
        }
    }
}
Also used : EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) IllegalLoopbackException(javax.ejb.IllegalLoopbackException) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) RemoveException(javax.ejb.RemoveException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 68 with EJBException

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

the class AsynchronousTask method repopulateEEMMapsInContext.

private void repopulateEEMMapsInContext(Object sessionKey, SessionContextImpl context) {
    Collection<EEMRefInfo> allRefInfos = context.getAllEEMRefInfos();
    for (EEMRefInfo refInfo : allRefInfos) {
        EEMRefInfoKey key = refInfo.getKey();
        synchronized (extendedEMReferenceCountMap) {
            EntityManager eMgr = eemKey2EEMMap.get(key);
            EEMRefInfo newRefInfo = null;
            if (eMgr != null) {
                EEMRefInfo cachedRefInfo = extendedEMReferenceCountMap.get(eMgr);
                // cachedRefInfo cannot be null
                context.addExtendedEntityManagerMapping(cachedRefInfo.getEntityManagerFactory(), cachedRefInfo);
                cachedRefInfo.refCount++;
                newRefInfo = cachedRefInfo;
            } else {
                // Deserialize em from the byte[]
                String emRefName = key.emRefName;
                String unitName = refInfo.getUnitName();
                EntityManagerFactory emf = EntityManagerFactoryWrapper.lookupEntityManagerFactory(ComponentInvocation.ComponentInvocationType.EJB_INVOCATION, unitName, ejbDescriptor);
                if (emf != null) {
                    try (ByteArrayInputStream bis = new ByteArrayInputStream(refInfo.serializedEEM);
                        ObjectInputStream ois = new ObjectInputStream(bis)) {
                        eMgr = (EntityManager) ois.readObject();
                        newRefInfo = new EEMRefInfo(emRefName, unitName, refInfo.getSynchronizationType(), super.getContainerId(), sessionKey, eMgr, emf);
                        newRefInfo.refCount = 1;
                        extendedEMReferenceCountMap.put(eMgr, newRefInfo);
                        eemKey2EEMMap.put(newRefInfo.getKey(), newRefInfo.getEntityManager());
                    } catch (Throwable th) {
                        EJBException ejbEx = new EJBException("Couldn't create EntityManager for" + " refName: " + emRefName);
                        ejbEx.initCause(th);
                        throw ejbEx;
                    }
                } else {
                    throw new EJBException("EMF is null. Couldn't get extended EntityManager for" + " refName: " + emRefName);
                }
            }
            context.addExtendedEntityManagerMapping(newRefInfo.getEntityManagerFactory(), newRefInfo);
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityManagerFactory(javax.persistence.EntityManagerFactory) EJBException(javax.ejb.EJBException) ObjectInputStream(java.io.ObjectInputStream)

Example 69 with EJBException

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

the class StatelessSessionContainer method _getContext.

/**
 * Called from preInvoke which is called from the EJBObject
 * for local and remote invocations.
 */
protected ComponentContext _getContext(EjbInvocation inv) {
    try {
        SessionContextImpl sessionCtx = (SessionContextImpl) pool.getObject(null);
        sessionCtx.setState(EJBContextImpl.BeanState.INVOKING);
        return sessionCtx;
    } catch (Exception ex) {
        throw new EJBException(ex);
    }
}
Also used : EJBException(javax.ejb.EJBException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 70 with EJBException

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

the class ActiveTxCache method preFind.

/**
 * Called from getContext before the ejb.ejbFind* is called
 */
protected void preFind(EjbInvocation inv, EntityContextImpl context) {
    // all updates done previously in the client's tx.
    if (willInvokeWithClientTx(inv) && !inv.method.getName().equals("findByPrimaryKey")) {
        Transaction tx = null;
        try {
            tx = transactionManager.getTransaction();
        } catch (SystemException ex) {
            throw new EJBException(ex);
        }
        storeAllBeansInTx(tx);
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) EJBException(javax.ejb.EJBException)

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