Search in sources :

Example 1 with ContainerTransaction

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

the class SEIEJBTxAttrChk method check.

/**
 * @param descriptor the  WebService deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebServiceEndpoint wsdescriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean pass = true;
    if (wsdescriptor.implementedByEjbComponent()) {
        EjbDescriptor descriptor = (EjbDescriptor) wsdescriptor.getEjbComponentImpl();
        try {
            ContainerTransaction ctx = descriptor.getContainerTransaction();
            if ((ctx != null) && (ContainerTransaction.MANDATORY.equals(ctx.getTransactionAttribute()))) {
                // Call result.failed here : All methods are having Mandatory TX
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "[{0}] of this WebService [{1}] have Mandatory Transaction Attribute.", new Object[] { "All the methods", compName.toString() }));
                return result;
            }
            Collection txMethDescs = descriptor.getTransactionMethodDescriptors();
            // get hold of the SEI Class
            String s = descriptor.getWebServiceEndpointInterfaceName();
            if (s == null) {
                // internal error, should never happen
                result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.webservices.Error", "Error: Unexpected error occurred [ {0} ]", new Object[] { "Service Endpoint Interface Class Name Null" }));
                pass = false;
            }
            ClassLoader cl = getVerifierContext().getClassLoader();
            Class sei = null;
            try {
                sei = Class.forName(s, false, cl);
            } catch (ClassNotFoundException e) {
                result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.webservices.Error", "Error: Unexpected error occurred [ {0} ]", new Object[] { "Could not Load Service Endpoint Interface Class" }));
                pass = false;
            }
            Iterator it = txMethDescs.iterator();
            while (it.hasNext()) {
                // need to check if this method is part of SEI
                MethodDescriptor methdesc = (MethodDescriptor) it.next();
                if (isSEIMethod(methdesc, descriptor, sei, cl)) {
                    ctx = descriptor.getContainerTransactionFor(methdesc);
                    if ((ctx != null) && (ContainerTransaction.MANDATORY.equals(ctx.getTransactionAttribute()))) {
                        // Call result.failed here with Method details here
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "[{0}] of this WebService [{1}] have Mandatory Transaction Attribute.", new Object[] { methdesc.getName(), compName.toString() }));
                        pass = false;
                    }
                }
            }
        } catch (Exception e) {
            // Call result.addErrorDetails here with exception details
            result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.webservices.Error", "Error: Unexpected error occurred [ {0} ]", new Object[] { e.getMessage() }));
            pass = false;
        }
        if (pass) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "None of the methods of this WebService [{0}] have Mandatory Transaction Attribute.", new Object[] { compName.toString() }));
        }
        return result;
    } else {
        // call result.notapplicable
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notapp", "Not applicable since this is not an EJB Service Endpoint."));
        return result;
    }
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) Iterator(java.util.Iterator) Collection(java.util.Collection) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 2 with ContainerTransaction

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

the class TransactionDemarcationComponentInterface method commonToBothInterfaces.

/**
 * This method is responsible for the logic of the test. It is called for both local and component interfaces.
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @param component for the Remote/Local interface of the Ejb.
 * @return boolean the results for this assertion i.e if a test has failed or not
 */
