Search in sources :

Example 1 with ComponentContext

use of com.sun.ejb.ComponentContext in project Payara by payara.

the class TimerWrapper method checkCallPermission.

/**
 * Verify that Timer method access is allowed from this context.
 * This method is static so that TimerHandle can call it even
 * before it has created a TimerWrapper instance.
 */
private static void checkCallPermission() throws IllegalStateException {
    // Can't store a static ref because in embedded container it can be
    // changed by server restart
    EjbContainerUtil ejbContainerUtil = EjbContainerUtilImpl.getInstance();
    ComponentInvocation inv = ejbContainerUtil.getCurrentInvocation();
    if (inv == null) {
        throw new IllegalStateException("Invocation cannot be null");
    }
    ComponentInvocation.ComponentInvocationType invType = inv.getInvocationType();
    if (invType == ComponentInvocation.ComponentInvocationType.EJB_INVOCATION) {
        if (inv instanceof EjbInvocation) {
            ComponentContext context = ((EjbInvocation) inv).context;
            // Delegate check to EJB context.  Let any
            // IllegalStateException bubble up.
            context.checkTimerServiceMethodAccess();
        }
    }
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) ComponentContext(com.sun.ejb.ComponentContext) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation)

Example 2 with ComponentContext

use of com.sun.ejb.ComponentContext in project Payara by payara.

the class AsynchronousTask method passivateBeansOnShutdown.

private void passivateBeansOnShutdown() {
    ClassLoader origLoader = Utility.setContextClassLoader(loader);
    try {
        _logger.log(Level.FINE, "Passivating SFSBs before container shutdown");
        if (!isPassivationCapable() && _logger.isLoggable(Level.INFO)) {
            _logger.log(Level.INFO, SFSB_NOT_RESTORED_AFTER_RESTART);
        }
        sessionBeanCache.shutdown();
        while (true) {
            ComponentContext ctx = null;
            synchronized (asyncTaskSemaphore) {
                int sz = passivationCandidates.size();
                if (sz > 0) {
                    ctx = (ComponentContext) passivationCandidates.remove(sz - 1);
                } else {
                    break;
                }
            }
            passivateEJB(ctx);
        }
        sessionBeanCache.destroy();
        cacheProbeListener.unregister();
        try {
            // backingStore will be null when passivation-capable is false
            if (backingStore != null) {
                backingStore.close();
            }
        } catch (BackingStoreException sfsbEx) {
            _logger.log(Level.WARNING, ERROR_DURING_BACKING_STORE_SHUTDOWN, new Object[] { ejbName, sfsbEx });
        }
    } catch (Throwable th) {
        _logger.log(Level.WARNING, ERROR_DURING_ON_SHUTDOWN, new Object[] { ejbName, th });
    } finally {
        Utility.setContextClassLoader(origLoader);
    }
}
Also used : ComponentContext(com.sun.ejb.ComponentContext) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) EJBObject(javax.ejb.EJBObject)

Example 3 with ComponentContext

use of com.sun.ejb.ComponentContext in project Payara by payara.

the class WebServiceInvocationHandler method invoke.

