Search in sources :

Example 61 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class HomeMethodRmiIIOPArgs method check.

/**
 * Enterprise Bean's ejbHome methods argument RMI IIOP test.
 * Each enterprise Bean class may define zero or more ejbHome methods.
 * The method signatures must follow these rules:
 *
 * The methods arguments must be legal types for RMI-IIOP.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        boolean oneFailed = false;
        int foundAtLeastOne = 0;
        try {
            if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", " [ {0} ] does not have a remote home interface. ", new Object[] { descriptor.getEjbClassName() }));
                return result;
            }
            ClassLoader jcl = getVerifierContext().getClassLoader();
            Class rc = Class.forName(descriptor.getHomeClassName(), false, jcl);
            Class[] homeMethodParameterTypes;
            boolean homeMethodFound = false;
            boolean isLegalRMIIIOP = false;
            for (Method remoteMethod : rc.getMethods()) {
                // we don't test the EJB methods
                if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome"))
                    continue;
                if (remoteMethod.getName().startsWith("create") || remoteMethod.getName().startsWith("find") || remoteMethod.getName().startsWith("remove"))
                    continue;
                // reset flags from last time thru loop
                Class c = Class.forName(descriptor.getEjbClassName(), false, jcl);
                // start do while loop here....
                do {
                    for (Method method : c.getDeclaredMethods()) {
                        isLegalRMIIIOP = false;
                        homeMethodFound = false;
                        String methodName = "ejbHome" + Character.toUpperCase(remoteMethod.getName().charAt(0)) + remoteMethod.getName().substring(1);
                        if (method.getName().equals(methodName)) {
                            foundAtLeastOne++;
                            homeMethodFound = true;
                            // The methods arguments types must be legal types for RMI-IIOP.
                            homeMethodParameterTypes = method.getParameterTypes();
                            if (RmiIIOPUtils.isValidRmiIIOPParameters(homeMethodParameterTypes)) {
                                // these method parameters are valid, continue
                                isLegalRMIIIOP = true;
                            }
                            // method
                            if (homeMethodFound && isLegalRMIIIOP) {
                                addGoodDetails(result, compName);
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares ejbHome<Method> method " + "[ {1} ] with valid RMI-IIOP parameter types.", new Object[] { descriptor.getEjbClassName(), method.getName() }));
                            } else if (homeMethodFound && !isLegalRMIIIOP) {
                                oneFailed = true;
                                addErrorDetails(result, compName);
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: ejbHome<Method> method [ {0} ] was found, " + "but ejbHome<Method> method has illegal parameter " + "values.   ejbHome<Method> methods arguments types " + "must be legal types for RMI-IIOP.", new Object[] { method.getName() }));
                                break;
                            }
                        }
                    }
                    if (oneFailed == true)
                        break;
                } while (((c = c.getSuperclass()) != null) && (!homeMethodFound));
            }
            if (foundAtLeastOne == 0) {
                addNaDetails(result, compName);
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", " [ {0} ] does not declare any ejbHome<Method> methods. ", new Object[] { descriptor.getEjbClassName() }));
            }
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            oneFailed = true;
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Remote interface [ {0} ] or bean class [ {1} ] does not " + "exist or is not loadable within bean [ {2} ].", new Object[] { descriptor.getRemoteClassName(), descriptor.getEjbClassName(), descriptor.getName() }));
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (foundAtLeastOne == 0) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
        return result;
    } else {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean or {2} bean, but called with {3}.", new Object[] { getClass(), "Session", "Entity", descriptor.getName() }));
        return result;
    }
}
Also used : Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 62 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class HomeMethodRmiIIOPReturn method check.

/**
 * Enterprise Bean's home methods argument RMI IIOP test.
 * Each enterprise Bean class must define zero or more home methods.
 * The method signatures must follow these rules:
 *
 * The methods return value must be legal types for RMI-IIOP.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        boolean oneFailed = false;
        int foundAtLeastOne = 0;
        try {
            if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
                addNaDetails(result, compName);
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", " [ {0} ] does not have a remote home interface. ", new Object[] { descriptor.getEjbClassName() }));
                return result;
            }
            ClassLoader jcl = getVerifierContext().getClassLoader();
            Class rc = Class.forName(descriptor.getHomeClassName(), false, jcl);
            Class methodReturnType;
            boolean homeMethodFound = false;
            boolean isLegalRMIIIOPReturn = false;
            for (Method remoteMethod : rc.getMethods()) {
                // we don't test the EJB methods
                if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome"))
                    continue;
                if (remoteMethod.getName().startsWith("create") || remoteMethod.getName().startsWith("find") || remoteMethod.getName().startsWith("remove"))
                    continue;
                // reset flags from last time thru loop
                Class c = Class.forName(descriptor.getEjbClassName(), false, jcl);
                // start do while loop here....
                do {
                    for (Method method : c.getDeclaredMethods()) {
                        // reset flags from last time thru loop
                        homeMethodFound = false;
                        isLegalRMIIIOPReturn = false;
                        String methodName = "ejbHome" + Character.toUpperCase(remoteMethod.getName().charAt(0)) + remoteMethod.getName().substring(1);
                        if (method.getName().equals(methodName)) {
                            foundAtLeastOne++;
                            homeMethodFound = true;
                            // The methods arguments types must be legal types for
                            // RMI-IIOP.  This means that their return values must
                            // be of valid types for RMI-IIOP,
                            methodReturnType = method.getReturnType();
                            if (RmiIIOPUtils.isValidRmiIIOPReturnType(methodReturnType)) {
                                // this is the right return type for method
                                isLegalRMIIIOPReturn = true;
                            }
                            // method
                            if (homeMethodFound && isLegalRMIIIOPReturn) {
                                addGoodDetails(result, compName);
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares ejbHome<METHOD> method [ {1} ] with valid RMI-IIOP return type.", new Object[] { descriptor.getEjbClassName(), method.getName() }));
                            } else if (homeMethodFound && !isLegalRMIIIOPReturn) {
                                oneFailed = true;
                                addErrorDetails(result, compName);
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: ejbHome<METHOD> method [ {0} ] was found, but ejbHome<METHOD> method has illegal return value.   ejbHome<METHOD> methods return type must be legal types for RMI-IIOP.", new Object[] { method.getName() }));
                            }
                        }
                    }
                    if (oneFailed == true)
                        break;
                } while (((c = c.getSuperclass()) != null) && (!homeMethodFound));
            }
            if (foundAtLeastOne == 0) {
                addNaDetails(result, compName);
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", " [ {0} ] does not declare any ejbHome<METHOD> methods. ", new Object[] { descriptor.getEjbClassName() }));
            }
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            oneFailed = true;
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Remote interface [ {0} ] or bean class [ {1} ] does not exist or is not loadable within bean [ {2} ].", new Object[] { descriptor.getRemoteClassName(), descriptor.getEjbClassName(), descriptor.getName() }));
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (foundAtLeastOne == 0) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
        return result;
    } else {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean or {2} bean, but called with {3}.", new Object[] { getClass(), "Session", "Entity", descriptor.getName() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Method(java.lang.reflect.Method) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 63 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class HomeMethodTest method check.

/**
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp", "Not Applicable because, EJB [ {0} ] has Local Interfaces only.", new Object[] { descriptor.getEjbClassName() }));
        return result;
    }
    if (!(descriptor instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    boolean homeMethodFound = false;
    try {
        // retrieve the remote interface methods
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class homeInterfaceClass = Class.forName(getClassName(descriptor), false, jcl);
        Vector<Method> v = new Vector<Method>();
        while (homeInterfaceClass != null && !homeInterfaceClass.getName().equals(getSuperInterface()) && !homeInterfaceClass.getName().equals("java.lang.Object")) {
            Method[] homeInterfaceMethods = homeInterfaceClass.getDeclaredMethods();
            for (int i = 0; i < homeInterfaceMethods.length; i++) {
                v.add(homeInterfaceMethods[i]);
            }
            homeInterfaceClass = homeInterfaceClass.getSuperclass();
        }
        Iterator iterator = v.iterator();
        while (iterator.hasNext()) {
            Method method = (Method) iterator.next();
            String methodName = method.getName();
            if (methodName.startsWith("create") || methodName.startsWith("find") || methodName.startsWith("remove"))
                continue;
            Method m = getMethod(javax.ejb.EJBHome.class, methodName, method.getParameterTypes());
            if (m != null) {
                // this is an EJBHome method...
                continue;
            }
            homeMethodFound = true;
            // if (!runIndividualHomeMethodTest( method,descriptor, result))
            // oneFailed = true;
            runIndividualHomeMethodTest(method, descriptor, result);
            if (result.getStatus() == Result.FAILED)
                break;
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { getClassName(descriptor), descriptor.getName() }));
    }
    if (!homeMethodFound) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable2", "Home interface [ {0} ] does not define any home methods", new Object[] { getClassName(descriptor) }));
    }
    // }
    return result;
}
Also used : Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Iterator(java.util.Iterator) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) Vector(java.util.Vector) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 64 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class RemoteHomeInterfaceRmiIIOPException method runIndividualHomeMethodTest.

/**
 * <p>
 * run an individual verifier test against a declared method of the
 * remote interface.
 * </p>
 *
 * @param descriptor the deployment descriptor for the bean
 * @param method the method to run the test on
 */
