Search in sources :

Example 16 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class InterceptorMethodTest method check.

public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    testInterceptorMethods(descriptor.getAroundInvokeDescriptors(), "AroundInvoke", true);
    testInterceptorMethods(descriptor.getPreDestroyDescriptors(), "PreDestroy", true);
    testInterceptorMethods(descriptor.getPostConstructDescriptors(), "PostConstruct", true);
    if (descriptor instanceof EjbSessionDescriptor) {
        EjbSessionDescriptor sessionDescriptor = (EjbSessionDescriptor) descriptor;
        testInterceptorMethods(sessionDescriptor.getPrePassivateDescriptors(), "PrePassivate", true);
        testInterceptorMethods(sessionDescriptor.getPostActivateDescriptors(), "PostActivate", true);
    }
    descriptor.getInterceptorClasses();
    for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
        testInterceptorMethods(interceptor.getAroundInvokeDescriptors(), "AroundInvoke", false);
        testInterceptorMethods(interceptor.getPreDestroyDescriptors(), "PreDestroy", false);
        testInterceptorMethods(interceptor.getPostConstructDescriptors(), "PostConstruct", false);
        testInterceptorMethods(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE), "PrePassivate", false);
        testInterceptorMethods(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE), "PostActivate", false);
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.ejb30.InterceptorMethodTest.passed", "Valid Interceptor methods."));
    }
    return result;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 17 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class Generator method getTxAttribute.

protected String getTxAttribute(EjbDescriptor dd, Method method) {
    // com.sun.ejb.Container.
    if (dd instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) dd).getTransactionType().equals("Bean"))
        return "TX_BEAN_MANAGED";
    String txAttr = null;
    MethodDescriptor mdesc = new MethodDescriptor(method, ejbClassSymbol);
    ContainerTransaction ct = dd.getContainerTransactionFor(mdesc);
    if (ct != null) {
        String attr = ct.getTransactionAttribute();
        if (attr.equals(ContainerTransaction.NOT_SUPPORTED))
            txAttr = "TX_NOT_SUPPORTED";
        else if (attr.equals(ContainerTransaction.SUPPORTS))
            txAttr = "TX_SUPPORTS";
        else if (attr.equals(ContainerTransaction.REQUIRED))
            txAttr = "TX_REQUIRED";
        else if (attr.equals(ContainerTransaction.REQUIRES_NEW))
            txAttr = "TX_REQUIRES_NEW";
        else if (attr.equals(ContainerTransaction.MANDATORY))
            txAttr = "TX_MANDATORY";
        else if (attr.equals(ContainerTransaction.NEVER))
            txAttr = "TX_NEVER";
    }
    if (txAttr == null) {
        throw new RuntimeException("Transaction Attribute not found for method " + method);
    }
    return txAttr;
}
Also used : ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 18 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class AbstractSingletonContainer method createSingletonEJB.