private boolean commonToBothInterfaces(String component, EjbDescriptor descriptor, String methodIntf) {
    boolean oneFailed = false;
    try {
        Arrays.sort(EJBObjectMethods);
        // retrieve the component interface methods
        Class componentInterfaceClass = Class.forName(component, false, getVerifierContext().getClassLoader());
        Method[] componentInterfaceMethods = componentInterfaceClass.getDeclaredMethods();
        boolean lookForIt = false;
        for (int i = 0; i < componentInterfaceMethods.length; i++) {
            if (Arrays.binarySearch(EJBObjectMethods, componentInterfaceMethods[i].getName()) < 0) {
                try {
                    ContainerTransaction containerTransaction = null;
                    boolean resolved = false;
                    if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                        for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                            lookForIt = false;
                            MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                            // style 1)
                            if (methodDescriptor.getName().equals(MethodDescriptor.ALL_METHODS)) {
                                // if Remote - PASS
                                if (methodDescriptor.getEjbClassSymbol() == null) {
                                    lookForIt = true;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) {
                                    lookForIt = true;
                                // if empty String PASS
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) {
                                    lookForIt = true;
                                } else if (methodDescriptor.getEjbClassSymbol().equals("")) {
                                    lookForIt = true;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) {
                                    lookForIt = false;
                                } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) {
                                    lookForIt = false;
                                } else {
                                    // carry on & don't look for
                                    // container transaction
                                    lookForIt = false;
                                }
                            } else if (methodDescriptor.getParameterClassNames() == null) {
                                // if (getEjbClassSybol() is Remote or is the empty String AND if componentInterfaceMethods[i].getName().equals(methodDescriptor.getName())
                                if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) && (componentInterfaceMethods[i].getName().equals(methodDescriptor.getName()))) {
                                    // PASS
                                    lookForIt = true;
                                } else {
                                    // carry on
                                    lookForIt = false;
                                }
                            } else {
                                if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCAL)) && (componentInterfaceMethods[i].getName().equals(methodDescriptor.getName())) && (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(componentInterfaceMethods[i], methodIntf)).getParameterClassNames()))) {
                                    // PASS
                                    lookForIt = true;
                                } else {
                                    // CARRY ON
                                    lookForIt = false;
                                }
                            }
                            if (lookForIt) {
                                containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
                                if (containerTransaction != null) {
                                    String transactionAttribute = containerTransaction.getTransactionAttribute();
                                    // don't need this check here
                                    if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute) || (!transactionAttribute.equals(""))) {
                                        addGoodDetails(result, compName);
                                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid: [ {0} ] TransactionAttribute [ {1} ] for method [ {2} ] is valid. Transaction attributes must be defined for all methods except getEJBHome, getHandle, getPrimaryKey, and isIdentical methods of component interface [ {3} ].", new Object[] { componentInterfaceMethods[i].getName(), transactionAttribute, methodDescriptor.getName(), component }));
                                        resolved = true;
                                    } else {
                                        oneFailed = true;
                                        addErrorDetails(result, compName);
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] TransactionAttribute [ {1} ] for method [ {2} ] is not valid.   Transaction attributes must be defined for all methods except getEJBHome, getHandle, getPrimaryKey, and isIdentical methods of component interface [ {3} ]", new Object[] { componentInterfaceMethods[i].getName(), transactionAttribute, methodDescriptor.getName(), component }));
                                    }
                                } else {
                                    oneFailed = true;
                                    addErrorDetails(result, compName);
                                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException", "Error: TransactionAttribute is null for method [ {0} ]", new Object[] { methodDescriptor.getName() }));
                                }
                            }
                        }
                        // did you resolve the last one okay?
                        if (!resolved) {
                            /*
                                // This if-stmt code is a workaround introduced by Harminder
                                // because currently methodDescriptor.getEjbClassSymbol() is
                                // returning NULL
                                //if (allMethods){
                                if (!wildCardWasPresent) {
*/
                            oneFailed = true;
                            addErrorDetails(result, compName);
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: Transaction attributes must be specified for the methods defined in the component interface [ {0} ].  Method [ {1} ] has no transaction attribute defined within this bean [ {2} ].", new Object[] { component, componentInterfaceMethods[i].getName(), descriptor.getName() }));
                        }
                    /*
                                 else {
					     result.addGoodDetails(smh.getLocalString
								   ("tests.componentNameConstructor",
								    "For [ {0} ]",
								    new Object[] {compName.toString()}));
					     result.addGoodDetails(smh.getLocalString
								   (getClass().getName() + ".passed",
								    "Valid: [ {0} ] TransactionAttribute [ {1} ] for method [ {2} ] is valid. Transaction attributes must be defined for all methods except getEJBHome, getHandle, getPrimaryKey, and isIdentical methods of component interface [ {3} ].",
								    new Object[] {componentInterfaceMethods[i].getName(), "*", "*" ,component}));
//                              }
                              // End of workaround code. Note : this else also has to be removed once
                              // the original bug of methodDesc.getEjbClassSymbol() is fixed
			     }
*/
                    } else {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed2", "Error: There are no method permissions within this bean [ {0} ].   Transaction attributes must be specified for the methods defined in the component interface [ {1} ].  Method [ {2} ] has no transaction attribute defined.", new Object[] { descriptor.getName(), component, componentInterfaceMethods[i].getName() }));
                    }
                    if (oneFailed == true && i == componentInterfaceMethods.length - 1)
                        return oneFailed;
                    else
                        continue;
                } catch (Exception e) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: Component interface [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { component, e.getMessage(), descriptor.getName() }));
                    oneFailed = true;
                    return oneFailed;
                }
            } else // if you found a business method
            {
                oneFailed = true;
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failedExcep", "Error: Method [ {0} ] should not be assigned a transaction attribute.", new Object[] { componentInterfaceMethods[i].getName() }));
            }
        }
        // for all component interface methods
        return oneFailed;
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Component interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { component, descriptor.getName() }));
        oneFailed = true;
        return oneFailed;
    }
}
Also used : Enumeration(java.util.Enumeration) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor)

