use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class ActiveTxCache method internalRemoveBeanUnchecked.
/**
* Remove a bean. Used by the PersistenceManager.
* This is needed because the PM's remove must bypass tx/security checks.
*/
private void internalRemoveBeanUnchecked(EJBLocalRemoteObject localRemoteObj, boolean local) {
EjbInvocation inv = super.createEjbInvocation();
inv.ejbObject = localRemoteObj;
inv.isLocal = local;
inv.isRemote = !local;
Method method = null;
try {
method = EJBLocalObject.class.getMethod("remove", NO_PARAMS);
} catch (NoSuchMethodException e) {
_logger.log(Level.FINE, "Exception in internalRemoveBeanUnchecked()", e);
}
inv.method = method;
inv.invocationInfo = (InvocationInfo) invocationInfoMap.get(method);
try {
// First get a bean instance on which ejbRemove can be invoked.
// This code must be in sync with getContext().
// Can't call getContext() directly because it does stuff
// based on remove's txAttr.
// Assume there is a tx on the current thread.
EntityContextImpl context = getEJBWithIncompleteTx(inv);
if (context == null) {
context = getReadyEJB(inv);
}
synchronized (context) {
if (context.isInState(BeanState.INVOKING) && !isReentrant) {
throw new EJBException("EJB is already executing another request");
}
if (context.isInState(BeanState.POOLED) || context.isInState(BeanState.DESTROYED)) {
// this is an internal error.
throw new EJBException("Internal error: unknown EJB state");
}
context.setState(BeanState.INVOKING);
}
inv.context = context;
context.setLastTransactionStatus(-1);
context.incrementCalls();
inv.instance = inv.ejb = context.getEJB();
inv.container = this;
invocationManager.preInvoke(inv);
// call ejbLoad if necessary
useClientTx(context.getTransaction(), inv);
try {
context.setCascadeDeleteBeforeEJBRemove(true);
removeBean(inv);
} catch (Exception ex) {
_logger.log(Level.FINE, "Exception in internalRemoveBeanUnchecked()", ex);
// if system exception mark the tx for rollback
inv.exception = checkExceptionClientTx(context, ex);
}
if (inv.exception != null) {
throw inv.exception;
}
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new EJBException(ex);
} catch (Throwable ex) {
EJBException ejbEx = new EJBException();
ejbEx.initCause(ex);
throw ejbEx;
} finally {
invocationManager.postInvoke(inv);
releaseContext(inv);
}
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class ActiveTxCache method removeBean.
// Called from EJBObjectImpl.remove, EJBLocalObjectImpl.remove,
// and removeBean above.
protected void removeBean(EJBLocalRemoteObject ejbo, Method removeMethod, boolean local) throws RemoveException, EJBException, RemoteException {
EjbInvocation i = super.createEjbInvocation();
i.ejbObject = ejbo;
i.isLocal = local;
i.isRemote = !local;
i.method = removeMethod;
// Method must be a remove method defined on one of :
// javax.ejb.EJBHome, javax.ejb.EJBObject, javax.ejb.EJBLocalHome,
// javax.ejb.EJBLocalObject
Class declaringClass = removeMethod.getDeclaringClass();
i.isHome = ((declaringClass == javax.ejb.EJBHome.class) || (declaringClass == javax.ejb.EJBLocalHome.class));
try {
preInvoke(i);
removeBean(i);
} catch (Exception e) {
_logger.log(Level.SEVERE, "entitybean.container.preinvoke_exception", logParams);
_logger.log(Level.SEVERE, "", e);
i.exception = e;
} finally {
postInvoke(i);
}
if (i.exception != null) {
if (i.exception instanceof RemoveException) {
throw (RemoveException) i.exception;
} else if (i.exception instanceof RuntimeException) {
throw (RuntimeException) i.exception;
} else if (i.exception instanceof Exception) {
throw new EJBException((Exception) i.exception);
} else {
EJBException ejbEx = new EJBException();
ejbEx.initCause(i.exception);
throw ejbEx;
}
}
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class ActiveTxCache method passivateAndPoolEJB.
// called from addReadyEJB and afterCompletion
protected void passivateAndPoolEJB(EntityContextImpl context) {
if (context.isInState(BeanState.DESTROYED) || context.isInState(BeanState.POOLED))
return;
// if ( context.isPooled() ) {
// context.isPooled(false);
// return;
// }
EntityBean ejb = (EntityBean) context.getEJB();
synchronized (context) {
EjbInvocation inv = super.createEjbInvocation(ejb, context);
inv.method = ejbPassivateMethod;
invocationManager.preInvoke(inv);
try {
ejb.ejbPassivate();
} catch (Exception ex) {
_logger.log(Level.FINE, "Exception in passivateAndPoolEJB()", ex);
forceDestroyBean(context);
return;
} finally {
invocationManager.postInvoke(inv);
}
// remove EJB(Local)Object from ejb(Local)ObjectStore
Object primaryKey = context.getPrimaryKey();
if (isRemote) {
removeEJBObjectFromStore(primaryKey);
}
if (isLocal) {
ejbLocalObjectStore.remove(primaryKey);
}
addPooledEJB(context);
}
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class MessageBeanContainer method afterMessageDeliveryInternal.
private boolean afterMessageDeliveryInternal(ResourceHandle resourceHandle) {
// return value. assume failure until proven otherwise.
boolean success = false;
EjbInvocation invocation = null;
invocation = (EjbInvocation) invocationManager.getCurrentInvocation();
if (invocation == null) {
_logger.log(Level.SEVERE, "containers.mdb.no_invocation", new Object[] { appEJBName_, "" });
} else {
try {
if (invocation.isContainerStartsTx()) {
// Unregister the session associated with
// the message-driven bean's destination.
unregisterMessageBeanResource(resourceHandle);
}
// counterpart of invocationManager.preInvoke
invocationManager.postInvoke(invocation);
// Commit/Rollback container-managed transaction.
postInvokeTx(invocation);
// Consider successful delivery. Commit failure will be
// checked below.
success = true;
// TODO: Check if Tx existed / committed
ejbProbeNotifier.messageDeliveredEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName);
} catch (Throwable ce) {
_logger.log(Level.SEVERE, "containers.mdb.postinvoke_exception", new Object[] { appEJBName_, ce.toString() });
_logger.log(Level.SEVERE, ce.getClass().getName(), ce);
} finally {
releaseContext(invocation);
}
// Reset original class loader
Utility.setContextClassLoader(invocation.getOriginalContextClassLoader());
if (invocation.exception != null) {
if (isSystemUncheckedException(invocation.exception)) {
success = false;
}
// Log system exceptions by default and application exceptions
// only when log level is FINE or higher.
Level exLogLevel = isSystemUncheckedException(invocation.exception) ? Level.WARNING : Level.FINE;
_logger.log(exLogLevel, "containers.mdb.invocation_exception", new Object[] { appEJBName_, invocation.exception.toString() });
_logger.log(exLogLevel, invocation.exception.getClass().getName(), invocation.exception);
}
}
return success;
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class MessageBeanContainer method userTransactionMethodsAllowed.
public boolean userTransactionMethodsAllowed(ComponentInvocation inv) {
boolean utMethodsAllowed = false;
if (isBeanManagedTran) {
if (inv instanceof EjbInvocation) {
EjbInvocation ejbInvocation = (EjbInvocation) inv;
MessageBeanContextImpl mdc = (MessageBeanContextImpl) ejbInvocation.context;
utMethodsAllowed = (mdc.operationsAllowed()) ? true : false;
}
}
return utMethodsAllowed;
}
Aggregations