private SingletonContextImpl createSingletonEJB() throws CreateException {
    EjbInvocation ejbInv = null;
    SingletonContextImpl context;
    Object ejb;
    // Track whether initialization got as far as preInvokeTx.
    // Needed for adequate error handling in the face of an initialization
    // exception.
    boolean initGotToPreInvokeTx = false;
    boolean doPostConstruct = true;
    try {
        String sessionKey = clusteredLookup.getClusteredSessionKey();
        EjbSessionDescriptor sessDesc = (EjbSessionDescriptor) ejbDescriptor;
        if (clusteredLookup.isClusteredEnabled()) {
            IMap<String, Object> singletonMap = clusteredLookup.getClusteredSingletonMap();
            if (!singletonMap.containsKey(sessionKey)) {
                context = (SingletonContextImpl) createEjbInstanceAndContext();
                ejb = singletonMap.putIfAbsent(sessionKey, context.getEJB());
                if ((ejb != null) && (ejb != context.getEJB()) && sessDesc.dontCallPostConstructOnAttach()) {
                    doPostConstruct = false;
                }
            } else {
                context = (SingletonContextImpl) _constructEJBContextImpl(singletonMap.get(sessionKey));
                ejb = context.getEJB();
                ejbInv = createInvocationAndPreInvoke(ejbInv, ejb, context);
                createEmptyContextAndInterceptors(context);
                if (isJCDIEnabled()) {
                    _createJCDIInjectionContext(context, ejb, context.getJCDIInjectionContext());
                }
                if (sessDesc.dontCallPostConstructOnAttach()) {
                    doPostConstruct = false;
                }
            }
            clusteredLookup.getClusteredUsageCount().incrementAndGet();
        } else {
            if (sessDesc.isClustered() && !clusteredLookup.getHazelcastCore().isEnabled()) {
                _logger.log(Level.WARNING, "Clustered Singleton {0} not available - Hazelcast is Disabled", sessionKey);
            }
            // a dummy invocation will be created by the BaseContainer to support
            // possible AroundConstruct interceptors
            context = (SingletonContextImpl) createEjbInstanceAndContext();
            ejb = context.getEJB();
        }
        ejbInv = createInvocationAndPreInvoke(ejbInv, ejb, context);
        // Perform injection right after where setSessionContext
        // would be called.  This is important since injection methods
        // have the same "operations allowed" permissions as
        // setSessionContext.
        injectEjbInstance(context);
        if (isRemote) {
            if (hasRemoteBusinessView) {
                context.setEJBRemoteBusinessObjectImpl(theRemoteBusinessObjectImpl);
            }
        }
        if (isLocal) {
            if (hasLocalBusinessView) {
                context.setEJBLocalBusinessObjectImpl(theEJBLocalBusinessObjectImpl);
            }
            if (hasOptionalLocalBusinessView) {
                context.setOptionalEJBLocalBusinessObjectImpl(theOptionalEJBLocalBusinessObjectImpl);
            }
        }
        // Call preInvokeTx directly.  InvocationInfo containing tx
        // attribute must be set prior to calling preInvoke
        ejbInv.transactionAttribute = postConstructInvInfo.txAttr;
        ejbInv.invocationInfo = postConstructInvInfo;
        initGotToPreInvokeTx = true;
        preInvokeTx(ejbInv);
        context.setInstanceKey(singletonInstanceKey);
        if (doPostConstruct) {
            intercept(CallbackType.POST_CONSTRUCT, context);
        }
    } catch (Throwable th) {
        if (ejbInv != null) {
            ejbInv.exception = th;
        }
        singletonInitializationFailed = true;
        CreateException creEx = new CreateException("Initialization failed for Singleton " + ejbDescriptor.getName());
        creEx.initCause(th);
        throw creEx;
    } finally {
        initializationInProgress = false;
        if (ejbInv != null) {
            try {
                invocationManager.postInvoke(ejbInv);
                if (initGotToPreInvokeTx) {
                    postInvokeTx(ejbInv);
                }
            } catch (Exception pie) {
                if (ejbInv.exception != null) {
                    _logger.log(Level.WARNING, "Exception during Singleton startup postInvoke ", pie);
                } else {
                    ejbInv.exception = pie;
                    singletonInitializationFailed = true;
                    CreateException creEx = new CreateException("Initialization failed for Singleton " + ejbDescriptor.getName());
                    creEx.initCause(pie);
                    throw creEx;
                }
            }
        }
    }
    // Set the state to POOLED after ejbCreate so that
    // EJBContext methods not allowed will throw exceptions
    context.setState(EJBContextImpl.BeanState.POOLED);
    context.touch();
    return context;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) CreateException(javax.ejb.CreateException) NoSuchEJBException(javax.ejb.NoSuchEJBException) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 19 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class SafeProperties method setConcurrencyInvInfo.

