Search in sources :

Example 26 with EjbInterceptor

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

the class CallbackMethodException method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    ClassLoader cl = getVerifierContext().getClassLoader();
    Set<LifecycleCallbackDescriptor> callbackDescs = new HashSet<LifecycleCallbackDescriptor>();
    for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
        callbackDescs.addAll(interceptor.getPostConstructDescriptors());
        callbackDescs.addAll(interceptor.getPreDestroyDescriptors());
        callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE));
        callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE));
    }
    if (descriptor.hasPostConstructMethod())
        callbackDescs.addAll(descriptor.getPostConstructDescriptors());
    if (descriptor.hasPreDestroyMethod())
        callbackDescs.addAll(descriptor.getPreDestroyDescriptors());
    // session descriptor has two extra interceptor methods.
    if (descriptor instanceof EjbSessionDescriptor) {
        EjbSessionDescriptor ejbSessionDescriptor = ((EjbSessionDescriptor) descriptor);
        if (ejbSessionDescriptor.hasPostActivateMethod())
            callbackDescs.addAll(ejbSessionDescriptor.getPostActivateDescriptors());
        if (ejbSessionDescriptor.hasPrePassivateMethod())
            callbackDescs.addAll(ejbSessionDescriptor.getPrePassivateDescriptors());
    }
    for (LifecycleCallbackDescriptor callbackDesc : callbackDescs) {
        try {
            Method method = callbackDesc.getLifecycleCallbackMethodObject(cl);
            Class[] excepClasses = method.getExceptionTypes();
            for (Class exception : excepClasses) {
                if (!(RuntimeException.class.isAssignableFrom(exception) || java.rmi.RemoteException.class.isAssignableFrom(exception))) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "Method [ {0} ] throws an application exception.", new Object[] { method }));
                }
            }
        }// will be caught in other tests
         catch (Exception e) {
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Callback methods."));
    }
    return result;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) HashSet(java.util.HashSet)

Example 27 with EjbInterceptor

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

the class CallbacksOnBeanClass method check.

public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    Set<EjbInterceptor> interceptors = descriptor.getInterceptorClasses();
    for (EjbInterceptor interceptor : interceptors) {
        if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE)) {
            Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE);
            reportError(callBackDescs, "ejbActivate", interceptor.getInterceptorClassName());
        }
        if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE)) {
            Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE);
            reportError(callBackDescs, "ejbPassivate", interceptor.getInterceptorClassName());
        }
        if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT)) {
            Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_CONSTRUCT);
            reportError(callBackDescs, "ejbCreate", interceptor.getInterceptorClassName());
        }
        if (interceptor.hasCallbackDescriptor(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY)) {
            Set<LifecycleCallbackDescriptor> callBackDescs = interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_DESTROY);
            reportError(callBackDescs, "ejbRemove", interceptor.getInterceptorClassName());
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid lifecycle callback method(s)"));
    }
    return result;
}
Also used : LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor)

Example 28 with EjbInterceptor

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

