Search in sources :

Example 71 with EjbSessionDescriptor

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

the class EjbReferencesElement method check.

// Logger to log messages
/**
 * The Bean Provider must declare all enterprise bean's references to the homes
 * of other enterprise beans as specified in section 14.3.2 of the Moscone spec.
 * Check for one within the same jar file, can't check outside of jar file.
 * Load/locate & check other bean's home/remote/bean, ensure they match with
 * what the linking bean says they should be; check for pair of referencing and
 * referenced beans exist.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    if ((descriptor instanceof EjbEntityDescriptor) || (descriptor instanceof EjbSessionDescriptor)) {
        // RULE: References to other beans must be declared in the form of
        // references to other beans homes as specified in section
        // 14.3.2 of the Moscone spec.
        // check for one bean within the same jar file; can't check outside of
        // jar file.  need to load/locate and check other beans remote, home, bean
        // match with the linking bean says they should be. i.e. check for pair
        // of referencing & referenced bean exist, using reflection API
        EjbReferenceDescriptor ejbReference;
        // EjbAbstractDescriptor ejbDescriptor;
        try {
            String fName = null;
            Set references = descriptor.getEjbReferenceDescriptors();
            if (references == null) {
                logger.log(Level.INFO, getClass().getName() + ".refnull");
                return result;
            }
            Iterator iterator = references.iterator();
            if (iterator.hasNext()) {
                boolean oneFailed = false;
                // boolean foundBeanClassName = false;
                // boolean foundHomeClassName = false;
                // boolean foundRemoteClassName = false;
                // File fileName = Verifier.getArchiveFile(descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri());
                // if (fileName!=null){
                // fName = fileName.getName();
                // }else{
                fName = descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri();
                // }
                while (iterator.hasNext()) {
                    ejbReference = (EjbReferenceDescriptor) iterator.next();
                    if (ejbReference.isLinked()) {
                        // reset
                        if (ejbReference.getEjbHomeInterface() != null && ejbReference.getEjbInterface() != null) {
                            oneFailed = commonToBothInterfaces(ejbReference.getEjbHomeInterface(), ejbReference.getEjbInterface(), fName);
                        }
                    } else {
                        // (e.g. external references)
                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Not Applicable: [ {0} ] must be external reference to bean outside of [ {1} ].", new Object[] { ejbReference.getName(), fName }));
                    }
                }
                if (oneFailed) {
                    result.setStatus(result.FAILED);
                } else {
                    result.setStatus(result.PASSED);
                }
            } else {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There are no ejb references to other beans within this bean [ {0} ]", new Object[] { descriptor.getName() }));
            }
            return result;
        } catch (Exception e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedRef", "Exception occurred : [ {0} ]", new Object[] { e.getMessage() }));
            return result;
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] not called \n with a Session or Entity bean.", new Object[] { getClass() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Set(java.util.Set) EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) Iterator(java.util.Iterator) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 72 with EjbSessionDescriptor

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

the class ExcludeListMethodsExist method check.

/**
 * Methods used in exclude-list element of the deployment descriptor
 * must be methods defined in the enterprise bean's remote and/or home
 * interface.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        Set<MethodDescriptor> permissionedMethods = descriptor.getExcludedMethodDescriptors();
        if (permissionedMethods != null && permissionedMethods.size() > 0) {
            for (MethodDescriptor methodDescriptor : permissionedMethods) checkMethodStyles(methodDescriptor, descriptor);
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid exclude list method(s) found."));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 73 with EjbSessionDescriptor

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

the class MethodPermissionMethodExists method check.

/**
 * Methods used in method permission element of the deployment descriptor
 * must be methods defined in the enterprise bean's remote and/or home
 * interface.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        Map<MethodPermission, Collection<MethodDescriptor>> permissionedMethods = descriptor.getMethodPermissionsFromDD();
        if (permissionedMethods != null) {
            for (MethodPermission methodPermission : permissionedMethods.keySet()) for (MethodDescriptor methodDescriptor : permissionedMethods.get(methodPermission)) checkMethodStyles(methodDescriptor, descriptor);
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid method permission method(s) found."));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Collection(java.util.Collection) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) MethodPermission(com.sun.enterprise.deployment.MethodPermission)

Example 74 with EjbSessionDescriptor

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

the class UncheckedMethodsExist method check.

/**
 * Methods used in unchecked element of the deployment descriptor
 * must be methods defined in the enterprise bean's component and/or home
 * interface.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        Set<MethodDescriptor> permissionedMethods = descriptor.getUncheckedMethodDescriptors();
        if (permissionedMethods != null && permissionedMethods.size() > 0) {
            for (MethodDescriptor methodDescriptor : permissionedMethods) checkMethodStyles(methodDescriptor, descriptor);
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid unchecked method(s) found."));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 75 with EjbSessionDescriptor

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

the class BeanMethodCalculatorImpl method getTransactionalMethodsFor.

/**
 * @return a collection of MethodDescriptor for all the methods of my
 * ejb which are elligible to have a particular transaction setting.
 */