private void setConcurrencyInvInfo(Method invInfoMethod, String methodIntf, InvocationInfo invInfo) {
    MethodLockInfo lockInfo = null;
    // Set READ/WRITE lock info.  Only applies to singleton beans.
    if (isSingleton) {
        EjbSessionDescriptor singletonDesc = (EjbSessionDescriptor) ejbDescriptor;
        List<MethodDescriptor> readLockMethods = singletonDesc.getReadLockMethods();
        List<MethodDescriptor> writeLockMethods = singletonDesc.getWriteLockMethods();
        DistributedLockType distLockType = singletonDesc.isClustered() ? singletonDesc.getClusteredLockType() : DistributedLockType.LOCK_NONE;
        for (MethodDescriptor readLockMethodDesc : readLockMethods) {
            Method readLockMethod = readLockMethodDesc.getMethod(singletonDesc);
            if (implMethodMatchesInvInfoMethod(invInfoMethod, methodIntf, readLockMethod)) {
                lockInfo = new MethodLockInfo();
                switch(distLockType) {
                    case INHERIT:
                        {
                            _logger.log(Level.WARNING, "Distributed Read Lock for Method {0} Upgraded to Read/Write", readLockMethod.getName());
                            lockInfo.setLockType(LockType.WRITE, true);
                            break;
                        }
                    case LOCK_NONE:
                        {
                            lockInfo.setLockType(LockType.READ, false);
                        }
                }
                break;
            }
        }
        if (lockInfo == null) {
            for (MethodDescriptor writeLockMethodDesc : writeLockMethods) {
                Method writeLockMethod = writeLockMethodDesc.getMethod(singletonDesc);
                if (implMethodMatchesInvInfoMethod(invInfoMethod, methodIntf, writeLockMethod)) {
                    lockInfo = new MethodLockInfo();
                    lockInfo.setLockType(LockType.WRITE, distLockType != DistributedLockType.LOCK_NONE);
                    break;
                }
            }
        }
    }
    // Set AccessTimeout info
    if (isSingleton || isStatefulSession) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDescriptor;
        List<EjbSessionDescriptor.AccessTimeoutHolder> accessTimeoutInfo = sessionDesc.getAccessTimeoutInfo();
        for (EjbSessionDescriptor.AccessTimeoutHolder accessTimeoutHolder : accessTimeoutInfo) {
            MethodDescriptor accessTimeoutMethodDesc = accessTimeoutHolder.method;
            Method accessTimeoutMethod = accessTimeoutMethodDesc.getMethod(sessionDesc);
            if (implMethodMatchesInvInfoMethod(invInfoMethod, methodIntf, accessTimeoutMethod)) {
                if (lockInfo == null) {
                    lockInfo = new MethodLockInfo();
                }
                lockInfo.setTimeout(accessTimeoutHolder.value, accessTimeoutHolder.unit);
                break;
            }
        }
    }
    if (lockInfo != null) {
        invInfo.methodLockInfo = lockInfo;
    }
}
Also used : DistributedLockType(fish.payara.cluster.DistributedLockType) Method(java.lang.reflect.Method) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 20 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.

the class SafeProperties method addInvocationInfo.

