Search in sources :

Example 36 with EjbInvocation

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

the class EJBLocalObjectInvocationHandler method invoke.

Object invoke(Class clientInterface, Method method, Object[] args) throws Throwable {
    ClassLoader originalClassLoader = null;
    // if method signature has 0 arguments.
    try {
        container.onEnteringContainer();
        if (Thread.currentThread().getContextClassLoader() != getContainer().getClassLoader()) {
            originalClassLoader = Utility.setContextClassLoader(getContainer().getClassLoader());
        }
        Class methodClass = method.getDeclaringClass();
        if (methodClass == java.lang.Object.class) {
            return InvocationHandlerUtil.invokeJavaObjectMethod(this, method, args);
        } else if (methodClass == IndirectlySerializable.class) {
            return this.getSerializableObjectFactory();
        }
        // Use optimized version of get that takes param count as an argument.
        InvocationInfo invInfo = (InvocationInfo) invocationInfoMap_.get(method, ((args != null) ? args.length : 0));
        if (invInfo == null) {
            throw new IllegalStateException("Unknown method :" + method);
        }
        if ((methodClass == javax.ejb.EJBLocalObject.class) || invInfo.ejbIntfOverride) {
            return invokeEJBLocalObjectMethod(method.getName(), args);
        } else if (invInfo.targetMethod1 == null) {
            Object[] params = new Object[] { invInfo.ejbName, "Local", invInfo.method.toString() };
            logger.log(Level.SEVERE, "ejb.bean_class_method_not_found", params);
            String errorMsg = localStrings.getLocalString("ejb.bean_class_method_not_found", "", params);
            throw new EJBException(errorMsg);
        }
        // Process application-specific method.
        Object returnValue = null;
        EjbInvocation inv = container.createEjbInvocation();
        inv.isLocal = true;
        inv.isBusinessInterface = !isLocalHomeView();
        inv.isHome = false;
        inv.ejbObject = this;
        inv.method = method;
        inv.methodParams = args;
        inv.clientInterface = clientInterface;
        // Set cached invocation params.  This will save additional lookups
        // in BaseContainer.
        inv.transactionAttribute = invInfo.txAttr;
        inv.invocationInfo = invInfo;
        inv.beanMethod = invInfo.targetMethod1;
        try {
            container.preInvoke(inv);
            returnValue = container.intercept(inv);
        } catch (InvocationTargetException ite) {
            inv.exception = ite.getCause();
            inv.exceptionFromBeanMethod = inv.exception;
        } catch (Throwable t) {
            inv.exception = t;
        } finally {
            container.postInvoke(inv);
        }
        if (inv.exception != null) {
            InvocationHandlerUtil.throwLocalException(inv.exception, method.getExceptionTypes());
        }
        return returnValue;
    } finally {
        if (originalClassLoader != null) {
            Utility.setContextClassLoader(originalClassLoader);
        }
        container.onLeavingContainer();
    }
}
Also used : InvocationInfo(com.sun.ejb.InvocationInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) EjbInvocation(com.sun.ejb.EjbInvocation) IndirectlySerializable(com.sun.enterprise.container.common.spi.util.IndirectlySerializable) EJBLocalObject(javax.ejb.EJBLocalObject) EJBException(javax.ejb.EJBException)

Example 37 with EjbInvocation

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

the class EJBObjectInvocationHandler method invoke.

