Search in sources :

Example 21 with EjbInvocation

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);
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 22 with EjbInvocation

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);
    }
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException) 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 23 with EjbInvocation

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;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) PhysicalEntityManagerWrapper(com.sun.enterprise.container.common.impl.PhysicalEntityManagerWrapper)

Example 24 with EjbInvocation

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);
        }
    }
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) EJBObject(javax.ejb.EJBObject) 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) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 25 with EjbInvocation

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);
    }
}
Also used : BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) 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) EjbInvocation(com.sun.ejb.EjbInvocation) EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException)

Aggregations

EjbInvocation (com.sun.ejb.EjbInvocation)44 EJBException (javax.ejb.EJBException)22 RemoteException (java.rmi.RemoteException)18 CreateException (javax.ejb.CreateException)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)16 RemoveException (javax.ejb.RemoveException)16 SystemException (javax.transaction.SystemException)15 EJBObject (javax.ejb.EJBObject)11 IOException (java.io.IOException)9 NotSerializableException (java.io.NotSerializableException)9 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)9 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)9 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)9 BackingStoreException (org.glassfish.ha.store.api.BackingStoreException)9 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)7 EJBLocalRemoteObject (com.sun.ejb.containers.EJBLocalRemoteObject)6 FinderException (javax.ejb.FinderException)6 NoSuchEntityException (javax.ejb.NoSuchEntityException)6 InvocationInfo (com.sun.ejb.InvocationInfo)4