Search in sources :

Example 1 with ResourceReferenceDescriptor

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

the class ResourceRefName method check.

/**
 * Resource Ref Name must be of finite length.
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Set resourceRefs;
    ResourceReferenceDescriptor resrefDes;
    Iterator itr;
    String resrefName;
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // boolean foundIt = false;
    boolean oneFailed = false;
    boolean notApp = false;
    if (!descriptor.getResourceReferenceDescriptors().isEmpty()) {
        // get the Resource Reference Descriptors set
        resourceRefs = descriptor.getResourceReferenceDescriptors();
        itr = resourceRefs.iterator();
        // test the Resource Reference Descriptor
        while (itr.hasNext()) {
            resrefDes = (ResourceReferenceDescriptor) itr.next();
            resrefName = resrefDes.getName();
            if (resrefName.length() != 0) {
                // foundIt  = true;
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Resource Reference exists in the web application."));
            } else {
                if (!oneFailed)
                    oneFailed = true;
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Resource reference entry must be of finite length."));
            }
        }
    } else {
        notApp = true;
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no resource references defined within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else if (notApp) {
        result.setStatus(Result.NOT_APPLICABLE);
    } else {
        result.setStatus(Result.PASSED);
    }
    return result;
}
Also used : ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor)

Example 2 with ResourceReferenceDescriptor

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

the class ASEntBeanCmpResource method check.

public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    try {
        EjbBundleDescriptorImpl ejbBundleDesc = descriptor.getEjbBundleDescriptor();
        ResourceReferenceDescriptor cmpResource = ejbBundleDesc.getCMPResourceReference();
        if (cmpResource != null) {
            // String jndiName = cmpResource.getJndiName();
            String jndiName = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/jndi-name");
            if (jndiName == null || jndiName.length() == 0) {
                // 4698046
                oneFailed = true;
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-EJB cmp-resource] : jndi-name cannot be an empty string"));
            } else {
                if (jndiName.startsWith("jdbc/") || jndiName.startsWith("jdo/")) {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB cmp-resource] : jndi-name is {0}", new Object[] { jndiName }));
                } else {
                    // 4698046
                    oneWarning = true;
                    addWarningDetails(result, compName);
                    result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB cmp-resource] : The jndi-name  is {0}, the preferred jndi-name should start with  jdbc/ or jdo/", new Object[] { jndiName }));
                }
            }
            ResourcePrincipal defPrincipal = cmpResource.getResourcePrincipal();
            if (defPrincipal != null) {
                // String name = defPrincipal.getName();
                String name = getXPathValue("sun-ejb-jar/enterprise-beans/cmp-resource/default-resource-principal/name");
                if (name == null || name.length() == 0) {
                    // 4698046
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB default-resource-principal] :  name cannot be an empty string"));
                } else {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB default-resource-principal] : name is {0}", new Object[] { name }));
                }
                // String password = defPrincipal.getPassword();
                char[] password = getXPathValueasCharArray("sun-ejb-jar/enterprise-beans/cmp-resource/default-resource-principal/password");
                if (password == null || password.length == 0) {
                    // 4698046
                    oneWarning = true;
                    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() + ".passed2", "PASSED [AS-EJB default-resource-principal] : password is  {0}", new Object[] { new String(password) }));
                }
                Arrays.fill(password, ' ');
            } else {
                addNaDetails(result, compName);
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB cmp-resource] : default-resource-principal Element not defined"));
            }
            Float specVer = getRuntimeSpecVersion();
            if ((Float.compare(specVer.floatValue(), (new Float("2.1")).floatValue()) >= 0)) {
                // property
                result = testProperty("property", result, "sun-ejb-jar/enterprise-beans/cmp-resource/property", compName, descriptor);
                // schema-generator-properties
                result = testProperty("schema-generator-properties", result, "sun-ejb-jar/enterprise-beans/cmp-resource/schema-generator-properties/property", compName, descriptor);
            }
            if (// 4698046
            oneFailed)
                result.setStatus(Result.FAILED);
            else if (oneWarning)
                result.setStatus(Result.WARNING);
        } else {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "NOT APPLICABLE [AS-EJB enterprise-beans] : cmp-resource element is not defined"));
        }
    } catch (Exception ex) {
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB cmp] Could not create descriptor Object."));
    }
    return result;
}
Also used : 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) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 3 with ResourceReferenceDescriptor

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

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

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

the class EnterpriseBeansRuntimeNode method writeDescriptor.

/**
 * write the descriptor class to a DOM tree and return it
 *
 * @param parent node for the DOM tree
 * @param the descriptor to write
 * @return the DOM tree top node
 */
