Search in sources :

Example 41 with EjbEntityDescriptor

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

the class InterfaceMethodTest method check.

/**
 * Run the verifier test against the local or remote interface, get all methods
 * and delegate actual testing for individual methods to the
 * runIndividualMethodTest
 *
 * @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)) {
        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;
    }
    if (getInterfaceName(descriptor) == null || "".equals(getInterfaceName(descriptor))) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable", "Not Applicable because, EJB [ {0} ] does not have {1} Interface.", new Object[] { descriptor.getEjbClassName(), getInterfaceType() }));
        return result;
    }
    try {
        Arrays.sort(EJBObjectMethods);
        // retrieve the local/remote interface methods
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class interfaceClass = Class.forName(getClassName(descriptor), false, jcl);
        if (studyInterface(descriptor, interfaceClass, result)) {
            result.setStatus(Result.PASSED);
        } else {
            result.setStatus(Result.FAILED);
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: " + getInterfaceType() + "interface [ {0} ] does not " + "exist or is not loadable within bean [ {1} ]", new Object[] { getClassName(descriptor), descriptor.getName() }));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 42 with EjbEntityDescriptor

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

the class RemoteInterfaceSuperInterface method check.

/**
 * Remote interface/business methods test.
 * Verify the following:
 *
 *   The remote 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 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;
    }
    if (descriptor.getRemoteClassName() == null || "".equals(descriptor.getRemoteClassName())) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable", "Not Applicable because, EJB [ {0} ] does not have {1} Interface.", new Object[] { descriptor.getEjbClassName(), "Remote" }));
        return result;
    }
    boolean oneFailed = false;
    try {
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class c = Class.forName(descriptor.getRemoteClassName(), false, jcl);
        Class remote = c;
        boolean validRemoteInterface = false;
        boolean ok = 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);
                }
                // check the methods now.
                if (RmiIIOPUtils.isValidRmiIIOPInterfaceMethods(intf)) {
                    // this interface is valid, continue
                    if (intf.getName().equals("javax.ejb.EJBObject")) {
                        validRemoteInterface = true;
                        break;
                    }
                } else {
                    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 remote interfaces are allowed " + "to have superinterfaces that conform to the " + "rules of RMI-IIOP for superinterfaces .  [ {1} ]" + " is not a valid remote interface.", new Object[] { intf.getName(), descriptor.getRemoteClassName() }));
                }
            }
        } while ((((c = c.getSuperclass()) != null) && (!validRemoteInterface)));
        if (!ok) {
            // check that one superinterface met rmiiiop requirement
            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 " + "remote interfaces are allowed to have superinterfaces " + "that conform to the rules of RMI-IIOP for superinterfaces. " + " [ {1} ] is not a valid remote interface.", new Object[] { remote.getName(), descriptor.getRemoteClassName() }));
        }
        if (validRemoteInterface) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly conforms to rules of RMI-IIOP for superinterfaces.", new Object[] { descriptor.getRemoteClassName() }));
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addGoodDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Remote interface [ {0} ] does not exist or is not " + "loadable within bean [ {1} ]", new Object[] { descriptor.getRemoteClassName(), descriptor.getName() }));
        oneFailed = true;
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else {
        result.setStatus(Result.PASSED);
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 43 with EjbEntityDescriptor

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

the class TransactionTypeBeanManaged method check.

/**
 * Session Bean's bean-managed transaction demarcation test.
 *
 *  The enterprise bean with bean-managed transaction demarcation must
 *  be a Session bean.
 *
 * @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();
    String transactionType = descriptor.getTransactionType();
    if (EjbSessionDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType)) {
        if (descriptor instanceof EjbSessionDescriptor) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] is valid transactionType within Session bean [ {1} ]", new Object[] { transactionType, descriptor.getName() }));
        } else if (descriptor instanceof EjbEntityDescriptor) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] is not valid transactionType within entity bean [ {1} ]", new Object[] { transactionType, descriptor.getName() }));
        }
        return result;
    } else if (EjbSessionDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Expected [ {0} ] transaction demarcation, but [ {1} ] bean has [ {2} ] transaction demarcation.", new Object[] { EjbSessionDescriptor.BEAN_TRANSACTION_TYPE, descriptor.getName(), EjbSessionDescriptor.CONTAINER_TRANSACTION_TYPE }));
        return result;
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Expected [ {0} ] transaction demarcation, but [ {1} ] bean has [ {2} ] transaction demarcation.", new Object[] { EjbSessionDescriptor.BEAN_TRANSACTION_TYPE, descriptor.getName(), transactionType }));
        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)

Example 44 with EjbEntityDescriptor

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

the class LocalInterfaceExposed method check.

/**
 * Bean interface type test.
 * The bean provider must provide either Local or Remote or Both 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 instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    EjbBundleDescriptorImpl bundle = descriptor.getEjbBundleDescriptor();
    Iterator<EjbDescriptor> iterator = (bundle.getEjbs()).iterator();
    Set<String> localInterfaces = new HashSet<String>();
    while (iterator.hasNext()) {
        EjbDescriptor entity = iterator.next();
        if (entity.getLocalClassName() != null)
            localInterfaces.add(entity.getLocalClassName());
        localInterfaces.addAll(entity.getLocalBusinessClassNames());
    }
    ClassLoader jcl = getVerifierContext().getClassLoader();
    try {
        Set<String> remoteInterfaces = new HashSet<String>();
        if (descriptor.getRemoteClassName() != null)
            remoteInterfaces.add(descriptor.getRemoteClassName());
        remoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());
        for (String intf : remoteInterfaces) {
            Class c = Class.forName(intf, false, getVerifierContext().getClassLoader());
            Method[] methods = c.getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                // check all the local interfaces in the ejb bundle
                for (Iterator itr = localInterfaces.iterator(); itr.hasNext(); ) {
                    String localIntf = (String) itr.next();
                    Class returnType = methods[i].getReturnType();
                    if ((getBaseComponentType(returnType).getName()).equals(localIntf) || (contains(methods[i].getParameterTypes(), localIntf))) {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error : Local Interface [ {0} ] has been " + "exposed in remote interface [ {1} ]", new Object[] { localIntf, c.getName() }));
                        return result;
                    }
                }
            }
        }
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Remote interface."));
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getRemoteClassName() }));
    }
    return result;
}
Also used : Method(java.lang.reflect.Method) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) 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) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl) HashSet(java.util.HashSet)

Example 45 with EjbEntityDescriptor

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

the class JarFileContainsProperEJBClasses method check.

/**
 * ejb-jar file must contain the java class file of the enterprise bean
 * implementation class, and any of the classes that it depends on.
 *
 * @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();
    try {
        VerifierTestContext context = getVerifierContext();
        Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
        // if we are dealing with a CMP2 entity bean, the class is abstract..
        if (descriptor instanceof EjbEntityDescriptor) {
            String persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType();
            if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
                if (EjbCMPEntityDescriptor.CMP_1_1 != ((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "Bean class [ {0} ] exists and it's supporting classes exist.", new Object[] { descriptor.getEjbClassName() }));
                    return result;
                }
            }
        }
        try {
            c.newInstance();
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "Bean class [ {0} ] exists and it's supporting classes exist.", new Object[] { descriptor.getEjbClassName() }));
        } catch (InstantiationException e) {
            Verifier.debug(e);
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Could not instantiate [ {0} ] within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), descriptor.getName() }));
        } catch (IllegalAccessException e) {
            Verifier.debug(e);
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: Illegal Access while trying to instantiate [ {0} ] within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), descriptor.getName() }));
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Can't find class [ {0} ] within bean [ {1} ]", new Object[] { descriptor.getEjbClassName(), descriptor.getName() }));
    } catch (Throwable t) {
        Verifier.debug(t);
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "Not Applicable: [ {0} ] class encountered [ {1} ]. Cannot create instance of class [ {2} ] becuase [ {3} ] is not accessible within [ {4} ].", new Object[] { (descriptor).getEjbClassName(), t.toString(), descriptor.getEjbClassName(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri() }));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)100 Result (com.sun.enterprise.tools.verifier.Result)88 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)87 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)49 Method (java.lang.reflect.Method)42 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)18 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)12 Iterator (java.util.Iterator)12 Field (java.lang.reflect.Field)10 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 Set (java.util.Set)8 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)7 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)6 Vector (java.util.Vector)5 Descriptor (org.glassfish.deployment.common.Descriptor)3 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)3 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)3 IASEjbExtraDescriptors (org.glassfish.ejb.deployment.descriptor.runtime.IASEjbExtraDescriptors)3 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)2