Search in sources :

Example 96 with Result

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

the class ASEjbRRefDefResPrincipal method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    try {
        Set resRef = descriptor.getResourceReferenceDescriptors();
        if (!(resRef.isEmpty())) {
            Iterator it = resRef.iterator();
            while (it.hasNext()) {
                ResourceReferenceDescriptor resDesc = ((ResourceReferenceDescriptor) it.next());
                String refName = resDesc.getName();
                String refJndiName = resDesc.getJndiName();
                ResourcePrincipal resPrinci = resDesc.getResourcePrincipal();
                if (resPrinci == null) {
                    try {
                        resDesc = descriptor.getResourceReferenceByName(refName);
                        String resAuth = resDesc.getAuthorization();
                        if (resAuth.equals(ResourceReferenceDescriptor.APPLICATION_AUTHORIZATION)) {
                            addErrorDetails(result, compName);
                            result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB resource-ref] : res-auth for res-ref-name {0} is defined as Application." + "Therefore the default-resource-principal should be supplied with valid properties", new Object[] { refName }));
                        } else {
                            addNaDetails(result, compName);
                            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB resource-ref] : default-resource-principal Element not defined"));
                        }
                    } catch (IllegalArgumentException iaex) {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB resource-ref] : res-ref-name {0} is not defined in the ejb-jar.xml", new Object[] { refName }));
                    }
                } else {
                    String name = resPrinci.getName();
                    if (name == null || name.length() == 0) {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-EJB default-resource-principal] :  name cannot be an empty string"));
                    } else {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB default-resource-principal] : name is {0}", new Object[] { name }));
                    }
                    String password = resPrinci.getPassword();
                    if (password == null || password.length() == 0) {
                        addWarningDetails(result, compName);
                        result.warning(smh.getLocalString(getClass().getName() + ".warning1", "WARNING [AS-EJB default-resource-principal] : password is an empty string"));
                    } else {
                        addGoodDetails(result, compName);
                        result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB default-resource-principal] : password is  {0}", new Object[] { password }));
                    }
                    if (oneFailed)
                        result.setStatus(Result.FAILED);
                }
            }
        } else {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} Does not define any resource-ref Elements"));
        }
    } catch (Exception ex) {
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create the descriptor object"));
    }
    return result;
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 97 with Result

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

the class ASEjbRRefName method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    try {
        Set resRef = descriptor.getResourceReferenceDescriptors();
        if (!(resRef.isEmpty())) {
            Iterator it = resRef.iterator();
            while (it.hasNext()) {
                ResourceReferenceDescriptor resDesc = ((ResourceReferenceDescriptor) it.next());
                String refName = resDesc.getName();
                if (refName == null || refName.length() == 0) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB resource-ref] : resource-ref has empty res-ref-name"));
                } else {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB resource-ref] : res-ref-name is {0}", new Object[] { refName }));
                }
            }
        } else {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} Does not define any resource-ref Elements", new Object[] { descriptor.getName() }));
        }
    } catch (Exception ex) {
        addErrorDetails(result, compName);
        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create the descriptor object"));
    }
    return result;
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 98 with Result

use of com.sun.enterprise.tools.verifier.Result 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 99 with Result

use of com.sun.enterprise.tools.verifier.Result 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 100 with Result

use of com.sun.enterprise.tools.verifier.Result 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)

Aggregations

Result (com.sun.enterprise.tools.verifier.Result)288 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)212 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)88 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)66 Method (java.lang.reflect.Method)66 Iterator (java.util.Iterator)50 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)28 Set (java.util.Set)26 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)17 Enumeration (java.util.Enumeration)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)14 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)14 Field (java.lang.reflect.Field)13 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)10 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)9 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)9 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)7 ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)6 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)6