Search in sources :

Example 16 with ConnectionDefDescriptor

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

the class CheckConnectionFactoryImplSerializable method check.

/**
 * <p>
 * Test for each connection-definition, that "connectionfactory-impl-class"
 * implements java.io.Serializable
 * </p>
 *
 * @param descriptor deployment descriptor for the rar file
 * @return result object containing the result of the individual test
 * performed
 */
public Result check(ConnectorDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // test NA for inboundRA
    if (!descriptor.getOutBoundDefined()) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.managed.notApplicableForInboundRA", "Resource Adapter does not provide outbound communication"));
        return result;
    }
    OutboundResourceAdapter outboundRA = descriptor.getOutboundResourceAdapter();
    if (outboundRA == null) {
        return null;
    }
    boolean oneFailed = false;
    Set connDefs = outboundRA.getConnectionDefs();
    Iterator iter = connDefs.iterator();
    while (iter.hasNext()) {
        ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor) iter.next();
        String connectionImpl = connDefDesc.getConnectionFactoryImpl();
        Class implClass = null;
        try {
            implClass = Class.forName(connectionImpl, false, getVerifierContext().getClassLoader());
        } catch (ClassNotFoundException e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".nonexist", "Error: The class [ {0} ] as defined under connectionfactory-impl-class in the deployment descriptor does not exist", new Object[] { connectionImpl }));
            return result;
        }
        if (!isImplementorOf(implClass, "java.io.Serializable")) {
            oneFailed = true;
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: connectionfactory-impl-class [ {0} ] does not implement java.io.Serializable", new Object[] { implClass.getName() }));
            return result;
        }
    }
    if (!oneFailed) {
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Success: all connectionfactory-impl-class implement java.io.Serializable"));
    }
    return result;
}
Also used : Set(java.util.Set) ConnectionDefDescriptor(com.sun.enterprise.deployment.ConnectionDefDescriptor) Iterator(java.util.Iterator) OutboundResourceAdapter(com.sun.enterprise.deployment.OutboundResourceAdapter) Result(com.sun.enterprise.tools.verifier.Result)

Example 17 with ConnectionDefDescriptor

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

the class ManagedConnectionFactoryProperties method check.

/**
 * <p>
 * Test that the class declared implementing the javax.resource.spi.ManagedConnectionFactory
 * interface implements the properties declared under the config-property
 * xml tag under the followind requirements :
 *      - Provide a getter and setter method ala JavaBeans
 *      - Properties should be either bound or constrained
 *      - PropertyListener registration/unregistration methods are public
 * </p>
 *
 * @paramm descriptor deployment descriptor for the rar file
 * @return result object containing the result of the individual test
 * performed
 */
public Result check(ConnectorDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // test NA for inboundRA
    if (!descriptor.getOutBoundDefined()) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.managed.notApplicableForInboundRA", "Resource Adapter does not provide outbound communication"));
        return result;
    }
    boolean oneFailed = false;
    OutboundResourceAdapter outboundRA = descriptor.getOutboundResourceAdapter();
    Set connDefs = outboundRA.getConnectionDefs();
    Iterator iter = connDefs.iterator();
    while (iter.hasNext()) {
        ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor) iter.next();
        Set configProperties = connDefDesc.getConfigProperties();
        if (!configProperties.isEmpty()) {
            Iterator propIterator = configProperties.iterator();
            Class mcf = testManagedConnectionFactoryImpl(descriptor, result);
            if (mcf == null) {
                // set the error code now, just abandon
                return result;
            }
            while (propIterator.hasNext()) {
                EnvironmentProperty ep = (EnvironmentProperty) propIterator.next();
                // Set method first
                String propertyName = Character.toUpperCase(ep.getName().charAt(0)) + ep.getName().substring(1);
                String setMethodName = "set" + propertyName;
                Class[] parmTypes = new Class[] { ep.getValueType() };
                Method m = getMethod(mcf, setMethodName, parmTypes);
                if (m != null) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Found a JavaBeans compliant accessor method [ {0} ] for the config-property [ {1} ]", new Object[] { m, ep.getName() }));
                } else {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: There is no JavaBeans compliant accessor method [ {0} ] implemented in [ {1} ] for the config-property [ {2} ]", new Object[] { "public void " + setMethodName + "(" + ep.getValueType().getName() + ")", mcf.getName(), ep.getName() }));
                }
                String getMethodName = "get" + propertyName;
                m = getMethod(mcf, getMethodName, null);
                if (m != null) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Found a JavaBeans compliant accessor method [ {0} ] for the config-property [ {1} ]", new Object[] { m, ep.getName() }));
                } else {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: There is no JavaBeans compliant accessor method [ {0} ] implemented in [ {1} ] for the config-property [ {2} ]", new Object[] { "public " + ep.getValueType().getName() + " " + getMethodName, mcf.getName(), ep.getName() }));
                }
            }
        }
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else {
        result.setStatus(Result.PASSED);
    }
    return result;
}
Also used : ConnectionDefDescriptor(com.sun.enterprise.deployment.ConnectionDefDescriptor) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) OutboundResourceAdapter(com.sun.enterprise.deployment.OutboundResourceAdapter)

