Search in sources :

Example 11 with EjbSessionDescriptor

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

the class HomeInterfaceClassExist method check.

/**
 * Home Interface test.
 * Verify that the bean home interface class exist and is loadable.
 *
 * @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)) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        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 (getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        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;
    }
    // verify that the home interface class exist and is loadable
    try {
        VerifierTestContext context = getVerifierContext();
        ClassLoader jcl = context.getClassLoader();
        Class c = Class.forName(getClassName(descriptor), false, jcl);
        if (c != null) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "Home interface [ {0} ] exist and is loadable.", new Object[] { getClassName(descriptor) }));
        } else {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Home interface [ {0} ] does not exist or is not loadable.", new Object[] { getClassName(descriptor) }));
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Home interface [ {0} ] does not exist or is not loadable.", new Object[] { getClassName(descriptor) }));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 12 with EjbSessionDescriptor

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

the class HomeInterfacePublic method check.

/**
 * All enterprise beans home interface's must be declared as public.
 *
 * @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))) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        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)) {
        try {
            VerifierTestContext context = getVerifierContext();
            ClassLoader jcl = context.getClassLoader();
            Class c = Class.forName(getClassName(descriptor), false, jcl);
            // remote interface must be defined as public
            boolean isPublic = false;
            int modifiers = c.getModifiers();
            if (Modifier.isPublic(modifiers)) {
                isPublic = true;
            }
            // it extends the proper EJBHome, but is it's modifier public
            if (!isPublic) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] is not defined as public.  All enterprise beans home interfaces must be defined as public.  [ {1} ] is not a valid home interface.", new Object[] { getClassName(descriptor), getClassName(descriptor) }));
            } else {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares the home interface as public.", new Object[] { getClassName(descriptor) }));
            }
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { getClassName(descriptor) }));
        }
        return result;
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        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) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 13 with EjbSessionDescriptor

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

the class ASEjbIsReadOnlyBean method testROBSpecific.

public void testROBSpecific(EjbDescriptor descriptor, IASEjbExtraDescriptors iasEjbExtraDesc, Result result) {
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    try {
        // Read only Beans can only be Entity Beans
        if (descriptor instanceof EjbEntityDescriptor) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB ejb] : Read Only Beans can only be Entity Beans"));
        } else if (descriptor instanceof EjbSessionDescriptor) {
            oneFailed = true;
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-EJB ejb] : Read Only Beans cannot be Session Beans. They can only be Entity Beans"));
            return;
        } else if (descriptor instanceof EjbMessageBeanDescriptor) {
            oneFailed = true;
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB ejb] : Read Only Beans cannot be Message Driven Beans. They can only be Entity Beans"));
            return;
        }
        // Only Container Managed Transactions are Allowed
        String txnType = descriptor.getTransactionType();
        if (txnType.equals(descriptor.CONTAINER_TRANSACTION_TYPE)) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-EJB ejb] : Read Only Beans can only have Container Managed Transactions"));
        } else {
            oneFailed = true;
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-EJB ejb] : Read Only Beans cannot have Bean Managed Transactions"));
        }
        // Encourage not to have create/remove methods in Home Interface
        String homeName = descriptor.getHomeClassName();
        Class homeClass = null;
        boolean foundCreateMethod = false;
        boolean foundRemoveMethod = false;
        homeClass = getVerifierContext().getClassLoader().loadClass(homeName);
        Method[] methods = homeClass.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().startsWith("create")) {
                foundCreateMethod = true;
                break;
            }
        }
        for (int i = 0; i < methods.length; i++) {
            if (methods[i].getName().startsWith("remove")) {
                foundRemoveMethod = true;
                break;
            }
        }
        if (foundCreateMethod) {
            oneWarning = true;
            result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb] : Home interface [ {0} ] should have zero create Methods for Read Only Beans.", new Object[] { homeName }));
        } else {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed3", "PASSED [AS-EJB ejb] : Read Only Bean has zero create Methods"));
        }
        if (foundRemoveMethod) {
            oneWarning = true;
            result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning1", "WARNING [AS-EJB ejb] : Home interface [ {0} ] should have zero remove Methods for Read Only Beans.", new Object[] { homeName }));
        } else {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed4", "PASSED [AS-EJB ejb] : Read Only Bean has zero remove Methods"));
        }
        // Refresh Period Test
        int refreshPeriod = iasEjbExtraDesc.getRefreshPeriodInSeconds();
        if (refreshPeriod != -1) {
            long refValue = new Integer(refreshPeriod).longValue();
            if (refValue < 0 || refValue > Long.MAX_VALUE) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed4", "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and {0}.", new Object[] { new Long(Long.MAX_VALUE) }));
            } else {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed5", "PASSED [AS-EJB ejb] : refresh-period-in-seconds is {0}", new Object[] { new Long(refValue) }));
            }
        } else {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "NOT APPLICABLE [AS-EJB ejb] refresh-period-in-seconds Element not defined"));
        }
        if (oneFailed)
            result.setStatus(Result.FAILED);
    } catch (ClassNotFoundException cnfe) {
        oneFailed = true;
    } catch (RuntimeException ex) {
        oneFailed = true;
    }
    if (oneFailed) {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create a descriptor object"));
    }
}
Also used : Method(java.lang.reflect.Method) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbMessageBeanDescriptor(com.sun.enterprise.deployment.EjbMessageBeanDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 14 with EjbSessionDescriptor

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

the class ASEjbBeanCache method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    String beanCache = null;
    try {
        beanCache = getXPathValue("/sun-ejb-jar/enterprise-beans/ejb[ejb-name=\"" + descriptor.getName() + "\"]/bean-cache");
        if (beanCache != null) {
            if (descriptor instanceof EjbEntityDescriptor || (descriptor instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) descriptor).getSessionType().equals(EjbSessionDescriptor.STATEFUL))) {
                addGoodDetails(result, compName);
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB ejb] : bean-cache Element parsed"));
            } else {
                addWarningDetails(result, compName);
                result.warning(smh.getLocalString(getClass().getName() + ".warning1", "WARNING [AS-EJB ejb] : bean-cache should be defined only for Stateful Session and Entity Beans"));
            }
        } else {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB ejb] : bean-cache element not defined"));
        }
    } catch (Exception ex) {
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not get a beanCache object"));
    }
    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 15 with EjbSessionDescriptor

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

the class ASEjbBeanPool method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    IASEjbExtraDescriptors ejbJar = descriptor.getIASEjbExtraDescriptors();
    if (ejbJar != null) {
        try {
            beanPool = ejbJar.getBeanPool();
            if (beanPool != null) {
                if (descriptor instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) descriptor).getSessionType().equals(EjbSessionDescriptor.STATEFUL)) {
                    result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb] : bean-pool should be defined for Stateless Session Beans, Entity Beans or Message Driven Beans"));
                } else if (descriptor instanceof EjbMessageBeanDescriptor || (descriptor instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) descriptor).getSessionType().equals(EjbSessionDescriptor.STATELESS)) || descriptor instanceof EjbEntityDescriptor) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB ejb] : bean-pool is correctly defined"));
                }
            } else {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB ejb] : bean-pool element not defined"));
            }
            return result;
        } catch (Exception ex) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create a beanPool object"));
        }
    } else {
        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create an IASEjbExtraDescriptor object"));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbMessageBeanDescriptor(com.sun.enterprise.deployment.EjbMessageBeanDescriptor) IASEjbExtraDescriptors(org.glassfish.ejb.deployment.descriptor.runtime.IASEjbExtraDescriptors) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)21 Result (com.sun.enterprise.tools.verifier.Result)14 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)14 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)12 Method (java.lang.reflect.Method)5 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)4 HashSet (java.util.HashSet)3 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)2 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)2 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)2 BusinessInterfaceDescriptor (org.jboss.weld.ejb.spi.BusinessInterfaceDescriptor)2 Node (org.w3c.dom.Node)2 EjbIORConfigurationDescriptor (com.sun.enterprise.deployment.EjbIORConfigurationDescriptor)1 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)1 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)1 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)1 XMLElement (com.sun.enterprise.deployment.node.XMLElement)1 EjbRefNode (com.sun.enterprise.deployment.node.runtime.EjbRefNode)1 MessageDestinationRefNode (com.sun.enterprise.deployment.node.runtime.MessageDestinationRefNode)1 ResourceEnvRefNode (com.sun.enterprise.deployment.node.runtime.ResourceEnvRefNode)1