Search in sources :

Example 1 with InboundResourceAdapter

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

the class CheckActivationSpecClass method check.

/**
 * <p>
 * Test for each message-listener , that "activationspec-class"
 * implements "javax.resource.spi.ActivationSpec".
 * </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();
    if (!descriptor.getInBoundDefined()) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.messageinflow.notApp", "Resource Adapter does not provide inbound communication"));
        return result;
    }
    InboundResourceAdapter ra = descriptor.getInboundResourceAdapter();
    Set msgListeners = ra.getMessageListeners();
    boolean oneFailed = false;
    Iterator iter = msgListeners.iterator();
    while (iter.hasNext()) {
        MessageListener msgListener = (MessageListener) iter.next();
        String impl = msgListener.getActivationSpecClass();
        Class implClass = null;
        try {
            implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
        } catch (ClassNotFoundException e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.messageinflow.nonexist", "Error: The class [ {0} ] as defined under activationspec-class in the deployment descriptor does not exist", new Object[] { impl }));
            return result;
        }
        if (!isImplementorOf(implClass, "javax.resource.spi.ActivationSpec")) {
            oneFailed = true;
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: activationspec-class [ {0} ] does not implement javax.resource.spi.ActivationSpec.", new Object[] { impl }));
            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 activationspec-class implement javax.resource.spi.ActivationSpec"));
    }
    return result;
}
Also used : Set(java.util.Set) InboundResourceAdapter(com.sun.enterprise.deployment.InboundResourceAdapter) Iterator(java.util.Iterator) MessageListener(com.sun.enterprise.deployment.MessageListener) Result(com.sun.enterprise.tools.verifier.Result)

Example 2 with InboundResourceAdapter

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

the class CheckActivationSpecJavaBean method check.

/**
 * <p>
 * Test for each message-listener, that "activationspec-class" is a Java Bean.
 * </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();
    if (!descriptor.getInBoundDefined()) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.messageinflow.notApp", "Resource Adapter does not provide inbound communication"));
        return result;
    }
    InboundResourceAdapter ra = descriptor.getInboundResourceAdapter();
    Set msgListeners = ra.getMessageListeners();
    boolean oneFailed = false;
    Iterator iter = msgListeners.iterator();
    while (iter.hasNext()) {
        MessageListener msgListener = (MessageListener) iter.next();
        String impl = msgListener.getActivationSpecClass();
        Class implClass = null;
        try {
            implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
        } catch (ClassNotFoundException e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.messageinflow.nonexist", "Error: The class [ {0} ] as defined under activationspec-class in the deployment descriptor does not exist", new Object[] { impl }));
            return result;
        }
        Set configProps = msgListener.getConfigProperties();
        Iterator propIter = configProps.iterator();
        BeanInfo bi = null;
        try {
            bi = Introspector.getBeanInfo(implClass, Object.class);
        } catch (IntrospectionException ie) {
            oneFailed = true;
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: The activationspec-class [ {0} ] is not JavaBeans compliant", new Object[] { impl }));
            return result;
        }
        PropertyDescriptor[] properties = bi.getPropertyDescriptors();
        Hashtable<String, PropertyDescriptor> props = new Hashtable<String, PropertyDescriptor>();
        for (int i = 0; i < properties.length; i++) {
            props.put(properties[i].getName(), properties[i]);
        }
        while (propIter.hasNext()) {
            EnvironmentProperty envProp = (EnvironmentProperty) propIter.next();
            String name = envProp.getName();
            String type = envProp.getType();
            PropertyDescriptor propDesc = (PropertyDescriptor) props.get(name.substring(0, 1).toLowerCase() + name.substring(1));
            if (propDesc != null) {
                if (propDesc.getReadMethod() == null || propDesc.getWriteMethod() == null) {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: The activationspec-class [ {0} ] does not provide accessor methods for [ {1} ].", new Object[] { impl, name }));
                    return result;
                }
            } else {
                oneFailed = true;
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed1", "Error: The activationspec-class [ {0} ] does not provide accessor methods for [ {1} ].", new Object[] { impl, name }));
                return result;
            }
        }
    }
    if (!oneFailed) {
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Success: Each activationspec-class is a Java Bean"));
    }
    return result;
}
Also used : InboundResourceAdapter(com.sun.enterprise.deployment.InboundResourceAdapter) MessageListener(com.sun.enterprise.deployment.MessageListener) Result(com.sun.enterprise.tools.verifier.Result) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty)

Example 3 with InboundResourceAdapter

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

the class CheckActivationSpecSerializable method check.

/**
 * <p>
 * Test that "activationspec-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();
    if (!descriptor.getInBoundDefined()) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.messageinflow.notApp", "Resource Adapter does not provide inbound communication"));
        return result;
    }
    InboundResourceAdapter ra = descriptor.getInboundResourceAdapter();
    Set msgListeners = ra.getMessageListeners();
    boolean oneFailed = false;
    Iterator iter = msgListeners.iterator();
    while (iter.hasNext()) {
        MessageListener msgListener = (MessageListener) iter.next();
        String impl = msgListener.getActivationSpecClass();
        Class implClass = null;
        try {
            implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
        } catch (ClassNotFoundException e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.messageinflow.nonexist", "Error: The class [ {0} ] as defined under activationspec-class in the deployment descriptor does not exist", new Object[] { impl }));
            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: activationspec-class [ {0} ] does not implement java.io.Serializable", new Object[] { impl }));
            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 activationspec-class implement java.io.Serializable"));
    }
    return result;
}
Also used : Set(java.util.Set) InboundResourceAdapter(com.sun.enterprise.deployment.InboundResourceAdapter) Iterator(java.util.Iterator) MessageListener(com.sun.enterprise.deployment.MessageListener) Result(com.sun.enterprise.tools.verifier.Result)

Example 4 with InboundResourceAdapter

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

the class ActivationHandler method processAnnotation.

public HandlerProcessingResult processAnnotation(AnnotationInfo element) throws AnnotationProcessorException {
    AnnotatedElementHandler aeHandler = element.getProcessingContext().getHandler();
    Activation activation = (Activation) element.getAnnotation();
    if (aeHandler instanceof RarBundleContext) {
        RarBundleContext rarContext = (RarBundleContext) aeHandler;
        ConnectorDescriptor desc = rarContext.getDescriptor();
        // process annotation only if message-listeners are provided
        if (activation.messageListeners().length > 0) {
            // initialize inbound if it was not done already
            if (!desc.getInBoundDefined()) {
                desc.setInboundResourceAdapter(new InboundResourceAdapter());
            }
            InboundResourceAdapter ira = desc.getInboundResourceAdapter();
            // get the activation-spec implementation class-name
            Class c = (Class) element.getAnnotatedElement();
            String activationSpecClass = c.getName();
            // process all message-listeners, ensure that no duplicate message-listener-types are found
            for (Class mlClass : activation.messageListeners()) {
                MessageListener ml = new MessageListener();
                ml.setActivationSpecClass(activationSpecClass);
                ml.setMessageListenerType(mlClass.getName());
                if (!ira.hasMessageListenerType(mlClass.getName())) {
                    ira.addMessageListener(ml);
                }
            // else {
            // ignore the duplicates
            // duplicates can be via :
            // (i) message listner defined in DD
            // (ii) as part of this particular annotation processing,
            // already this message-listener-type is defined
            // TODO V3 how to handle (ii)
            // }
            }
        }
    } else {
        getFailureResult(element, "Not a rar bundle context", true);
    }
    return getDefaultProcessedResult();
}
Also used : ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) InboundResourceAdapter(com.sun.enterprise.deployment.InboundResourceAdapter) RarBundleContext(com.sun.enterprise.deployment.annotation.context.RarBundleContext) MessageListener(com.sun.enterprise.deployment.MessageListener) Activation(javax.resource.spi.Activation)

Example 5 with InboundResourceAdapter

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

the class CheckActivationSpecOverridesEquals method check.

/**
 * <p>
 * Test for each message-listener , that "activationspec-class"
 * does not override the equals method.
 * </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();
    if (!descriptor.getInBoundDefined()) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.messageinflow.notApp", "Resource Adapter does not provide inbound communication"));
        return result;
    }
    InboundResourceAdapter ra = descriptor.getInboundResourceAdapter();
    Set msgListeners = ra.getMessageListeners();
    boolean oneFailed = false;
    Iterator iter = msgListeners.iterator();
    while (iter.hasNext()) {
        MessageListener msgListener = (MessageListener) iter.next();
        String impl = msgListener.getActivationSpecClass();
        Class implClass = null;
        try {
            implClass = Class.forName(impl, false, getVerifierContext().getClassLoader());
        } catch (ClassNotFoundException e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.connector.messageinflow.nonexist", "Error: The class [ {0} ] as defined under activationspec-class in the deployment descriptor does not exist", new Object[] { impl }));
            return result;
        }
        try {
            Method equalsMethod = implClass.getMethod("equals", new Class[] { implClass });
            oneFailed = true;
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: activationspec-class [ {0} ] overrides the equals method", new Object[] { impl }));
            return result;
        } catch (NoSuchMethodException e) {
        // implClass does not override equals.
        } catch (SecurityException e) {
        }
    }
    if (!oneFailed) {
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Success: all activationspec-class do not override the equals method"));
    }
    return result;
}
Also used : Set(java.util.Set) InboundResourceAdapter(com.sun.enterprise.deployment.InboundResourceAdapter) MessageListener(com.sun.enterprise.deployment.MessageListener) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) Iterator(java.util.Iterator)

Aggregations

InboundResourceAdapter (com.sun.enterprise.deployment.InboundResourceAdapter)6 MessageListener (com.sun.enterprise.deployment.MessageListener)6 Result (com.sun.enterprise.tools.verifier.Result)4 Iterator (java.util.Iterator)4 Set (java.util.Set)3 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)1 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)1 RarBundleContext (com.sun.enterprise.deployment.annotation.context.RarBundleContext)1 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)1 Method (java.lang.reflect.Method)1 Activation (javax.resource.spi.Activation)1 Node (org.w3c.dom.Node)1