Search in sources :

Example 6 with EjbInterceptor

use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.

the class BeanCallbackInterceptor method buildEjbInterceptorChain.

private void buildEjbInterceptorChain() throws Exception {
    Set<Class> listOfClasses = new HashSet<Class>();
    for (EjbInterceptor ejbi : ejbDesc.getInterceptorClasses()) {
        // PAYARA-826 if the interceptor class is available use it
        Class interceptorClass = ejbi.getInterceptorClass();
        if (interceptorClass == null) {
            String className = ejbi.getInterceptorClassName();
            interceptorClass = loader.loadClass(className);
        }
        listOfClasses.add(interceptorClass);
    }
    // class before attempting to load it via application class loader
    for (InterceptorDescriptor frameworkInterceptor : frameworkInterceptors) {
        Class clazz = frameworkInterceptor.getInterceptorClass();
        if (clazz == null) {
            clazz = loader.loadClass(frameworkInterceptor.getInterceptorClassName());
        }
        listOfClasses.add(clazz);
    }
    initInterceptorClasses(listOfClasses);
    interceptorsExists = (listOfClasses.size() > 0) || ejbDesc.hasAroundInvokeMethod() || ejbDesc.hasAroundTimeoutMethod();
    initEjbCallbackIndices();
}
Also used : InterceptorDescriptor(com.sun.enterprise.deployment.InterceptorDescriptor) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) HashSet(java.util.HashSet)

Example 7 with EjbInterceptor

use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.

the class EjbDescriptor method getConstructorInterceptors.

/**
 * Return bean constructor for AroundConstruct interceptors
 */
private List<EjbInterceptor> getConstructorInterceptors(ClassLoader classLoader) {
    List<EjbInterceptor> callbackInterceptors = null;
    String shortClassName = ejbClassName;
    int i = ejbClassName.lastIndexOf('.');
    if (i > -1) {
        shortClassName = ejbClassName.substring(i + 1);
    }
    JCDIService jcdiService = (sl == null) ? null : sl.getService(JCDIService.class);
    if (jcdiService != null && jcdiService.isJCDIEnabled(getEjbBundleDescriptor())) {
        try {
            Class beanClass = classLoader.loadClass(getEjbClassName());
            Constructor<?>[] ctors = beanClass.getDeclaredConstructors();
            String[] parameterClassNames = null;
            MethodDescriptor dummy = new MethodDescriptor();
            for (Constructor<?> ctor : ctors) {
                if (ctor.getAnnotation(Inject.class) != null) {
                    // @Inject constructor
                    Class[] ctorParamTypes = ctor.getParameterTypes();
                    parameterClassNames = dummy.getParameterClassNamesFor(null, ctorParamTypes);
                    callbackInterceptors = getClassOrMethodInterceptors(new MethodDescriptor(shortClassName, null, parameterClassNames, MethodDescriptor.EJB_BEAN));
                    break;
                }
            }
        } catch (Throwable t) {
            _logger.log(Level.SEVERE, "enterprise.deployment.backend.methodClassLoadFailure", new Object[] { this.getEjbClassName() });
            throw new RuntimeException(t);
        }
    }
    if (callbackInterceptors == null) {
        // non-CDI or no @Inject constructor - use no-arg constructor
        callbackInterceptors = getClassOrMethodInterceptors(new MethodDescriptor(shortClassName, null, new String[0], MethodDescriptor.EJB_BEAN));
    }
    return callbackInterceptors;
}
Also used : Inject(javax.inject.Inject) JCDIService(com.sun.enterprise.container.common.spi.JCDIService) Constructor(java.lang.reflect.Constructor) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 8 with EjbInterceptor

use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.

the class EjbDescriptor method addMethodLevelChain.

@Override
public void addMethodLevelChain(List<EjbInterceptor> chain, Method m, boolean aroundInvoke) {
    if (chain.size() == 0) {
        return;
    }
    MethodDescriptor methodDesc = new MethodDescriptor(m);
    List<EjbInterceptor> existingChain = null;
    for (MethodDescriptor next : methodInterceptorsMap.keySet()) {
        if (next.implies(methodDesc)) {
            existingChain = methodInterceptorsMap.get(methodDesc);
            break;
        }
    }
    if (existingChain != null) {
        existingChain.addAll(chain);
    } else {
        List<EjbInterceptor> newChain = new LinkedList<EjbInterceptor>();
        for (EjbInterceptor interceptor : interceptorChain) {
            boolean include = aroundInvoke ? interceptor.hasAroundInvokeDescriptor() : interceptor.hasAroundTimeoutDescriptor();
            if (include) {
                newChain.add(interceptor);
            }
        }
        newChain.addAll(chain);
        methodInterceptorsMap.put(methodDesc, newChain);
    }
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) LinkedList(java.util.LinkedList)

Example 9 with EjbInterceptor

use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.

the class EjbDescriptor method getAroundTimeoutInterceptors.