Example 3 with ContainerTransaction

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

the class HasValidMethodDescriptor method check.

/**
 * Run a verifier test against an individual declared message
 * drive bean component
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbMessageBeanDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor.getTransactionType().equals(EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
        // returns the Message Listener methods and "ejbTimeout" if the bean is a
        // TimedObject.
        Collection methods = descriptor.getTransactionMethodDescriptors();
        if (methods.size() == 0) {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Message-driven bean [ {0} ] does not define any method", new Object[] { descriptor.getName() }));
            return result;
        }
        Iterator iterator = methods.iterator();
        while (iterator.hasNext()) {
            MethodDescriptor method = (MethodDescriptor) iterator.next();
            if (descriptor.isTimedObject() && (method.getName()).equals("ejbTimeout"))
                continue;
            ContainerTransaction txAttr = descriptor.getContainerTransactionFor(method);
            if (txAttr == null) {
                if (getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5) < 0) {
                    // transaction attribute is not specified for method.
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed4", "Error : Message-driven bean [ {0} ] method definition [ {1} ] does not have a valid container transaction descriptor.", new Object[] { descriptor.getName(), method.getName() }));
                }
                // default transaction attr in EJB 3.0 is REQUIRED
                continue;
            }
            String ta = txAttr.getTransactionAttribute();
            if (ContainerTransaction.REQUIRED.equals(ta) || ContainerTransaction.NOT_SUPPORTED.equals(ta)) {
                addGoodDetails(result, compName);
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "Message-driven bean [ {0} ] method definition [ {1} ] in assembly-descriptor is correct", new Object[] { descriptor.getName(), method.getName() }));
            } else {
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed3", "Error : Message-driven bean [ {0} ] method definition [ {1} ] transaction attribute must be Required or NotSupported", new Object[] { descriptor.getName(), method.getName() }));
            }
        }
        return result;
    } else {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Message-driven bean [ {0} ] does not use container-managed transaction", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) Iterator(java.util.Iterator) Collection(java.util.Collection) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 4 with ContainerTransaction

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

the class TransactionDemarcationHomeInterface method commonToBothInterfaces.

/**
 * This method is responsible for the logic of the test. It is called for both local and remote interfaces.
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @param home for the Home interface of the Ejb.
 * @param methodIntf for the interface type
 * @return boolean the results for this assertion i.e if a test has failed or not
 */
