use of com.sun.enterprise.deployment.MethodDescriptor 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;
}
}
use of com.sun.enterprise.deployment.MethodDescriptor 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;
}
}
use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.
the class FindMethodHasDescriptors method runIndividualQueryTest.
/**
* <p>
* Run an individual test against a finder method (single or multi)
* </p>
*
* @param method is the finder method reference
* @param descriptor is the entity bean descriptor
* @param targetClass is the class to apply to tests to
* @param result is where to place the result
*
* @return true if the test passes
*/
protected boolean runIndividualQueryTest(Method method, EjbCMPEntityDescriptor descriptor, Class targetClass, Result result) {
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
if (method.getName().equals("findByPrimaryKey")) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.FindMethodHasDescriptors.passed1", "Passed: Found method findByPrimaryKey", new Object[] {}));
return true;
}
// We don't use getQueryFor to free ourselfves from classloader issues.
Set set = descriptor.getPersistenceDescriptor().getQueriedMethods();
Iterator iterator = set.iterator();
if (iterator.hasNext()) {
while (iterator.hasNext()) {
MethodDescriptor queryMethod = (MethodDescriptor) iterator.next();
if (queryMethod.getName().equals(method.getName())) {
Class[] mParms = method.getParameterTypes();
String[] queryParms = queryMethod.getParameterClassNames();
int queryParamsLen;
if (queryParms == null)
queryParamsLen = 0;
else
queryParamsLen = queryParms.length;
if (queryParamsLen == mParms.length) {
boolean same = true;
if (queryParamsLen > 0) {
for (int i = 0; i < mParms.length; i++) {
if (!mParms[i].getName().equals(queryParms[i]))
same = false;
}
}
if (same) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.FindMethodHasDescriptors.passed", "[ {0} ] has a query element associated with it", new Object[] { method }));
return true;
}
}
}
}
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.FindMethodHasDescriptors.failed", "Error : [ {0} ] seems to be a finder method but has no query element associated with it", new Object[] { method }));
return false;
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.FindMethodHasDescriptors.notApplicable", "NotApplicable : No Query methods found", new Object[] {}));
return true;
}
}
use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.
the class SelectMethodQL method runIndividualSelectTest.
/**
* <p>
* run an individual test against a declared ejbSelect method
* </p>
*
* @param m is the ejbSelect method
* @param descriptor is the entity declaring the ejbSelect
* @param result is where to put the result
*
* @return true if the test passes
*/
protected boolean runIndividualSelectTest(Method m, EjbCMPEntityDescriptor descriptor, Result result) {
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
// We don't use getQueryFor to free ourselfves from classloader issues.
Set set = descriptor.getPersistenceDescriptor().getQueriedMethods();
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
MethodDescriptor queryMethod = (MethodDescriptor) iterator.next();
if (queryMethod.getName().equals(m.getName())) {
Class[] mParms = m.getParameterTypes();
String[] queryParms = queryMethod.getParameterClassNames();
if (queryParms != null) {
if (queryParms.length == mParms.length) {
boolean same = true;
for (int i = 0; i < mParms.length; i++) {
if (!mParms[i].getName().equals(queryParms[i]))
same = false;
}
if (same) {
QueryDescriptor qd = descriptor.getPersistenceDescriptor().getQueryFor(queryMethod);
String query = qd.getQuery();
if (query == null && qd.getSQL() == null) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.failed2", "Error : [ {0} ] EJB-QL query and description are null", new Object[] { m.getName() }));
return false;
} else {
if (query == null) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.passed1", "Description for [ {0} ] is provided", new Object[] { m.getName() }));
return true;
}
if (query.toUpperCase().indexOf("SELECT") == -1) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.failed2", "Error : EJB-QL query for method [ {0} is null", new Object[] { m.getName() }));
return false;
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.passed2", "EJB-QL query for [ {0} ] is correct", new Object[] { m.getName() }));
return true;
}
}
}
}
} else if (mParms.length == 0) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.passed3", "No EJB-QL query found", new Object[] {}));
return true;
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.failed2", "Error : EJB-QL query for method [ {0} is null", new Object[] { m.getName() }));
return false;
}
}
}
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.SelectMethodQL.failed1", "Error : [ {0} ] does not have a XML query element associated", new Object[] { m.getName() }));
return false;
}
use of com.sun.enterprise.deployment.MethodDescriptor 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;
}
Aggregations