public Node writeDescriptor(Node parent, String nodeName, EjbBundleDescriptorImpl bundleDescriptor) {
    Node ejbs = super.writeDescriptor(parent, nodeName, bundleDescriptor);
    // NOTE : unique-id is no longer written out to sun-ejb-jar.xml.  It is persisted via
    // domain.xml deployment context properties instead.
    // ejb*
    EjbNode ejbNode = new EjbNode();
    for (Iterator ejbIterator = bundleDescriptor.getEjbs().iterator(); ejbIterator.hasNext(); ) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) ejbIterator.next();
        ejbNode.writeDescriptor(ejbs, RuntimeTagNames.EJB, ejbDescriptor);
    }
    // pm-descriptors?
    PMDescriptorsNode pmsNode = new PMDescriptorsNode();
    pmsNode.writeDescriptor(ejbs, RuntimeTagNames.PM_DESCRIPTORS, bundleDescriptor);
    // cmpresource?
    ResourceReferenceDescriptor rrd = bundleDescriptor.getCMPResourceReference();
    if (rrd != null) {
        CmpResourceNode crn = new CmpResourceNode();
        crn.writeDescriptor(ejbs, RuntimeTagNames.CMP_RESOURCE, rrd);
    }
    // message-destination*
    writeMessageDestinationInfo(ejbs, bundleDescriptor);
    // webservice-description*
    WebServiceRuntimeNode webServiceNode = new WebServiceRuntimeNode();
    webServiceNode.writeWebServiceRuntimeInfo(ejbs, bundleDescriptor);
    for (NameValuePairDescriptor p : bundleDescriptor.getEnterpriseBeansProperties()) {
        RuntimeNameValuePairNode nameValNode = new RuntimeNameValuePairNode();
        nameValNode.writeDescriptor(ejbs, RuntimeTagNames.PROPERTY, p);
    }
    return ejbs;
}
Also used : NameValuePairDescriptor(com.sun.enterprise.deployment.NameValuePairDescriptor) MessageDestinationRuntimeNode(com.sun.enterprise.deployment.node.runtime.MessageDestinationRuntimeNode) RuntimeNameValuePairNode(com.sun.enterprise.deployment.node.runtime.common.RuntimeNameValuePairNode) WebServiceRuntimeNode(com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode) Node(org.w3c.dom.Node) RuntimeDescriptorNode(com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode) Iterator(java.util.Iterator) RuntimeNameValuePairNode(com.sun.enterprise.deployment.node.runtime.common.RuntimeNameValuePairNode) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) WebServiceRuntimeNode(com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Aggregations

ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)24 Iterator (java.util.Iterator)11 Set (java.util.Set)8 Result (com.sun.enterprise.tools.verifier.Result)6 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)6 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)5 EjbReference (com.sun.enterprise.deployment.types.EjbReference)4 ResourcePrincipal (com.sun.enterprise.deployment.ResourcePrincipal)3 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)2 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)2 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)2 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)2 MessageDestinationRuntimeNode (com.sun.enterprise.deployment.node.runtime.MessageDestinationRuntimeNode)2 RuntimeDescriptorNode (com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode)2 WebServiceRuntimeNode (com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode)2 MessageDestinationReferencer (com.sun.enterprise.deployment.types.MessageDestinationReferencer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)2 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)2