private boolean commonToBothInterfaces(String home, EjbSessionDescriptor descriptor, String methodIntf) {
    boolean oneFailed = false;
    try {
        VerifierTestContext context = getVerifierContext();
        ClassLoader jcl = context.getClassLoader();
        Class c = Class.forName(home, false, getVerifierContext().getClassLoader());
        Method[] methods = c.getDeclaredMethods();
        boolean lookForIt = false;
        for (int i = 0; i < methods.length; i++) {
            try {
                ContainerTransaction containerTransaction = null;
                boolean resolved = true;
                if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                    for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                        lookForIt = false;
                        MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                        // style 1)
                        if (methodDescriptor.getName().equals(MethodDescriptor.ALL_METHODS)) {
                            // if Home - PASS
                            if (methodDescriptor.getEjbClassSymbol() == null) {
                                lookForIt = true;
                            } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME)) {
                                lookForIt = true;
                            // if empty String PASS
                            } else if (methodDescriptor.getEjbClassSymbol().equals("")) {
                                lookForIt = true;
                            } else if (methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_REMOTE)) {
                                lookForIt = false;
                            // else (Bogus)
                            } else {
                                // carry on & don't look for
                                // container transaction
                                lookForIt = false;
                            }
                        } else if (methodDescriptor.getParameterClassNames() == null) {
                            // if (getEjbClassSybol() is Home or is the empty String AND if methods[i].getName().equals(methodDescriptor.getName())
                            if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) && (methods[i].getName().equals(methodDescriptor.getName()))) {
                                // PASS
                                lookForIt = true;
                            } else {
                                // carry on
                                lookForIt = false;
                            }
                        } else {
                            // the parameters of the method[i] are the same as the parameters of the method descriptor )
                            if (((methodDescriptor.getEjbClassSymbol() == null) || methodDescriptor.getEjbClassSymbol().equals("") || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) || methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) && (methods[i].getName().equals(methodDescriptor.getName())) && (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(methods[i], methodIntf)).getParameterClassNames()))) {
                                // PASS
                                lookForIt = true;
                            } else {
                                // CARRY ON
                                lookForIt = false;
                            }
                        }
                        if (lookForIt) {
                            containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
                            if (containerTransaction != null) {
                                String transactionAttribute = containerTransaction.getTransactionAttribute();
                                // don't need this check here
                                if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute) || (!transactionAttribute.equals(""))) {
                                    // if "*" ignore, test N/A
                                    if (!methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_HOME) && !methodDescriptor.getEjbClassSymbol().equals(MethodDescriptor.EJB_LOCALHOME)) {
                                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for home interface [ {2} ]", new Object[] { transactionAttribute, methods[i].getName(), home }));
                                    } else {
                                        oneFailed = true;
                                        addErrorDetails(result, compName);
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid.   Transaction attributes must not be specified for all methods of session bean home interface [ {2} ].", new Object[] { transactionAttribute, methods[i].getName(), home }));
                                        resolved = false;
                                    }
                                } else {
                                    addGoodDetails(result, compName);
                                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for home interface [ {2} ]", new Object[] { transactionAttribute, methods[i].getName(), home }));
                                }
                            } else {
                                addGoodDetails(result, compName);
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedException", "Valid: TransactionAttribute is null for method [ {0} ]", new Object[] { methodDescriptor.getName() }));
                            }
                        }
                    }
                    // did you resolve the last one okay?
                    if (!resolved) {
                        /*
                            // This if-stmt code is a workaround introduced by Harminder
                            // because currently methodDescriptor.getEjbClassSymbol() is
                            // returning NULL
                            //if (allMethods){
                            if (!wildCardWasPresent) {

*/
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: Transaction attributes must not be specified for the methods defined in the session bean home interface [ {0} ].  Method [ {1} ] has transaction attribute defined within this bean [ {2} ].", new Object[] { home, methods[i].getName(), descriptor.getName() }));
                    /*
                            }
                            else {
                            
                              result.addGoodDetails(smh.getLocalString
                                                                   ("tests.componentNameConstructor",
                                                                    "For [ {0} ]",
                                                                    new Object[] {compName.toString()}));
                              result.addGoodDetails(smh.getLocalString
                                                                  (getClass().getName() + ".passed",
                                                                   "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is defined for remote interface [ {2} ]", new Object[] {"*", "*",home}));


                            }
                            // End of workaround code. Note : this else also has to be removed once
                            // the original bug of methodDesc.getEjbClassSymbol() is fixed
*/
                    } else {
                        addGoodDetails(result, compName);
                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed2", "Valid: Transaction attributes must not be specified for the methods defined in the session bean home interface [ {0} ].  Method [ {1} ] has no transaction attribute defined within this bean [ {2} ].", new Object[] { home, methods[i].getName(), descriptor.getName() }));
                    }
                } else {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Valid: There are no method permissions within this bean [ {0} ].   Transaction attributes must not be specified for the methods defined in the session bean home interface [ {1} ].  Method [ {2} ] has no transaction attribute defined.", new Object[] { descriptor.getName(), home, methods[i].getName() }));
                }
                if (oneFailed == true)
                    return oneFailed;
            } catch (Exception e) {
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: Home interface [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { home, e.getMessage(), descriptor.getName() }));
                return oneFailed;
            }
        }
        // for all the methods within the home interface class, loop
        return oneFailed;
    } 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[] { home, descriptor.getName() }));
        return oneFailed;
    }
}
Also used : Enumeration(java.util.Enumeration) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction)

