use of com.sun.enterprise.deployment.MethodDescriptor 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;
}
}
use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.
the class MethodPermissionComponentInterface method check.
/**
* All methods should have a
* @param descriptor the Enterprise Java Bean deployment descriptor
*
* @return <code>Result</code> the results for this assertion
*/
public Result check(EjbDescriptor descriptor) {
result = getInitializedResult();
try {
if (descriptor instanceof EjbSessionDescriptor || descriptor instanceof EjbEntityDescriptor) {
Set methods = descriptor.getMethodDescriptors();
// Set methodPermissions = new HashSet();
boolean noPermissions = false;
for (Iterator i = methods.iterator(); i.hasNext(); ) {
MethodDescriptor md = (MethodDescriptor) i.next();
Set permissions = descriptor.getMethodPermissionsFor(md);
if (permissions.isEmpty() || (permissions == null)) {
result.addWarningDetails(smh.getLocalString(getClass().getName() + ".failed", "Warning: Method [ {0} ] of EJB [ {1} ] does not have assigned security-permissions", new Object[] { md.getName(), descriptor.getName() }));
result.setStatus(result.WARNING);
noPermissions = true;
}
}
if (!noPermissions) {
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid: All [ {0} ]EJB interfaces methods have security-permissions assigned.", new Object[] { descriptor.getName() }));
}
} else {
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "The bean [ {0} ] is neither a Session nor Entity Bean", new Object[] { descriptor.getName() }));
return result;
}
} catch (Exception e) {
result.failed(smh.getLocalString(getClass().getName() + ".exception", "The test generated the following exception [ {0} ]", new Object[] { e.getLocalizedMessage() }));
}
return result;
}
use of com.sun.enterprise.deployment.MethodDescriptor 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;
}
}
use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.
the class BusinessMethodMatchesWithDD method commonToBothInterfaces.
/**
* This method is responsible for the logic of the test. It is called for
* both local and remote interfaces.
* @param intf for the Remote/Local interface of the Ejb.
* @param descriptor the Enterprise Java Bean deployment descriptor
* This parameter may be optional depending on the test
* @param methodIntf for the interface type
*/
private void commonToBothInterfaces(String intf, EjbDescriptor descriptor, String methodIntf) {
try {
Class intfClass = Class.forName(intf, false, getVerifierContext().getClassLoader());
boolean found = false;
Set allMethods = new HashSet();
for (Iterator e = descriptor.getPermissionedMethodsByPermission().values().iterator(); e.hasNext(); ) {
Set methodDescriptors = (Set) e.next();
if (methodDescriptors != null)
allMethods.addAll(methodDescriptors);
}
for (Enumeration e = descriptor.getMethodContainerTransactions().keys(); e.hasMoreElements(); ) {
allMethods.add(e.nextElement());
}
for (Method remoteMethod : intfClass.getMethods()) {
found = false;
// we don't test the EJB methods
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBObject"))
continue;
if (!remoteMethod.getName().startsWith("ejb") && !remoteMethod.getName().equals("class$") && !remoteMethod.getName().equals("setSessionContext")) {
Iterator methods = allMethods.iterator();
while (methods.hasNext()) {
MethodDescriptor methodDescriptor = (MethodDescriptor) methods.next();
if (methodDescriptor.getName().equals(remoteMethod.getName())) {
if (MethodUtils.stringArrayEquals(methodDescriptor.getParameterClassNames(), (new MethodDescriptor(remoteMethod, methodIntf)).getParameterClassNames())) {
found = true;
break;
}
}
}
}
if (!found) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Business method [ {0} ] is not defined " + "in the deployment descriptor.", new Object[] { remoteMethod.getName() }));
}
}
} catch (Exception e) {
Verifier.debug(e);
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Component interface [ {0} ] does not exist " + "or is not loadable within bean [ {1} ].", new Object[] { intf, descriptor.getName() }));
}
}
use of com.sun.enterprise.deployment.MethodDescriptor in project Payara by payara.
the class AroundInvokeNotBusinessMethod method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
ClassLoader cl = getVerifierContext().getClassLoader();
if (descriptor.hasAroundInvokeMethod()) {
Set<MethodDescriptor> businessMethods = descriptor.getMethodDescriptors();
Set<LifecycleCallbackDescriptor> aiDescriptors = descriptor.getAroundInvokeDescriptors();
for (LifecycleCallbackDescriptor aiDesc : aiDescriptors) {
try {
Method interceptorMethod = aiDesc.getLifecycleCallbackMethodObject(cl);
MethodDescriptor interceptorMD = new MethodDescriptor(interceptorMethod);
if (businessMethods.contains(interceptorMD)) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "AroundInvoke method [ {0} ] is a business method.", new Object[] { interceptorMethod }));
}
}// will be caught in other tests
catch (Exception e) {
}
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Interceptor methods."));
}
return result;
}
Aggregations