Search in sources :

Example 1 with InterceptorDescriptor

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

the class BeanCallbackInterceptor method initEjbCallbackIndices.

private void initEjbCallbackIndices() throws ClassNotFoundException, Exception {
    int size = CallbackType.values().length;
    ArrayList[] callbacks = new ArrayList[size];
    boolean scanFor2xLifecycleMethods = true;
    int numPostConstructFrameworkCallbacks = 0;
    for (CallbackType eventType : CallbackType.values()) {
        int index = eventType.ordinal();
        callbacks[index] = new ArrayList<CallbackInterceptor>();
        boolean scanForCallbacks = true;
        if (!(ejbDesc instanceof EjbSessionDescriptor)) {
            if ((eventType == CallbackType.PRE_PASSIVATE) || (eventType == CallbackType.POST_ACTIVATE)) {
                scanForCallbacks = false;
            }
        }
        if (scanForCallbacks) {
            // Make sure any framework interceptors are first
            for (InterceptorDescriptor callback : frameworkInterceptors) {
                if (callback.hasCallbackDescriptor(eventType)) {
                    Class interceptorClass = callback.getInterceptorClass();
                    ClassLoader classLoaderToUse = (interceptorClass != null) ? interceptorClass.getClassLoader() : loader;
                    List<CallbackInterceptor> inters = createCallbackInterceptors(eventType, callback, classLoaderToUse);
                    for (CallbackInterceptor inter : inters) {
                        callbacks[index].add(inter);
                        if (eventType == CallbackType.POST_CONSTRUCT) {
                            numPostConstructFrameworkCallbacks++;
                        }
                    }
                }
            }
            List<EjbInterceptor> callbackList = ejbDesc.getCallbackInterceptors(eventType);
            // to scan for the old 2.x style lifecycle methods
            if (callbackList.size() > 0) {
                scanFor2xLifecycleMethods = false;
            }
            for (EjbInterceptor callback : callbackList) {
                List<CallbackInterceptor> inters = createCallbackInterceptors(eventType, callback);
                for (CallbackInterceptor inter : inters) {
                    callbacks[index].add(inter);
                }
            }
        }
    }
    if (scanFor2xLifecycleMethods) {
        load2xLifecycleMethods(callbacks);
    }
    // The next set of lines are to handle the case where
    // the app doesn't have a @PostConstruct or it
    // doesn't implement the EntrerpriseBean interface
    // In this case we scan for ejbCreate() for MDBs and SLSBs
    boolean lookForEjbCreateMethod = container.scanForEjbCreateMethod();
    if (lookForEjbCreateMethod) {
        loadOnlyEjbCreateMethod(callbacks, numPostConstructFrameworkCallbacks);
    }
    callbackChain = new CallbackChainImpl[size];
    for (CallbackType eventType : CallbackType.values()) {
        int index = eventType.ordinal();
        CallbackInterceptor[] interceptors = (CallbackInterceptor[]) callbacks[index].toArray(new CallbackInterceptor[callbacks[index].size()]);
        callbackChain[index] = new CallbackChainImpl(interceptors);
    }
}
Also used : ArrayList(java.util.ArrayList) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) InterceptorDescriptor(com.sun.enterprise.deployment.InterceptorDescriptor) CallbackType(com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 2 with InterceptorDescriptor

use of com.sun.enterprise.deployment.InterceptorDescriptor 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 3 with InterceptorDescriptor

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

the class BeanCallbackInterceptor method getAroundInvokeChain.

public InterceptorManager.InterceptorChain getAroundInvokeChain(MethodDescriptor mDesc, Method beanMethod) {
    ArrayList<AroundInvokeInterceptor> interceptors = new ArrayList<AroundInvokeInterceptor>();
    for (InterceptorDescriptor interceptor : frameworkInterceptors) {
        Set<LifecycleCallbackDescriptor> aroundInvokeDescs = interceptor.getAroundInvokeDescriptors();
        if (aroundInvokeDescs.isEmpty()) {
            continue;
        }
        List<LifecycleCallbackDescriptor> orderedAIInterceptors = null;
        Class interceptorClass = interceptor.getInterceptorClass();
        ClassLoader classLoaderToUse = (interceptorClass != null) ? interceptorClass.getClassLoader() : loader;
        try {
            orderedAIInterceptors = interceptor.getOrderedAroundInvokeDescriptors(classLoaderToUse);
        } catch (Exception e) {
            throw new IllegalStateException("No AroundInvokeIntercetpors found " + " on class " + interceptor.getInterceptorClassName(), e);
        }
        addAroundInvokeInterceptors(interceptors, interceptor, orderedAIInterceptors, interceptor.getInterceptorClassName(), classLoaderToUse);
    }
    List<? extends InterceptorDescriptor> list = (ejbDesc != null) ? ejbDesc.getAroundInvokeInterceptors(mDesc) : interceptorInfo.getAroundInvokeInterceptors(beanMethod);
    for (InterceptorDescriptor interceptor : list) {
        String className = interceptor.getInterceptorClassName();
        Set<LifecycleCallbackDescriptor> aroundInvokeDescs = interceptor.getAroundInvokeDescriptors();
        if (aroundInvokeDescs.isEmpty()) {
            continue;
        }
        List<LifecycleCallbackDescriptor> orderedAIInterceptors = null;
        try {
            orderedAIInterceptors = interceptor.getOrderedAroundInvokeDescriptors(loader);
        } catch (Exception e) {
            throw new IllegalStateException("No AroundInvokeIntercetpors found " + " on class " + className, e);
        }
        addAroundInvokeInterceptors(interceptors, interceptor, orderedAIInterceptors, className, loader);
    }
    AroundInvokeInterceptor[] inter = interceptors.toArray(new AroundInvokeInterceptor[interceptors.size()]);
    return new AroundInvokeChainImpl(inter);
}
Also used : ArrayList(java.util.ArrayList) EJBException(javax.ejb.EJBException) InterceptorDescriptor(com.sun.enterprise.deployment.InterceptorDescriptor) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor)

