use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class MessageBeanContextImpl method isCallerInRole.
public boolean isCallerInRole(String roleRef) {
if (roleRef == null)
throw new IllegalStateException("Argument is null");
checkAccessToCallerSecurity();
ComponentInvocation inv = EjbContainerUtilImpl.getInstance().getCurrentInvocation();
if (inv instanceof EjbInvocation) {
EjbInvocation ejbInv = (EjbInvocation) inv;
if (ejbInv.isTimerCallback) {
throw new IllegalStateException("isCallerInRole not allowed from timer callback");
}
} else {
throw new IllegalStateException("not invoked from within a message-bean context");
}
com.sun.enterprise.security.SecurityManager sm = container.getSecurityManager();
return sm.isCallerInRole(roleRef);
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method beforeCompletion.
protected void beforeCompletion(EJBContextImpl context) {
// Do not call beforeCompletion if it is a transactional lifecycle callback
if (isBeanManagedTran || beforeCompletionMethod == null || ((SessionContextImpl) context).getInLifeCycleCallback()) {
return;
}
Object ejb = context.getEJB();
// No need to check for a concurrent invocation
// because beforeCompletion can only be called after
// all business methods are completed.
EjbInvocation inv = super.createEjbInvocation(ejb, context);
invocationManager.preInvoke(inv);
try {
transactionManager.enlistComponentResources();
beforeCompletionMethod.invoke(ejb, null);
} catch (Exception ex) {
// Error during beforeCompletion, so discard bean: EJB2.0 18.3.3
try {
forceDestroyBean(context);
} catch (Exception e) {
_logger.log(Level.FINE, "error destroying bean", e);
}
throw new EJBException("Error during SessionSynchronization." + "beforeCompletion, EJB instance discarded", ex);
} finally {
invocationManager.postInvoke(inv);
}
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method findExtendedEMFromInvList.
private PhysicalEntityManagerWrapper findExtendedEMFromInvList(EntityManagerFactory emf) {
PhysicalEntityManagerWrapper em = null;
ComponentInvocation compInv = (ComponentInvocation) invocationManager.getCurrentInvocation();
if (compInv != null) {
if (compInv.getInvocationType() == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
EjbInvocation ejbInv = (EjbInvocation) compInv;
if (ejbInv.context instanceof SessionContextImpl) {
SessionContextImpl ctxImpl = (SessionContextImpl) ejbInv.context;
if (ctxImpl.container instanceof StatefulSessionContainer) {
em = ctxImpl.getExtendedEntityManager(emf);
}
}
}
}
return em;
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method callEjbAfterCompletion.
private void callEjbAfterCompletion(SessionContextImpl context, boolean status) {
if (afterCompletionMethod != null) {
Object ejb = context.getEJB();
EjbInvocation ejbInv = createEjbInvocation(ejb, context);
invocationManager.preInvoke(ejbInv);
try {
context.setInAfterCompletion(true);
afterCompletionMethod.invoke(ejb, status);
// reset flags
context.setAfterCompletionDelayed(false);
context.setTxCompleting(false);
} catch (Exception ex) {
Throwable realException = ex;
if (ex instanceof InvocationTargetException) {
realException = ((InvocationTargetException) ex).getTargetException();
}
// Error during afterCompletion, so discard bean: EJB2.0 18.3.3
try {
forceDestroyBean(context);
} catch (Exception e) {
_logger.log(Level.FINE, "error destroying bean", e);
}
_logger.log(Level.INFO, AFTER_COMPLETION_EXCEPTION, realException);
// No use throwing an exception here, since the tx has already
// completed, and afterCompletion may be called asynchronously
// when there is no client to receive the exception.
} finally {
context.setInAfterCompletion(false);
invocationManager.postInvoke(ejbInv);
}
}
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method activateEJB.
// called from StatefulSessionStore
public void activateEJB(Object sessionKey, StatefulEJBContext sfsbCtx, Object cookie) {
SessionContextImpl context = (SessionContextImpl) sfsbCtx.getSessionContext();
if (_logger.isLoggable(TRACE_LEVEL)) {
logTraceInfo(context, "Attempting to activate");
}
EJBLocalRemoteObject ejbObject = (EJBLocalRemoteObject) cookie;
Object ejb = context.getEJB();
EjbInvocation ejbInv = createEjbInvocation(ejb, context);
invocationManager.preInvoke(ejbInv);
boolean needToDoPostInvokeTx = false;
try {
// we're sure that no concurrent thread can be using this bean
// so no need to synchronize.
// No need to call enlistComponentResources here because
// ejbActivate executes in unspecified tx context (spec 6.6.1)
// Set the timestamp here, else Recycler might remove this bean!
context.touch();
context.setContainer(this);
context.setState(BeanState.READY);
incrementMethodReadyStat();
context.setInstanceKey(sessionKey);
context.setExistsInStore(true);
context.initializeStatefulWriteLock();
if (ejbObject == null) {
// This MUST be a remote invocation
if (hasRemoteHomeView) {
createEJBObjectImpl(context);
} else {
createRemoteBusinessObjectImpl(context);
}
} else if (ejbObject instanceof EJBObjectImpl) {
EJBObjectImpl eo = (EJBObjectImpl) ejbObject;
ejbObject.setContext(context);
ejbObject.setKey(sessionKey);
byte[] sessionOID = uuidGenerator.keyToByteArray(sessionKey);
if (eo.isRemoteHomeView()) {
// introduce context and EJBObject to each other
context.setEJBObjectImpl(eo);
EJBObject ejbStub = (EJBObject) remoteHomeRefFactory.createRemoteReference(sessionOID);
eo.setStub(ejbStub);
context.setEJBStub(ejbStub);
if (hasRemoteBusinessView) {
createRemoteBusinessObjectImpl(context);
}
} else {
context.setEJBRemoteBusinessObjectImpl(eo);
for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
java.rmi.Remote stub = next.referenceFactory.createRemoteReference(sessionOID);
eo.setStub(next.generatedRemoteIntf.getName(), stub);
}
if (hasRemoteHomeView) {
createEJBObjectImpl(context);
}
}
if (isLocal) {
// create localObj too
if (hasLocalHomeView) {
createEJBLocalObjectImpl(context);
}
if (hasLocalBusinessView) {
createEJBLocalBusinessObjectImpl(context);
}
if (hasOptionalLocalBusinessView) {
createOptionalEJBLocalBusinessObjectImpl(context);
}
}
} else if (ejbObject instanceof EJBLocalObjectImpl) {
EJBLocalObjectImpl elo = (EJBLocalObjectImpl) ejbObject;
ejbObject.setContext(context);
ejbObject.setKey(sessionKey);
if (elo.isLocalHomeView()) {
context.setEJBLocalObjectImpl(elo);
if (hasLocalBusinessView) {
createEJBLocalBusinessObjectImpl(context);
}
if (hasOptionalLocalBusinessView) {
createOptionalEJBLocalBusinessObjectImpl(context);
}
} else if (elo.isOptionalLocalBusinessView()) {
context.setOptionalEJBLocalBusinessObjectImpl(elo);
if (hasLocalBusinessView) {
createEJBLocalBusinessObjectImpl(context);
}
if (hasLocalHomeView) {
createEJBLocalObjectImpl(context);
}
} else {
context.setEJBLocalBusinessObjectImpl(elo);
if (hasLocalHomeView) {
createEJBLocalObjectImpl(context);
}
if (hasOptionalLocalBusinessView) {
createOptionalEJBLocalBusinessObjectImpl(context);
}
}
if (hasRemoteHomeView) {
// create remote obj too
createEJBObjectImpl(context);
}
if (hasRemoteBusinessView) {
createRemoteBusinessObjectImpl(context);
}
}
// Now populate the EEM maps in this context
repopulateEEMMapsInContext(sessionKey, context);
try {
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, context, postActivateInvInfo, CallbackType.POST_ACTIVATE);
} catch (Throwable th) {
EJBException ejbEx = new EJBException("Error during activation" + sessionKey);
ejbEx.initCause(th);
throw ejbEx;
}
long now = System.currentTimeMillis();
try {
backingStore.updateTimestamp((Serializable) sessionKey, now);
context.setLastPersistedAt(now);
} catch (BackingStoreException sfsbEx) {
_logger.log(Level.WARNING, COULDNT_UPDATE_TIMESTAMP_FOR_EXCEPTION, new Object[] { sessionKey, sfsbEx });
_logger.log(Level.FINE, "Couldn't update timestamp for: " + sessionKey, sfsbEx);
}
if (_logger.isLoggable(TRACE_LEVEL)) {
logTraceInfo(context, "Successfully activated");
}
_logger.log(Level.FINE, "Activated: " + sessionKey);
} catch (Exception ex) {
if (_logger.isLoggable(TRACE_LEVEL)) {
logTraceInfo(context, "Failed to activate");
}
_logger.log(Level.SEVERE, SFSB_ACTIVATION_ERROR, new Object[] { sessionKey, ex });
_logger.log(Level.SEVERE, "", ex);
throw new EJBException("Unable to activate EJB for key: " + sessionKey, ex);
} finally {
invocationManager.postInvoke(ejbInv);
completeLifecycleCallbackTxIfUsed(ejbInv, context, needToDoPostInvokeTx);
}
}
Aggregations