private Object invoke(Method method, Object[] args, EjbInvocation inv) throws Exception {
    try {
        inv.ejbObject = this;
        // find the right method object on the SIB.
        if (endpoint_.getServiceEndpointInterface().equals(ejbClass_.getName())) {
            // we need to substiture the method object
            method = ejbClass_.getMethod(method.getName(), method.getParameterTypes());
        }
        inv.method = method;
        inv.clientInterface = serviceEndpointIntfClass_;
        inv.invocationInfo = (InvocationInfo) invocationInfoMap_.get(inv.method);
        if (inv.invocationInfo == null) {
            throw new EJBException("Web service Invocation Info lookup failed for method " + inv.method);
        }
        inv.transactionAttribute = inv.invocationInfo.txAttr;
        // special handling of jaxrpc endpoints (identfied by mapping file)
        if (endpoint_.getWebService().hasMappingFile()) {
            if (hasHandlers_) {
            // Handler performed method authorization already
            } else {
                final boolean authorized = container.authorize(inv);
                if (!authorized) {
                    throw new AccessLocalException("Client not authorized to access " + inv.method);
                }
            }
        } else if (hasHandlers_) {
            // jaxws enpoint
            // authorization was done in security pipe
            // Now that application handlers have run, do
            // another method lookup and compare the results
            // with the original one. This ensures that the
            // application handlers have not changed
            // which method is invoked.
            final Method methodBefore = inv.getWebServiceMethod();
            if (methodBefore != null && !methodBefore.equals(inv.method)) {
                inv.exception = new UnmarshalException(localStrings.getLocalString("enterprise.webservice.postHandlerMethodMismatch", "Original Method {0} does not match post-handler method {1}", new Object[] { methodBefore, inv.method }));
                throw inv.exception;
            }
        }
        final ComponentContext ctx = container.getContext(inv);
        inv.context = ctx;
        inv.ejb = ctx.getEJB();
        inv.instance = inv.ejb;
        container.preInvokeTx(inv);
        // Enterprise Bean class doesn't necessarily implement
        // web service endpoint interface, so we can't directly
        // dispatch through the given method object.
        final Method beanClassMethod = ejbClass_.getMethod(method.getName(), method.getParameterTypes());
        inv.beanMethod = beanClassMethod;
        inv.methodParams = args;
        return container.intercept(inv);
    } catch (NoSuchMethodException nsme) {
        inv.exception = nsme;
        return null;
    } catch (InvocationTargetException ite) {
        inv.exception = ite.getCause();
        return null;
    } catch (Throwable c) {
        inv.exception = c;
        return null;
    } finally {
        if (inv.ejb != null) {
            // Do post invoke tx processing so that a commit failure
            // will be visible to web service client.
            container.postInvokeTx(inv);
        }
    }
}
Also used : ComponentContext(com.sun.ejb.ComponentContext) UnmarshalException(java.rmi.UnmarshalException) AccessLocalException(javax.ejb.AccessLocalException) Method(java.lang.reflect.Method) EJBException(javax.ejb.EJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ComponentContext

use of com.sun.ejb.ComponentContext in project Payara by payara.

the class SafeProperties method preInvoke.

/**
 * Called from EJBObject/EJBHome before invoking on EJB.
 * Set the EJB instance in the EjbInvocation.
 *
 * It must be ensured that the following general pattern
 * is followed by various parts of the EJBContainer code:
 *
 * try {
 *      container.preInvoke(inv);
 *      returnValue = container.intercept(inv);
 * } catch (Exception1 e1) {
 *      ...
 * } catch (Exception2 e2) {
 *      ...
 * } finally {
 *      container.postInvoke();
 * }
 */
@Override
public void preInvoke(EjbInvocation inv) {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Entering BaseContainer::preInvoke : " + inv);
    }
    try {
        if (containerState != CONTAINER_STARTED) {
            throw new EJBException(localStrings.getLocalString("ejb.container_not_started", "Attempt to invoke when container is in {0}", containerStateToString(containerState)));
        }
        if (inv.method == null) {
            throw new EJBException(localStrings.getLocalString("ejb.null_invocation_method", "Attempt to invoke container with null invocation method"));
        }
        if (inv.invocationInfo == null) {
            inv.invocationInfo = getInvocationInfo(inv);
            if (inv.invocationInfo == null) {
                throw new EJBException(localStrings.getLocalString("ejb.null_invocation_info", "EjbInvocation Info lookup failed for method {0}", inv.method));
            }
        }
        inv.transactionAttribute = inv.invocationInfo.txAttr;
        inv.container = this;
        if (inv.mustInvokeAsynchronously()) {
            return;
        }
        if (doPreInvokeAuthorization(inv)) {
            if (!authorize(inv)) {
                throw new AccessLocalException(localStrings.getLocalString("ejb.client_not_authorized", "Client not authorized for this invocation"));
            }
        }
        // Cache value of txManager.getStatus() in invocation to avoid
        // multiple thread-local accesses of that value during pre-invoke
        // stage.
        inv.setPreInvokeTxStatus(transactionManager.getStatus());
        ComponentContext ctx = getContext(inv);
        inv.context = ctx;
        inv.instance = inv.ejb = ctx.getEJB();
        InvocationInfo info = inv.invocationInfo;
        inv.useFastPath = (info.isTxRequiredLocalCMPField) && (inv.foundInTxCache);
        if (!inv.useFastPath) {
            // Sets thread-specific state for Transaction, Naming, Security,
            // etc
            invocationManager.preInvoke(inv);
            // Do Tx machinery
            preInvokeTx(inv);
            // null out invocation preInovkeTxStatus since the cache value
            // is obsolete
            inv.setPreInvokeTxStatus(null);
            enlistExtendedEntityManagers(ctx);
        }
    } catch (Exception ex) {
        _logger.log(Level.FINE, "Exception while running pre-invoke : ejbName = [{0}]", logParams);
        _logger.log(Level.FINE, "", ex);
        EJBException ejbEx;
        if (ex instanceof EJBException) {
            ejbEx = (EJBException) ex;
        } else {
            ejbEx = new EJBException(ex);
        }
        throw new PreInvokeException(ejbEx);
    }
}
Also used : InvocationInfo(com.sun.ejb.InvocationInfo) ComponentContext(com.sun.ejb.ComponentContext) InvocationTargetException(java.lang.reflect.InvocationTargetException) DeploymentException(org.glassfish.deployment.common.DeploymentException) AccessException(java.rmi.AccessException) SystemException(javax.transaction.SystemException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) RollbackException(javax.transaction.RollbackException)

Example 5 with ComponentContext

use of com.sun.ejb.ComponentContext in project Payara by payara.

the class ReadOnlyBeanContainer method _getContext.

protected ComponentContext _getContext(EjbInvocation inv) {
    ComponentContext ctx = super._getContext(inv);
    // info cannot be null
    InvocationInfo info = inv.invocationInfo;
    if (info.isTxRequiredLocalCMPField) {
        if (!inv.foundInTxCache) {
            EntityContextImpl entityCtx = (EntityContextImpl) ctx;
            super.afterBegin(entityCtx);
            inv.foundInTxCache = true;
        }
    } else {
    // TODO: We can still optimize NonTx access to CMP getters/setters
    }
    return ctx;
}
Also used : InvocationInfo(com.sun.ejb.InvocationInfo) ComponentContext(com.sun.ejb.ComponentContext)

Aggregations

ComponentContext (com.sun.ejb.ComponentContext)5 InvocationInfo (com.sun.ejb.InvocationInfo)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 EjbInvocation (com.sun.ejb.EjbInvocation)1 Method (java.lang.reflect.Method)1 AccessException (java.rmi.AccessException)1 RemoteException (java.rmi.RemoteException)1 UnmarshalException (java.rmi.UnmarshalException)1 AccessLocalException (javax.ejb.AccessLocalException)1 EJBException (javax.ejb.EJBException)1 EJBObject (javax.ejb.EJBObject)1 NamingException (javax.naming.NamingException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)1 DeploymentException (org.glassfish.deployment.common.DeploymentException)1 BackingStoreException (org.glassfish.ha.store.api.BackingStoreException)1