public Collection getTransactionalMethodsFor(com.sun.enterprise.deployment.EjbDescriptor desc, ClassLoader loader) throws ClassNotFoundException, NoSuchMethodException {
    EjbDescriptor ejbDescriptor = (EjbDescriptor) desc;
    // only set if desc is a stateful session bean.  NOTE that
    // !statefulSessionBean does not imply stateless session bean
    boolean statefulSessionBean = false;
    Vector methods = new Vector();
    if (ejbDescriptor instanceof EjbSessionDescriptor) {
        statefulSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isStateful();
        boolean singletonSessionBean = ((EjbSessionDescriptor) ejbDescriptor).isSingleton();
        // Session Beans
        if (ejbDescriptor.isRemoteInterfacesSupported()) {
            Collection disallowedMethods = extractDisallowedMethodsFor(javax.ejb.EJBObject.class, sessionBeanMethodsDisallowed);
            Collection potentials = getTransactionMethodsFor(loader, ejbDescriptor.getRemoteClassName(), disallowedMethods);
            transformAndAdd(potentials, MethodDescriptor.EJB_REMOTE, methods);
        }
        if (ejbDescriptor.isRemoteBusinessInterfacesSupported()) {
            for (String intfName : ejbDescriptor.getRemoteBusinessClassNames()) {
                Class businessIntf = loader.loadClass(intfName);
                Method[] busIntfMethods = businessIntf.getMethods();
                for (Method next : busIntfMethods) {
                    methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_REMOTE));
                }
            }
        }
        if (ejbDescriptor.isLocalInterfacesSupported()) {
            Collection disallowedMethods = extractDisallowedMethodsFor(javax.ejb.EJBLocalObject.class, sessionLocalBeanMethodsDisallowed);
            Collection potentials = getTransactionMethodsFor(loader, ejbDescriptor.getLocalClassName(), disallowedMethods);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCAL, methods);
        }
        if (ejbDescriptor.isLocalBusinessInterfacesSupported()) {
            for (String intfName : ejbDescriptor.getLocalBusinessClassNames()) {
                Class businessIntf = loader.loadClass(intfName);
                Method[] busIntfMethods = businessIntf.getMethods();
                for (Method next : busIntfMethods) {
                    methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_LOCAL));
                }
            }
        }
        if (ejbDescriptor.isLocalBean()) {
            String intfName = ejbDescriptor.getEjbClassName();
            Class businessIntf = loader.loadClass(intfName);
            Method[] busIntfMethods = businessIntf.getMethods();
            for (Method next : busIntfMethods) {
                methods.add(new MethodDescriptor(next, MethodDescriptor.EJB_LOCAL));
            }
        }
        if (ejbDescriptor.hasWebServiceEndpointInterface()) {
            Class webServiceClass = loader.loadClass(ejbDescriptor.getWebServiceEndpointInterfaceName());
            Method[] webMethods = webServiceClass.getMethods();
            for (int i = 0; i < webMethods.length; i++) {
                methods.add(new MethodDescriptor(webMethods[i], MethodDescriptor.EJB_WEB_SERVICE));
            }
        }
        // SFSB and Singleton can have lifecycle callbacks transactional
        if (statefulSessionBean || singletonSessionBean) {
            Set<LifecycleCallbackDescriptor> lcds = ejbDescriptor.getLifecycleCallbackDescriptors();
            for (LifecycleCallbackDescriptor lcd : lcds) {
                try {
                    Method m = lcd.getLifecycleCallbackMethodObject(loader);
                    MethodDescriptor md = new MethodDescriptor(m, MethodDescriptor.LIFECYCLE_CALLBACK);
                    methods.add(md);
                } catch (Exception e) {
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "Lifecycle callback processing error", e);
                    }
                }
            }
        }
    } else {
        // entity beans local interfaces
        String homeIntf = ejbDescriptor.getHomeClassName();
        if (homeIntf != null) {
            Class home = loader.loadClass(homeIntf);
            Collection potentials = getTransactionMethodsFor(javax.ejb.EJBHome.class, home);
            transformAndAdd(potentials, MethodDescriptor.EJB_HOME, methods);
            String remoteIntf = ejbDescriptor.getRemoteClassName();
            Class remote = loader.loadClass(remoteIntf);
            potentials = getTransactionMethodsFor(javax.ejb.EJBObject.class, remote);
            transformAndAdd(potentials, MethodDescriptor.EJB_REMOTE, methods);
        }
        // enity beans remote interfaces
        String localHomeIntf = ejbDescriptor.getLocalHomeClassName();
        if (localHomeIntf != null) {
            Class home = loader.loadClass(localHomeIntf);
            Collection potentials = getTransactionMethodsFor(javax.ejb.EJBLocalHome.class, home);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCALHOME, methods);
            String remoteIntf = ejbDescriptor.getLocalClassName();
            Class remote = loader.loadClass(remoteIntf);
            potentials = getTransactionMethodsFor(javax.ejb.EJBLocalObject.class, remote);
            transformAndAdd(potentials, MethodDescriptor.EJB_LOCAL, methods);
        }
    }
    if (!statefulSessionBean) {
        if (ejbDescriptor.isTimedObject()) {
            if (ejbDescriptor.getEjbTimeoutMethod() != null) {
                methods.add(ejbDescriptor.getEjbTimeoutMethod());
            }
            for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
                methods.add(schd.getTimeoutMethod());
            }
        }
    }
    return methods;
}
Also used : ScheduledTimerDescriptor(org.glassfish.ejb.deployment.descriptor.ScheduledTimerDescriptor) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) LifecycleCallbackDescriptor(com.sun.enterprise.deployment.LifecycleCallbackDescriptor) Collection(java.util.Collection) Vector(java.util.Vector) 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