Search in sources :

Example 11 with InvocationInfo

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

the class EJBLocalHomeInvocationHandler method invoke.

/**
 * Called by EJBLocalHome proxy.
 */
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    LOG.finest(() -> String.format("invoke(proxy=%s, method=%s, args=%s)", proxy, method, Arrays.toString(args)));
    ClassLoader originalClassLoader = null;
    // if method signature has 0 arguments.
    try {
        getContainer().onEnteringContainer();
        if (Thread.currentThread().getContextClassLoader() != getContainer().getClassLoader()) {
            originalClassLoader = Utility.setContextClassLoader(getContainer().getClassLoader());
        }
        final Class methodClass = method.getDeclaringClass();
        if (methodClass == java.lang.Object.class) {
            return InvocationHandlerUtil.invokeJavaObjectMethod(this, method, args);
        } else if (methodClass == IndirectlySerializable.class) {
            return this.getSerializableObjectFactory();
        } else if (handleSpecialEJBLocalHomeMethod(method, methodClass)) {
            return invokeSpecialEJBLocalHomeMethod(method, methodClass, args);
        }
        // Use optimized version of get that takes param count as an argument.
        final InvocationInfo invInfo = (InvocationInfo) invocationInfoMap.get(method, (args == null ? 0 : args.length));
        if (invInfo == null) {
            throw new IllegalStateException("Unknown method: " + method);
        }
        if ((methodClass == javax.ejb.EJBLocalHome.class) || invInfo.ejbIntfOverride) {
            // There is exactly one argument on javax.ejb.EJBLocalHome: primaryKey
            super.remove(args[0]);
            return null;
        } else if (methodClass == GenericEJBLocalHome.class) {
            // This is a creation request through the EJB 3.0
            // client view, so just create a local business object and
            // return it.
            final EJBLocalObjectImpl localImpl = createEJBLocalBusinessObjectImpl((String) args[0]);
            return localImpl.getClientObject((String) args[0]);
        }
        // Process finder, create method, or home method.
        EJBLocalObjectImpl localObjectImpl = null;
        if (invInfo.startsWithCreate) {
            localObjectImpl = createEJBLocalObjectImpl();
            if (localObjectImpl != null) {
                if (isStatelessSession) {
                    return localObjectImpl.getClientObject();
                }
            }
        }
        if (isStatelessSession) {
            return null;
        }
        if (invInfo.targetMethod1 == null) {
            final LocalStringManagerImpl msgs = new LocalStringManagerImpl(EJBLocalHomeInvocationHandler.class);
            final Object[] params = new Object[] { invInfo.ejbName, "LocalHome", invInfo.method.toString() };
            final String errorMsg = msgs.getLocalString("ejb.bean_class_method_not_found", "", params);
            throw new EJBException(errorMsg);
        }
        final EjbInvocation inv = getContainer().createEjbInvocation();
        inv.isLocal = true;
        inv.isHome = true;
        inv.method = method;
        inv.clientInterface = localHomeIntfClass;
        // Set cached invocation params. This will save additional lookups
        // in BaseContainer.
        inv.transactionAttribute = invInfo.txAttr;
        inv.invocationInfo = invInfo;
        if (localObjectImpl != null && invInfo.startsWithCreate) {
            inv.ejbObject = localObjectImpl;
        }
        final Object returnValue = invokeBean(args, invInfo, inv);
        if (inv.exception != null) {
            InvocationHandlerUtil.throwLocalException(inv.exception, method.getExceptionTypes());
        }
        return returnValue;
    } finally {
        if (originalClassLoader != null) {
            Utility.setContextClassLoader(originalClassLoader);
        }
        getContainer().onLeavingContainer();
    }
}
Also used : LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) InvocationInfo(com.sun.ejb.InvocationInfo) EjbInvocation(com.sun.ejb.EjbInvocation) IndirectlySerializable(com.sun.enterprise.container.common.spi.util.IndirectlySerializable) EJBException(javax.ejb.EJBException)

Example 12 with InvocationInfo

use of com.sun.ejb.InvocationInfo 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 13 with InvocationInfo

use of com.sun.ejb.InvocationInfo 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 14 with InvocationInfo

use of com.sun.ejb.InvocationInfo 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)

Example 15 with InvocationInfo

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

the class ActiveTxCache method doFlush.

@Override
protected void doFlush(EjbInvocation inv) {
    if (!inv.invocationInfo.flushEnabled || inv.exception != null) {
        return;
    }
    if (!isContainerManagedPers) {
        // NEED TO INTERNATIONALIZE THIS WARNING MESSAGE
        _logger.log(Level.WARNING, "Cannot turn on flush-enabled-at-end-of-method for a bean with Bean Managed Persistence");
        return;
    }
    InvocationInfo invInfo = inv.invocationInfo;
    EntityContextImpl context = (EntityContextImpl) inv.context;
    Transaction tx = context.getTransaction();
    // could be committed or rolledback. In that case there is no point to call flush
    if (tx == null) {
        return;
    }
    // return w/o doing anything if the transaction is marked for rollback
    try {
        if (context.getRollbackOnly()) {
            return;
        }
    } catch (Throwable ex) {
        _logger.log(Level.WARNING, "Exception when calling getRollbackOnly", ex);
        return;
    }
    if (invInfo.isBusinessMethod) {
        try {
            // Store the state of all the beans that are part of this transaction
            storeAllBeansInTx(tx);
        } catch (Throwable ex) {
            inv.exception = ex;
            return;
        }
    }
    try {
        BeanStateSynchronization pmcontract = (BeanStateSynchronization) inv.ejb;
        pmcontract.ejb__flush();
    } catch (Throwable ex) {
        // check the type of the method and create the corresponding exception
        if (invInfo.startsWithCreate) {
            CreateException ejbEx = new CreateException();
            ejbEx.initCause(ex);
            inv.exception = ejbEx;
        } else if (invInfo.startsWithRemove) {
            RemoveException ejbEx = new RemoveException();
            ejbEx.initCause(ex);
            inv.exception = ejbEx;
        } else {
            EJBException ejbEx = new EJBException();
            ejbEx.initCause(ex);
            inv.exception = ejbEx;
        }
        return;
    }
}
Also used : InvocationInfo(com.sun.ejb.InvocationInfo) JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) Transaction(javax.transaction.Transaction) BeanStateSynchronization(com.sun.ejb.spi.container.BeanStateSynchronization)

Aggregations

InvocationInfo (com.sun.ejb.InvocationInfo)15 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 EjbInvocation (com.sun.ejb.EjbInvocation)4 RemoteException (java.rmi.RemoteException)4 EJBException (javax.ejb.EJBException)4 JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)3 SystemException (javax.transaction.SystemException)3 Transaction (javax.transaction.Transaction)3 ComponentContext (com.sun.ejb.ComponentContext)2 IndirectlySerializable (com.sun.enterprise.container.common.spi.util.IndirectlySerializable)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)2 Method (java.lang.reflect.Method)2 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)2 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)2 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)2 EjbRemovalInfo (org.glassfish.ejb.deployment.descriptor.EjbRemovalInfo)2 FencedLock (com.hazelcast.cp.lock.FencedLock)1 MethodLockInfo (com.sun.ejb.MethodLockInfo)1 BeanStateSynchronization (com.sun.ejb.spi.container.BeanStateSynchronization)1 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)1