protected void runIndividualHomeMethodTest(Method method, EjbDescriptor descriptor, Result result) {
    Class[] methodExceptionTypes = method.getExceptionTypes();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // methods must also throw java.rmi.RemoteException
    if (RmiIIOPUtils.isValidRmiIIOPException(methodExceptionTypes)) {
        // this is the right exception for method, throws RemoteException
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] method properly throws java.rmi.RemoteException.", new Object[] { method.getName() }));
    } else {
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] method was found, but does not properly throw " + "java.rmi.RemoteException.", new Object[] { method.getName() }));
    }
}
Also used : ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 65 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class RemoteHomeInterfaceSuperInterface method check.

/**
 * Enterprise beans home interface test.
 *
 * The following are the requirements for the enterprise Bean's home interface
 * signature:
 *
 * The home interface is allowed to have superinterfaces. Use of interface
 * inheritance is subject to the RMI-IIOP rules for the definition of remote
 * interfaces.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp", "Not Applicable because, EJB [ {0} ] has Local Interfaces only.", new Object[] { descriptor.getEjbClassName() }));
        return result;
    }
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        boolean oneFailed = false;
        boolean ok = false;
        try {
            ClassLoader jcl = getVerifierContext().getClassLoader();
            Class c = Class.forName(descriptor.getHomeClassName(), false, jcl);
            Class remote = c;
            boolean validHomeInterface = false;
            // walk up the class tree
            do {
                Class[] interfaces = c.getInterfaces();
                if (interfaces.length == 0) {
                    ok = true;
                }
                for (Class intf : interfaces) {
                    logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { intf.getName() });
                    // requirement is met if one superinterface complies.
                    if (!ok) {
                        ok = RmiIIOPUtils.isValidRmiIIOPInterface(intf);
                    }
                    if (RmiIIOPUtils.isValidRmiIIOPInterfaceMethods(intf)) {
                        // this interface is valid, continue
                        if (intf.getName().equals("javax.ejb.EJBHome")) {
                            validHomeInterface = true;
                            break;
                        }
                    } else {
                        // before you determine if this is EJBHome interface, and break
                        // out of loop, report status of SuperInterface
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly conform to " + "rules of RMI-IIOP for superinterfaces.  All " + "enterprise beans home interfaces are allowed " + "to have superinterfaces that conform to the " + "rules of RMI-IIOP for superinterfaces .  [ {1} ] " + "is not a valid home interface.", new Object[] { intf.getName(), descriptor.getHomeClassName() }));
                    }
                }
            } while ((((c = c.getSuperclass()) != null) && (!validHomeInterface)));
            // check that superinterface check was a success
            if (!ok) {
                oneFailed = true;
                addErrorDetails(result, compName);
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly conform to rules of " + "RMI-IIOP for superinterfaces.  All enterprise beans " + "home interfaces are allowed to have superinterfaces " + "that conform to the rules of RMI-IIOP for superinterfaces . " + " [{1} ] is not a valid home interface.", new Object[] { remote.getName(), descriptor.getHomeClassName() }));
            }
            // 
            if (validHomeInterface) {
                addGoodDetails(result, compName);
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly conforms to rules of RMI-IIOP for superinterfaces.", new Object[] { descriptor.getHomeClassName() }));
            }
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not " + "loadable within bean [ {1} ]", new Object[] { descriptor.getHomeClassName(), descriptor.getName() }));
            oneFailed = true;
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else {
            result.setStatus(Result.PASSED);
        }
        return result;
    } else {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean or {2} bean, but called with {3}.", new Object[] { getClass(), "Session", "Entity", descriptor.getName() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)237 Result (com.sun.enterprise.tools.verifier.Result)212 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)87 Method (java.lang.reflect.Method)70 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)66 Iterator (java.util.Iterator)40 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)28 Set (java.util.Set)19 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)16 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)14 Field (java.lang.reflect.Field)13 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)12 Enumeration (java.util.Enumeration)11 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)11 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)7 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)6 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)6 Vector (java.util.Vector)6