Example 18 with ConnectionDefDescriptor

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

the class ManagedConnectionFactoryTest method getManagedConnectionFactoryImpl.

/**
 * <p>
 * Get the <code>Class</code> object of the class declared to be implementing
 * the javax.resource.spi.ManagedConnectionFactory interface in the
 * archive deployment descriptor
 * </p>
 *
 * @param descriptor the rar file deployment descriptor
 *
 * @throws ClassNotFoundException if the class identified by className
 * cannot be loaded
 */
protected Class getManagedConnectionFactoryImpl(ConnectorDescriptor descriptor) throws ClassNotFoundException {
    OutboundResourceAdapter outboundRA = descriptor.getOutboundResourceAdapter();
    if (outboundRA == null) {
        return null;
    }
    Set connDefs = outboundRA.getConnectionDefs();
    Iterator iter = connDefs.iterator();
    while (iter.hasNext()) {
        ConnectionDefDescriptor connDefDesc = (ConnectionDefDescriptor) iter.next();
        managedConnectionFactoryImpl = connDefDesc.getManagedConnectionFactoryImpl();
        Class implClass = Class.forName(managedConnectionFactoryImpl, false, getVerifierContext().getClassLoader());
        if (isImplementorOf(implClass, "javax.resource.spi.ManagedConnectionFactory")) {
            return implClass;
        }
    }
    return null;
/*  String className = descriptor.getManagedConnectionFactoryImpl();
          if (className == null) 
          return null;

          VerifierTestContext context = getVerifierContext();
          ClassLoader jcl = context.getRarClassLoader();
          return jcl.loadClass(className);   */
}
Also used : Set(java.util.Set) ConnectionDefDescriptor(com.sun.enterprise.deployment.ConnectionDefDescriptor) Iterator(java.util.Iterator) OutboundResourceAdapter(com.sun.enterprise.deployment.OutboundResourceAdapter)

Aggregations

ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)18 OutboundResourceAdapter (com.sun.enterprise.deployment.OutboundResourceAdapter)11 Iterator (java.util.Iterator)8 Set (java.util.Set)8 Result (com.sun.enterprise.tools.verifier.Result)6 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)4 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)3 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)3 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)2 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)2 ConnectorDescriptorInfo (com.sun.enterprise.connectors.ConnectorDescriptorInfo)1 ConnectorRegistry (com.sun.enterprise.connectors.ConnectorRegistry)1 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)1 RarBundleContext (com.sun.enterprise.deployment.annotation.context.RarBundleContext)1 ClassLoader (java.lang.ClassLoader)1 Method (java.lang.reflect.Method)1 ManagedConnectionFactory (javax.resource.spi.ManagedConnectionFactory)1 Property (org.jvnet.hk2.config.types.Property)1