the class InterceptorNoArgConstructor method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    Set<EjbInterceptor> interceptors = descriptor.getInterceptorClasses();
    for (EjbInterceptor interceptor : interceptors) {
        try {
            Class interceptorClass = Class.forName(interceptor.getInterceptorClassName(), false, getVerifierContext().getClassLoader());
            try {
                interceptorClass.getConstructor(new Class[] {});
            } catch (NoSuchMethodException e) {
                result.getFaultLocation().setFaultyClass(interceptorClass);
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Interceptor class [ {0} ] does not have a " + "public constructor with no arguments.", new Object[] { interceptorClass }));
            }
        }// will be caught in other tests
         catch (ClassNotFoundException e) {
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Interceptor(s) used."));
    }
    return result;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 29 with EjbInterceptor

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

the class InterceptorMethodException method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    Set<Method> interceptorMethods = new HashSet<Method>();
    if (descriptor.hasAroundInvokeMethod()) {
    // XXX
    /*
            Method method = descriptor.getAroundInvokeMethod().getMethod(descriptor);
            interceptorMethods.add(method);
*/
    }
    List<EjbInterceptor> interceptors = descriptor.getInterceptorChain();
    for (EjbInterceptor interceptor : interceptors) {
        try {
            Class interceptorClass = Class.forName(interceptor.getInterceptorClassName(), false, getVerifierContext().getClassLoader());
        // XXX
        /*
                Method method = interceptor.getAroundInvokeMethod().getMethod(interceptorClass);
                interceptorMethods.add(method);
*/
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed1", "[ {0} ] not found.", new Object[] { interceptor.getInterceptorClassName() }));
        }
    }
    for (Method method : interceptorMethods) {
        Class[] exceptions = method.getExceptionTypes();
        for (Class excepClass : exceptions) {
            if (java.rmi.RemoteException.class.isAssignableFrom(excepClass)) {
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Method [ {0} ] throws java.rmi.RemoteException.", new Object[] { method }));
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Interceptor methods."));
    }
    return result;
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) Method(java.lang.reflect.Method) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result) HashSet(java.util.HashSet)

Example 30 with EjbInterceptor

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

the class EjbServicesImpl method registerInterceptors.

@Override
public void registerInterceptors(EjbDescriptor<?> ejbDesc, InterceptorBindings interceptorBindings) {
    com.sun.enterprise.deployment.EjbDescriptor glassfishEjbDesc = (com.sun.enterprise.deployment.EjbDescriptor) ((EjbDescriptorImpl<?>) ejbDesc).getEjbDescriptor();
    // First create master list of EjbInterceptor descriptors
    for (Interceptor<?> next : interceptorBindings.getAllInterceptors()) {
        if (logger.isLoggable(FINE)) {
            logger.log(FINE, TRYING_TO_REGISTER_INTERCEPTOR, new Object[] { next });
        }
        // Add interceptor to list all interceptors in ejb descriptor
        if (!(glassfishEjbDesc.hasInterceptorClass(next.getBeanClass().getName()))) {
            if (logger.isLoggable(FINE)) {
                logger.log(FINE, ADDING_INTERCEPTOR_FOR_EJB, new Object[] { next.getBeanClass().getName(), glassfishEjbDesc.getEjbClassName() });
            }
            EjbInterceptor ejbInt = makeEjbInterceptor(next, glassfishEjbDesc.getEjbBundleDescriptor());
            ejbInt.setInterceptorClass(next.getBeanClass());
            glassfishEjbDesc.addInterceptorClass(ejbInt);
        }
    }
    // Create ordered list of EjbInterceptor for each lifecycle interception type and append to
    // EjbDescriptor.
    // JSR 299 (CDI) interceptors are always added after any interceptors defined via
    // EJB-defined metadata, so the ordering will be correct since all the ejb interceptors
    // have already been processed.
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(AROUND_CONSTRUCT, interceptorBindings.getLifecycleInterceptors(AROUND_CONSTRUCT), glassfishEjbDesc));
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(POST_CONSTRUCT, interceptorBindings.getLifecycleInterceptors(POST_CONSTRUCT), glassfishEjbDesc));
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(PRE_DESTROY, interceptorBindings.getLifecycleInterceptors(PRE_DESTROY), glassfishEjbDesc));
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(PRE_PASSIVATE, interceptorBindings.getLifecycleInterceptors(PRE_PASSIVATE), glassfishEjbDesc));
    glassfishEjbDesc.appendToInterceptorChain(makeInterceptorChain(POST_ACTIVATE, interceptorBindings.getLifecycleInterceptors(POST_ACTIVATE), glassfishEjbDesc));
    // JSR 299-provided list is organized as per-method.  Append each method chain to EjbDescriptor.
    Class<?> ejbBeanClass = null;
    try {
        ClassLoader cl = glassfishEjbDesc.getEjbBundleDescriptor().getClassLoader();
        ejbBeanClass = cl.loadClass(glassfishEjbDesc.getEjbClassName());
    } catch (ClassNotFoundException cnfe) {
        throw new IllegalStateException("Cannot load bean class " + glassfishEjbDesc.getEjbClassName(), cnfe);
    }
    Class<?> ejbBeanSuperClass = ejbBeanClass;
    while (!ejbBeanSuperClass.equals(java.lang.Object.class)) {
        for (Method m : ejbBeanSuperClass.getDeclaredMethods()) {
            if (!methodOverridden(ejbBeanClass, m)) {
                List<EjbInterceptor> aroundInvokeChain = makeInterceptorChain(InterceptionType.AROUND_INVOKE, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_INVOKE, m), glassfishEjbDesc);
                glassfishEjbDesc.addMethodLevelChain(aroundInvokeChain, m, true);
                List<EjbInterceptor> aroundTimeoutChain = makeInterceptorChain(InterceptionType.AROUND_TIMEOUT, interceptorBindings.getMethodInterceptors(InterceptionType.AROUND_TIMEOUT, m), glassfishEjbDesc);
                glassfishEjbDesc.addMethodLevelChain(aroundTimeoutChain, m, false);
            }
        }
        ejbBeanSuperClass = ejbBeanSuperClass.getSuperclass();
    }
}
Also used : EjbInterceptor(com.sun.enterprise.deployment.EjbInterceptor) Method(java.lang.reflect.Method) EjbDescriptor(org.jboss.weld.ejb.spi.EjbDescriptor)

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