Example 4 with InterceptorDescriptor

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

the class SystemInterceptorProxy method createInterceptorDesc.

public static InterceptorDescriptor createInterceptorDesc() {
    InterceptorDescriptor interceptor = new InterceptorDescriptor();
    Class interceptorClass = SystemInterceptorProxy.class;
    String interceptorName = interceptorClass.getName();
    interceptor.setInterceptorClass(interceptorClass);
    {
        LifecycleCallbackDescriptor desc = new LifecycleCallbackDescriptor();
        desc.setLifecycleCallbackClass(interceptorName);
        desc.setLifecycleCallbackMethod("create");
        interceptor.addCallbackDescriptor(CallbackType.AROUND_CONSTRUCT, desc);
    }
    {
        LifecycleCallbackDescriptor desc = new LifecycleCallbackDescriptor();
        desc.setLifecycleCallbackClass(interceptorName);
        desc.setLifecycleCallbackMethod("init");
        interceptor.addCallbackDescriptor(CallbackType.POST_CONSTRUCT, desc);
    }
    {
        LifecycleCallbackDescriptor desc = new LifecycleCallbackDescriptor();
        desc.setLifecycleCallbackClass(interceptorName);
        desc.setLifecycleCallbackMethod("destroy");
        interceptor.addCallbackDescriptor(CallbackType.PRE_DESTROY, desc);
    }
    {
        LifecycleCallbackDescriptor desc = new LifecycleCallbackDescriptor();
        desc.setLifecycleCallbackClass(interceptorName);
        desc.setLifecycleCallbackMethod("aroundInvoke");
        interceptor.addAroundInvokeDescriptor(desc);
    }
    {
        LifecycleCallbackDescriptor desc = new LifecycleCallbackDescriptor();
        desc.setLifecycleCallbackClass(interceptorName);
        desc.setLifecycleCallbackMethod("aroundTimeout");
        interceptor.addAroundTimeoutDescriptor(desc);
    }
    return interceptor;
}
Also used : InterceptorDescriptor(com.sun.enterprise.deployment.InterceptorDescriptor) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor)

Example 5 with InterceptorDescriptor

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

the class BeanCallbackInterceptor method buildInterceptorChain.

private void buildInterceptorChain(InterceptorInfo interceptorInfo) throws Exception {
    Set<Class> listOfClasses = new HashSet<Class>();
    for (String name : interceptorInfo.getInterceptorClassNames()) {
        listOfClasses.add(loader.loadClass(name));
    }
    // 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) || interceptorInfo.getHasTargetClassAroundInvoke();
    int size = CallbackType.values().length;
    callbackChain = new CallbackChainImpl[size];
    initCallbackIndices(interceptorInfo.getAroundConstructInterceptors(), CallbackType.AROUND_CONSTRUCT);
    initCallbackIndices(interceptorInfo.getPostConstructInterceptors(), CallbackType.POST_CONSTRUCT);
    initCallbackIndices(interceptorInfo.getPreDestroyInterceptors(), CallbackType.PRE_DESTROY);
}
Also used : InterceptorDescriptor(com.sun.enterprise.deployment.InterceptorDescriptor) HashSet(java.util.HashSet)

Aggregations

InterceptorDescriptor (com.sun.enterprise.deployment.InterceptorDescriptor)7 ArrayList (java.util.ArrayList)4 EjbInterceptor (com.sun.enterprise.deployment.EjbInterceptor)3 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)3 HashSet (java.util.HashSet)2 EJBException (javax.ejb.EJBException)2 CallbackType (com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType)1 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)1