Object invoke(Class clientInterface, Method method, Object[] args) throws Throwable {
    ClassLoader originalClassLoader = null;
    // if method signature has 0 arguments.
    try {
        container.onEnteringContainer();
        if (Thread.currentThread().getContextClassLoader() != getContainer().getClassLoader()) {
            originalClassLoader = Utility.setContextClassLoader(getContainer().getClassLoader());
        }
        Class methodClass = method.getDeclaringClass();
        if (methodClass == java.lang.Object.class) {
            return InvocationHandlerUtil.invokeJavaObjectMethod(this, method, args);
        }
        // Use optimized version of get that takes param count as an
        // argument.
        InvocationInfo invInfo = (InvocationInfo) invocationInfoMap_.get(method, ((args != null) ? args.length : 0));
        if (invInfo == null) {
            throw new RemoteException("Unknown Remote interface method :" + method);
        }
        if ((methodClass == javax.ejb.EJBObject.class) || invInfo.ejbIntfOverride) {
            return invokeEJBObjectMethod(method.getName(), args);
        } else if (invInfo.targetMethod1 == null) {
            Object[] params = new Object[] { invInfo.ejbName, "Remote", invInfo.method.toString() };
            String errorMsg = localStrings.getLocalString("ejb.bean_class_method_not_found", "", params);
            _logger.log(Level.SEVERE, "ejb.bean_class_method_not_found", params);
            throw new RemoteException(errorMsg);
        }
        // Process application-specific method.
        Object returnValue = null;
        EjbInvocation inv = container.createEjbInvocation();
        inv.isRemote = true;
        inv.isHome = false;
        inv.isBusinessInterface = !isRemoteHomeView();
        inv.ejbObject = this;
        inv.method = method;
        inv.clientInterface = clientInterface;
        // Set cached invocation params.  This will save additional lookups
        // in BaseContainer.
        inv.transactionAttribute = invInfo.txAttr;
        inv.invocationInfo = invInfo;
        inv.beanMethod = invInfo.targetMethod1;
        inv.methodParams = args;
        try {
            container.preInvoke(inv);
            returnValue = container.intercept(inv);
        } catch (InvocationTargetException ite) {
            inv.exception = ite.getCause();
            inv.exceptionFromBeanMethod = inv.exception;
        } catch (Throwable t) {
            inv.exception = t;
        } finally {
            container.postInvoke(inv);
            // purge ThreadLocals before the thread is returned to pool
            if (container.getSecurityManager() != null) {
                container.getSecurityManager().resetPolicyContext();
            }
        }
        if (inv.exception != null) {
            InvocationHandlerUtil.throwRemoteException(inv.exception, method.getExceptionTypes());
        }
        return returnValue;
    } finally {
        if (originalClassLoader != null) {
            Utility.setContextClassLoader(originalClassLoader);
        }
        container.onLeavingContainer();
    }
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) InvocationInfo(com.sun.ejb.InvocationInfo) EJBObject(javax.ejb.EJBObject) RemoteException(java.rmi.RemoteException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 38 with EjbInvocation

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

the class EjbAsyncInvocationManager method remoteCancel.

RemoteAsyncResult remoteCancel(Long asyncTaskID) {
    EjbFutureTask task = getLocalTaskForID(asyncTaskID);
    if (_logger.isLoggable(Level.FINE)) {
        EjbAsyncTask asyncTask = task.getEjbAsyncTask();
        _logger.log(Level.FINE, "Enter remoteCancel for async task " + asyncTaskID + " : " + asyncTask.getEjbInvocation());
    }
    RemoteAsyncResult result = null;
    if (task.isDone()) {
        // Since the task is done just return the result on this
        // internal remote request.
        result = new RemoteAsyncResult();
        result.resultException = task.getResultException();
        result.resultValue = task.getResultValue();
        result.asyncID = asyncTaskID;
        // The client object won't make another request once it
        // has the result so we can remove it from the container map.
        remoteTaskMap.remove(asyncTaskID);
    } else {
        // Set flag on invocation so bean method has visibility to
        // the fact that client called cancel()
        EjbInvocation inv = task.getEjbAsyncTask().getEjbInvocation();
        inv.setWasCancelCalled(true);
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "Exit remoteCancel for async task " + asyncTaskID + " : " + task);
    }
    return result;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation)

Example 39 with EjbInvocation

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

the class EjbAsyncInvocationManager method submit.

public Future submit(EjbInvocation inv) {
    // We need to clone this invocation as submitting
    // so that the inv is *NOT* shared between the
    // current thread and the executor service thread
    EjbInvocation asyncInv = inv.clone();
    // EjbInvocation.clone clears the txOpsManager field so getTransactionOperationsManager()
    // returns null *after* EjbInvocation.clone(). However, in this case, we do want the original
    // TransactionOperationsManager so we explicitly set it after calling clone.
    // 
    // Note: EjbInvocation implements TransactionOperationsManager so we can use asyncInv to
    // be the TransactionOperationsManager for the new cloned invocation
    asyncInv.setTransactionOperationsManager(asyncInv);
    // In most of the cases we don't want registry entries from being reused in the cloned
    // invocation, in which case, this method must be called. I am not sure if async
    // ejb invocation must call this (It never did and someone in ejb team must investigate
    // if clearRegistry() must be called from here)
    inv.clearYetToSubmitStatus();
    asyncInv.clearYetToSubmitStatus();
    EjbFutureTask futureTask = asyncInv.getEjbFutureTask();
    // EjbAsyncTask.initialize captures calling thread's
    // CallerPrincipal and sets it on the dispatch thread
    // before authorization.
    futureTask.getEjbAsyncTask().initialize(asyncInv);
    EjbContainerUtil ejbContainerUtil = EjbContainerUtilImpl.getInstance();
    return ejbContainerUtil.getThreadPoolExecutor(null).submit(futureTask.getEjbAsyncTask());
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation)

Example 40 with EjbInvocation

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

the class EjbEndpointFacadeImpl method startInvocation.

public ComponentInvocation startInvocation() {
    // We need to split the preInvoke tasks into stages since handlers
    // need access to java:comp/env and method authorization must take
    // place before handlers are run.  Note that the application
    // classloader was set much earlier when the invocation first arrived
    // so we don't need to set it here.
    EjbInvocation inv = container_.createEjbInvocation();
    // Do the portions of preInvoke that don't need a Method object.
    inv.isWebService = true;
    inv.container = container_;
    inv.transactionAttribute = Container.TX_NOT_INITIALIZED;
    // AS per latest spec change, the MessageContext object in WebSvcCtxt
    // should be the same one as used in the ejb's interceptors'
    // TODO
    // inv.setContextData(wsCtxt);
    // In all cases, the WebServiceInvocationHandler will do the
    // remaining preInvoke tasks : getContext, preInvokeTx, etc.
    invManager_.preInvoke(inv);
    return inv;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation)

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