Search in sources :

Example 1 with EjbSessionDescriptor

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

the class StatefulSessionBeanInjection method check.

public Result check(WebBundleDescriptor descriptor) {
    // initialize the result object
    Result result = getInitializedResult();
    addWarningDetails(result, getVerifierContext().getComponentNameConstructor());
    // default status is PASSED
    result.setStatus(Result.PASSED);
    Set<EjbReference> s = descriptor.getEjbReferenceDescriptors();
    if (s == null)
        return result;
    for (EjbReference ejbRefDesc : s) {
        EjbDescriptor ejbDescriptor = ejbRefDesc.getEjbDescriptor();
        if (ejbDescriptor instanceof EjbSessionDescriptor) {
            // instaceof returns false if ejbDescriptor=null.
            String stateType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType();
            if (EjbSessionDescriptor.STATEFUL.equals(stateType)) {
                Set<InjectionTarget> injectionTargets = ejbRefDesc.getInjectionTargets();
                if (injectionTargets != null) {
                    for (InjectionTarget it : injectionTargets) {
                        String itClassName = it.getClassName();
                        result.warning(smh.getLocalString(className + ".warning", "Found a stateful session bean [ {0} ] injected into [ {1} ].", new Object[] { ejbDescriptor.getEjbClassName(), itClassName }));
                    }
                }
            }
        }
    }
    return result;
}
Also used : EjbReference(com.sun.enterprise.deployment.types.EjbReference) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 2 with EjbSessionDescriptor

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

the class HomeInterfaceExtendsRightInterface method check.

/**
 * Extends the EJBHome Interface test.
 * All enterprise beans home interface's must extend the EJBHome interface.
 *
 * @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 str = null;
    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);
            str = getSuperInterface();
            if (isImplementorOf(c, str)) {
                // it extends the proper EJBHome
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly extends the " + str + "interface.", 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: [ {0} ] does not properly extend the  " + str + " interface.  All enterprise beans home interfaces must extend the  " + str + " interface.  [ {1} ] is not a valid home interface.", new Object[] { getClassName(descriptor), 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 3 with EjbSessionDescriptor

use of com.sun.enterprise.deployment.EjbSessionDescriptor 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 4 with EjbSessionDescriptor

use of com.sun.enterprise.deployment.EjbSessionDescriptor 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 5 with EjbSessionDescriptor

use of com.sun.enterprise.deployment.EjbSessionDescriptor 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)

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