Example 5 with ContainerTransaction

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

the class TransactionDemarcationType method check.

/**
 * Session/Entity Bean Transaction demarcation type test.
 * Application Assembler may define attributes for the methods of the
 * remote/home interfaces of the beans that require container managed
 * transaction demarcation.  All beans of the this type (container managed
 * transactions) require container managed tranaction demarcation through
 * the use of "container-transaction" element.
 *
 * @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();
    // <ejb-class>verifier.ejb.hello.BogusEJB...
    try {
        if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
            boolean oneFailed = false;
            String transactionType = descriptor.getTransactionType();
            if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
                try {
                    Arrays.sort(EJBObjectMethods);
                    ContainerTransaction containerTransaction = null;
                    if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                        for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
                            MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                            if (Arrays.binarySearch(EJBObjectMethods, methodDescriptor.getName()) < 0) {
                                containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
                                if (containerTransaction != null && containerTransaction.getTransactionAttribute() != null) {
                                    String transactionAttribute = containerTransaction.getTransactionAttribute();
                                    // don't need this check here
                                    if (ContainerTransaction.NOT_SUPPORTED.equals(transactionAttribute) || ContainerTransaction.SUPPORTS.equals(transactionAttribute) || ContainerTransaction.REQUIRED.equals(transactionAttribute) || ContainerTransaction.REQUIRES_NEW.equals(transactionAttribute) || ContainerTransaction.MANDATORY.equals(transactionAttribute) || ContainerTransaction.NEVER.equals(transactionAttribute)) {
                                        addGoodDetails(result, compName);
                                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "TransactionAttribute [ {0} ] for method [ {1} ] is valid.", new Object[] { transactionAttribute, methodDescriptor.getName() }));
                                    } else {
                                        oneFailed = true;
                                        addErrorDetails(result, compName);
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid.", new Object[] { transactionAttribute, methodDescriptor.getName() }));
                                    }
                                } else {
                                    // Null transaction attributes are allowed in EJB 3. Default is REQUIRED.
                                    if (getVerifierContext().getJavaEEVersion().compareTo(SpecVersionMapper.JavaEEVersion_5) < 0) {
                                        oneFailed = true;
                                        addErrorDetails(result, compName);
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException", "Error: TransactionAttribute is null for method [ {0} ]", new Object[] { methodDescriptor.getName() }));
                                    }
                                }
                            } else // if you found a business method
                            {
                                // check if the ejb is a session bean
                                // and the method with transaction attribute belongs
                                // to home/local home interface
                                String ejbClass = methodDescriptor.getEjbClassSymbol();
                                /**
                                 * Fixed the bug: 4883730. ejbClassSymbol is null when method-intf is not
                                 * defined in the xml, since it is an optional field. Removed the earlier
                                 * checks. A null method-intf indicates that the method is supposed to be
                                 * in both Local & Home interfaces. **
                                 */
                                /*
                                    String methodIntf = null;
                                    try {
                                        methodIntf = methodDescriptor.getEjbClassSymbol();
                                    } catch ( Exception ex ) {}
                                    if ( methodIntf == null ) { //|| methodIntf.equals("") 
                                        continue;
                                    }

*/
                                boolean session = descriptor instanceof EjbSessionDescriptor;
                                boolean entity = descriptor instanceof EjbEntityDescriptor;
                                if (((ejbClass == null) || ejbClass.equals(MethodDescriptor.EJB_HOME) || ejbClass.equals(MethodDescriptor.EJB_LOCALHOME)) && session) {
                                    oneFailed = true;
                                    addErrorDetails(result, compName);
                                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedHome", "Error: TransactionAttribute for method [ {0} ] is not valid. Home or Local Home interface methods of a session bean must not hvae a transaction attribute.", new Object[] { methodDescriptor.getName() }));
                                } else // and method with Tx attribute is "remove"
                                if (((ejbClass == null) || ejbClass.equals(MethodDescriptor.EJB_REMOTE) || ejbClass.equals(MethodDescriptor.EJB_LOCAL)) && session && methodDescriptor.getName().equals("remove")) {
                                    // if remove method defined has parameters then pass else fail
                                    if (methodDescriptor.getParameterClassNames() == null || methodDescriptor.getParameterClassNames().length == 0) {
                                        // style 2
                                        oneFailed = true;
                                        addErrorDetails(result, compName);
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedComp", "Error: TransactionAttribute for method [ {0} ] is not valid. 'remove' method in Remote/Local interface of a session bean must not have a transaction attribute.", new Object[] { methodDescriptor.getName() }));
                                    } else {
                                        addGoodDetails(result, compName);
                                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
                                    }
                                } else if (((ejbClass == null) || ejbClass.equals(MethodDescriptor.EJB_HOME) || ejbClass.equals(MethodDescriptor.EJB_LOCALHOME)) && entity) {
                                    if (methodDescriptor.getParameterClassNames() == null || methodDescriptor.getParameterClassNames().length == 0) {
                                        // style 2
                                        oneFailed = true;
                                        addErrorDetails(result, compName);
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: TransactionAttribute for method [ {0} ] is not valid. ", new Object[] { methodDescriptor.getName() }));
                                    } else {
                                        addGoodDetails(result, compName);
                                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
                                    }
                                } else if (((ejbClass == null) || ejbClass.equals(MethodDescriptor.EJB_REMOTE) || ejbClass.equals(MethodDescriptor.EJB_LOCAL)) && entity) {
                                    if ((methodDescriptor.getName()).equals("isIdentical")) {
                                        if (methodDescriptor.getParameterClassNames() == null || methodDescriptor.getParameterClassNames().length == 0) {
                                            addGoodDetails(result, compName);
                                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
                                        } else {
                                            String[] paramList = methodDescriptor.getParameterClassNames();
                                            if (Array.getLength(paramList) == 1) {
                                                if (paramList[0].equals("javax.ejb.EJBObject")) {
                                                    // style 3
                                                    oneFailed = true;
                                                    addErrorDetails(result, compName);
                                                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: TransactionAttribute for method [ {0} ] is not valid.", new Object[] { methodDescriptor.getName() }));
                                                } else {
                                                    addGoodDetails(result, compName);
                                                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
                                                }
                                            } else {
                                                addGoodDetails(result, compName);
                                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
                                            }
                                        }
                                    } else {
                                        // for all other methods in entity bean
                                        if ((methodDescriptor.getName()).equals("remove")) {
                                            addGoodDetails(result, compName);
                                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passedTest", "TransactionAttribute for method [ {0} ] is valid.", new Object[] { methodDescriptor.getName() }));
                                        } else {
                                            if (methodDescriptor.getParameterClassNames() == null || methodDescriptor.getParameterClassNames().length == 0) {
                                                // style 2
                                                oneFailed = true;
                                                addErrorDetails(result, compName);
                                                result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: [ {0} ] should not have a Transaction Attribute", new Object[] { methodDescriptor.getName() }));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        addNaDetails(result, compName);
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There are no method permissions within this bean [ {0} ]", new Object[] { descriptor.getName() }));
                    }
                } catch (Exception e) {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), e.getMessage(), descriptor.getName() }));
                    return result;
                }
                if (oneFailed) {
                    result.setStatus(Result.FAILED);
                } else {
                    result.setStatus(Result.PASSED);
                }
                return result;
            } else {
                // not container managed, but is a session/entity 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} ] not called \n with a Session or Entity bean.", new Object[] { getClass() }));
            return result;
        }
    } catch (Throwable t) {
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Enumeration(java.util.Enumeration) ContainerTransaction(org.glassfish.ejb.deployment.descriptor.ContainerTransaction) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)18 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)17 Enumeration (java.util.Enumeration)7 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)6 Result (com.sun.enterprise.tools.verifier.Result)5 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)5 Method (java.lang.reflect.Method)5 Iterator (java.util.Iterator)4 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)4 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)3 Set (java.util.Set)3 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)3 Collection (java.util.Collection)2 TransactionAttribute (javax.ejb.TransactionAttribute)2 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)1 LifecycleCallbackDescriptor (com.sun.enterprise.deployment.LifecycleCallbackDescriptor)1 MethodPermission (com.sun.enterprise.deployment.MethodPermission)1 ResourceEnvReferenceDescriptor (com.sun.enterprise.deployment.ResourceEnvReferenceDescriptor)1 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)1 RoleReference (com.sun.enterprise.deployment.RoleReference)1