Search in sources :

Example 6 with EjbSessionDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor 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)

Example 7 with EjbSessionDescriptor

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

the class ExtendsRightInterface method check.

/**
 * local interfaces extend the EJBLocalObject interface and remote interfaces
 * extend the EJBObject interface test.
 * All enterprise beans remote interfaces must extend the EJBObject interface
 * and/or local interfaces must extend the EJBLocalObject 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 (!(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 {
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class c = Class.forName(getClassName(descriptor), false, jcl);
        str = getSuperInterface();
        if (isImplementorOf(c, str)) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] " + getInterfaceType() + " interface properly extends the" + str + " interface.", new Object[] { getClassName(descriptor) }));
        } else {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly extend the EJBObject interface. " + " All enterprise bean" + getInterfaceType() + " interfaces must extend the" + str + "  interface." + " [ {1} ] is not a valid " + getInterfaceType() + "interface within bean [ {2} ]", new Object[] { getClassName(descriptor), getClassName(descriptor), descriptor.getName() }));
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { getClassName(descriptor) }));
    }
    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 8 with EjbSessionDescriptor

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

the class BeanFieldsTransient method check.

/**
 *  The Bean Provider should not declare the session bean fields in the session
 *  bean class as transient.
 *
 *  This is to allow the Container to swap out an instance's state through
 *  techniques other than the Java Serialization protocol. For example, the
 *  Container's Java Virtual Machine implementation may use a block of memory
 *  to keep the instance's variables, and the Container swaps the whole memory
 *  block to the disk instead of performing Java Serialization on the instance.
 *
 * @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) {
        try {
            Class c = Class.forName(((EjbSessionDescriptor) descriptor).getEjbClassName(), false, getVerifierContext().getClassLoader());
            // fields should not be defined in the session bean class as transient.
            Field[] fields = c.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                int modifiers = fields[i].getModifiers();
                if (!Modifier.isTransient(modifiers)) {
                    continue;
                } else {
                    addWarningDetails(result, compName);
                    result.warning(smh.getLocalString(getClass().getName() + ".warning", "Warning: Field [ {0} ] defined within session bean class [ {1} ] is defined as transient.  Session bean fields should not be defined in the session bean class as transient.", new Object[] { fields[i].getName(), ((EjbSessionDescriptor) descriptor).getEjbClassName() }));
                }
            }
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { ((EjbSessionDescriptor) descriptor).getEjbClassName() }));
        } catch (Throwable t) {
            addWarningDetails(result, compName);
            result.warning(smh.getLocalString(getClass().getName() + ".warningException", "Warning: [ {0} ] class encountered [ {1} ]. " + "Cannot access fields of class [ {2} ] which is external to [ {3} ].", new Object[] { (descriptor).getEjbClassName(), t.toString(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri() }));
        }
        return result;
    }
    if (result.getStatus() != Result.WARNING) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "The session bean class has defined all fields " + "as non-transient fields."));
    }
    return result;
}
Also used : Field(java.lang.reflect.Field) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 9 with EjbSessionDescriptor

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

the class SessionSynchronizationInterface method check.

/**
 * Optionally implements the SessionSynchronization Interface test.
 * The optional SessionSynchronization interface may be implemented only by
 * a stateful Session Bean using container-managed transactions. The
 * SessionSynchronization interface must not be implemented by a stateless
 * 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();
    if (descriptor instanceof EjbSessionDescriptor) {
        String stateType = ((EjbSessionDescriptor) descriptor).getSessionType();
        try {
            Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
            // walk up the class tree
            do {
                // for (int i = 0; i < interfaces.length; i++) {
                for (Class interfaces : c.getInterfaces()) {
                    logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { interfaces.getName() });
                    if (interfaces.getName().equals("javax.ejb.SessionSynchronization")) {
                        String transactionType = descriptor.getTransactionType();
                        if ((EjbSessionDescriptor.STATELESS.equals(stateType)) || ((EjbSessionDescriptor.STATEFUL.equals(stateType)) && EjbSessionDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType))) {
                            addErrorDetails(result, compName);
                            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly implement the SessionSynchronization interface. " + " SessionSynchronization interface must not be implemented by a stateless Session Bean. " + "[ {1} ] is not a valid bean.", new Object[] { descriptor.getEjbClassName(), descriptor.getEjbClassName() }));
                            break;
                        }
                    }
                }
            } while ((c = c.getSuperclass()) != null);
        } 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[] { descriptor.getEjbClassName() }));
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "The required interface is properly implemented"));
    }
    return result;
}
Also used : EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 10 with EjbSessionDescriptor

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

the class TransactionDemarcationHomeInterface method check.

/**
 * Session Bean transaction demarcation type home interface methods test.
 * Transaction attributes must not be specified for the methods of a session
 * bean's 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();
    // <ejb-class>verifier.ejb.hello.BogusEJB...
    try {
        // bean's home interface.
        if (descriptor instanceof EjbSessionDescriptor) {
            String transactionType = descriptor.getTransactionType();
            VerifierTestContext context = getVerifierContext();
            ClassLoader jcl = context.getClassLoader();
            if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
                boolean oneFailed = false;
                if (descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) {
                    Class superclass = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
                    do {
                        oneFailed = commonToBothInterfaces(superclass.getName(), (EjbSessionDescriptor) descriptor, MethodDescriptor.EJB_HOME);
                        if (oneFailed == true) {
                            break;
                        }
                        superclass = superclass.getSuperclass();
                    } while (superclass != null);
                }
                if (descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) {
                    Class superclass = Class.forName(descriptor.getLocalHomeClassName(), false, getVerifierContext().getClassLoader());
                    do {
                        oneFailed = commonToBothInterfaces(superclass.getName(), (EjbSessionDescriptor) descriptor, MethodDescriptor.EJB_LOCALHOME);
                        if (oneFailed == true) {
                            break;
                        }
                        superclass = superclass.getSuperclass();
                    } while (superclass != null);
                }
                if ((oneFailed == false) && (implementsEndpoints(descriptor))) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.webservice.notapp", "Not Applicable because, EJB [ {0} ] implements a Service Endpoint Interface.", new Object[] { compName.toString() }));
                    result.setStatus(Result.NOT_APPLICABLE);
                    return result;
                }
                if (oneFailed) {
                    result.setStatus(Result.FAILED);
                } else {
                    result.setStatus(Result.PASSED);
                }
                return result;
            } else {
                // not container managed, but is a session bean
                addNaDetails(result, compName);
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Bean [ {0} ] is not [ {1} ] managed, it is [ {2} ] managed.", new Object[] { descriptor.getName(), EjbDescriptor.CONTAINER_TRANSACTION_TYPE, transactionType }));
                return result;
            }
        } else {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Session", "Entity" }));
            return result;
        }
    } catch (Throwable t) {
        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[] { t.getMessage(), descriptor.getName() }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) 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