private InvocationInfo addInvocationInfo(Method method, String methodIntf, Class originalIntf, boolean isEjbTimeout, boolean optionalLocalBusView) throws EJBException {
    MethodDescriptor md = new MethodDescriptor(method, methodIntf);
    boolean flushEnabled = findFlushEnabledAttr(md);
    int txAttr = containerTransactionManager.findTxAttr(md);
    InvocationInfo info = createInvocationInfo(method, txAttr, flushEnabled, methodIntf, originalIntf);
    boolean isHomeIntf = (methodIntf.equals(MethodDescriptor.EJB_HOME) || methodIntf.equals(MethodDescriptor.EJB_LOCALHOME));
    if (!isHomeIntf) {
        Method beanMethod = null;
        if (!isEjbTimeout) {
            try {
                beanMethod = getEJBClass().getMethod(method.getName(), method.getParameterTypes());
            } catch (NoSuchMethodException nsmEx) {
            // TODO
            }
        } else {
            // For a timeout it is the method
            beanMethod = method;
        }
        if (beanMethod != null) {
            // Can't set AroundInvoke/AroundTimeout chains here, but set up some
            // state on info object so it can be done right after InterceptorManager
            // is initialized.
            info.aroundMethod = beanMethod;
            info.isEjbTimeout = isEjbTimeout;
        }
        // Asynchronous method initialization
        if (isEligibleForAsync(originalIntf, methodIntf)) {
            Method targetMethod = optionalLocalBusView ? beanMethod : method;
            boolean isAsync = ((EjbSessionDescriptor) ejbDescriptor).isAsynchronousMethod(targetMethod);
            if (isAsync) {
                // Check return type
                if (optionalLocalBusView) {
                    boolean beanMethodReturnTypeVoid = beanMethod.getReturnType().equals(Void.TYPE);
                    boolean beanMethodReturnTypeFuture = beanMethod.getReturnType().equals(Future.class);
                    if (!beanMethodReturnTypeVoid && !beanMethodReturnTypeFuture) {
                        throw new RuntimeException("Invalid no-interface view asynchronous method '" + beanMethod + "' for bean " + ejbDescriptor.getName() + ". Async method exposed through no-interface view must " + " have return type void or java.lang.concurrent.Future<V>");
                    }
                } else {
                    // Use actual interface method instead of method from generated interface
                    Method intfMethod = null;
                    try {
                        intfMethod = originalIntf.getMethod(method.getName(), method.getParameterTypes());
                    } catch (NoSuchMethodException nsmEx) {
                        throw new RuntimeException("No matching async intf method for method '" + beanMethod + "' on bean " + ejbDescriptor.getName());
                    }
                    if (beanMethod == null) {
                        throw new RuntimeException("No matching bean class method for async method '" + intfMethod + "' on bean " + ejbDescriptor.getName());
                    }
                    boolean beanMethodReturnTypeVoid = beanMethod.getReturnType().equals(Void.TYPE);
                    boolean beanMethodReturnTypeFuture = beanMethod.getReturnType().equals(Future.class);
                    boolean intfMethodReturnTypeVoid = intfMethod.getReturnType().equals(Void.TYPE);
                    boolean intfMethodReturnTypeFuture = intfMethod.getReturnType().equals(Future.class);
                    boolean bothVoid = intfMethodReturnTypeVoid && beanMethodReturnTypeVoid;
                    boolean bothFuture = intfMethodReturnTypeFuture && beanMethodReturnTypeFuture;
                    boolean valid = false;
                    if (bothVoid) {
                        valid = true;
                    } else if (bothFuture) {
                        valid = true;
                    }
                    if (!valid) {
                        throw new RuntimeException("Invalid asynchronous bean class / interface " + "method signatures for bean " + ejbDescriptor.getName() + ". beanMethod = '" + beanMethod + "' , interface method = '" + intfMethod + "'");
                    }
                }
                info.setIsAsynchronous(true);
            }
        }
    }
    if (methodIntf.equals(MethodDescriptor.EJB_WEB_SERVICE)) {
        webServiceInvocationInfoMap.put(method, info);
    } else {
        invocationInfoMap.put(method, info);
    }
    return info;
}
Also used : Method(java.lang.reflect.Method) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Aggregations

EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)78 Result (com.sun.enterprise.tools.verifier.Result)28 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)28 Method (java.lang.reflect.Method)25 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)23 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)18 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)7 Iterator (java.util.Iterator)6 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)6 Set (java.util.Set)5 EJBException (javax.ejb.EJBException)4 Container (com.sun.ejb.Container)3 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)3 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)3 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)3 NoSuchEJBException (javax.ejb.NoSuchEJBException)3