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();
}
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;
}
}
}
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);
}
}
}
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);
}
}
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);
}
}
Aggregations