/**
 * Return the ordered list of interceptor info for AroundTimeout behavior
 * of a particular business method.  This list *does* include the info
 * on any bean class interceptor.  If present, this would always be the
 * last element in the list because of the precedence defined by the spec.
 * @param businessMethod
 * @return
 */
public List<EjbInterceptor> getAroundTimeoutInterceptors(MethodDescriptor businessMethod) {
    LinkedList<EjbInterceptor> aroundTimeoutInterceptors = new LinkedList<EjbInterceptor>();
    List<EjbInterceptor> classOrMethodInterceptors = getClassOrMethodInterceptors(businessMethod);
    for (EjbInterceptor next : classOrMethodInterceptors) {
        if (next.getAroundTimeoutDescriptors().size() > 0) {
            aroundTimeoutInterceptors.add(next);
        }
    }
    if (hasAroundTimeoutMethod()) {
        EjbInterceptor interceptorInfo = new EjbInterceptor();
        interceptorInfo.setFromBeanClass(true);
        interceptorInfo.addAroundTimeoutDescriptors(getAroundTimeoutDescriptors());
        interceptorInfo.setInterceptorClassName(getEjbImplClassName());
        aroundTimeoutInterceptors.add(interceptorInfo);
    }
    return aroundTimeoutInterceptors;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) LinkedList(java.util.LinkedList)

Example 10 with EjbInterceptor

use of com.sun.enterprise.deployment.EjbInterceptor in project Payara by payara.

the class EjbDescriptor method applyInterceptors.

/**
 * Derive all interceptors that are applicable to this bean.
 * @param bindingTranslator
 */
public void applyInterceptors(InterceptorBindingTranslator bindingTranslator) {
    // Apply this ejb to the ordered set of all interceptor bindings
    // for this ejb-jar.  The results will contain all interceptor
    // information that applies to the ejb.  There is no notion of
    // default interceptors within the results.  Default interceptors
    // are used during the translation process but once we derive
    // the per-ejb interceptor information there is only a notion of
    // class-level ordering and method-level ordering.  Any applicable
    // default interceptors will have been applied to the class-level.
    TranslationResults results = bindingTranslator.apply(getName());
    allInterceptorClasses.clear();
    allInterceptorClasses.addAll(results.allInterceptorClasses);
    interceptorChain.clear();
    interceptorChain.addAll(results.classInterceptorChain);
    methodInterceptorsMap.clear();
    methodInterceptorsMap.putAll(results.methodInterceptorsMap);
    for (EjbInterceptor interceptor : allInterceptorClasses) {
        for (Object ejbRefObj : interceptor.getEjbReferenceDescriptors()) {
            addEjbReferenceDescriptor((EjbReference) ejbRefObj);
        }
        for (Object msgDestRefObj : interceptor.getMessageDestinationReferenceDescriptors()) {
            addMessageDestinationReferenceDescriptor((MessageDestinationReferenceDescriptor) msgDestRefObj);
        }
        for (Object envPropObj : interceptor.getEnvironmentProperties()) {
            addOrMergeEnvironmentProperty((EnvironmentProperty) envPropObj);
        }
        for (Object servRefObj : interceptor.getServiceReferenceDescriptors()) {
            addServiceReferenceDescriptor((ServiceReferenceDescriptor) servRefObj);
        }
        for (Object resRefObj : interceptor.getResourceReferenceDescriptors()) {
            addResourceReferenceDescriptor((ResourceReferenceDescriptor) resRefObj);
        }
        for (Object resourceEnvRefObj : interceptor.getResourceEnvReferenceDescriptors()) {
            addResourceEnvReferenceDescriptor((ResourceEnvReferenceDescriptor) resourceEnvRefObj);
        }
        for (EntityManagerFactoryReferenceDescriptor entMgrFacRef : interceptor.getEntityManagerFactoryReferenceDescriptors()) {
            addEntityManagerFactoryReferenceDescriptor(entMgrFacRef);
        }
        for (EntityManagerReferenceDescriptor entMgrRef : interceptor.getEntityManagerReferenceDescriptors()) {
            addEntityManagerReferenceDescriptor(entMgrRef);
        }
    }
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) TranslationResults(org.glassfish.ejb.deployment.util.InterceptorBindingTranslator.TranslationResults) EntityManagerFactoryReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor) EntityManagerReferenceDescriptor(com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)

Aggregations

EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)34 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)9 LinkedList (java.util.LinkedList)6 Method (java.lang.reflect.Method)5 HashSet (java.util.HashSet)5 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)3 InterceptorDescriptor (com.sun.enterprise.deployment.InterceptorDescriptor)3 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)3 Result (com.sun.enterprise.tools.verifier.Result)3 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)3 ArrayList (java.util.ArrayList)3 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)3 Descriptor (org.glassfish.deployment.common.Descriptor)2 Node (org.w3c.dom.Node)2 JCDIService (com.sun.enterprise.container.common.spi.JCDIService)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)1 EntityManagerFactoryReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor)1 EntityManagerReferenceDescriptor (com.sun.enterprise.deployment.EntityManagerReferenceDescriptor)1