use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.
the class HomeMethodRmiIIOPArgs method check.
/**
* Enterprise Bean's ejbHome methods argument RMI IIOP test.
* Each enterprise Bean class may define zero or more ejbHome methods.
* The method signatures must follow these rules:
*
* The methods arguments must be legal types for RMI-IIOP.
*
* @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();
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
boolean oneFailed = false;
int foundAtLeastOne = 0;
try {
if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", " [ {0} ] does not have a remote home interface. ", new Object[] { descriptor.getEjbClassName() }));
return result;
}
ClassLoader jcl = getVerifierContext().getClassLoader();
Class rc = Class.forName(descriptor.getHomeClassName(), false, jcl);
Class[] homeMethodParameterTypes;
boolean homeMethodFound = false;
boolean isLegalRMIIIOP = false;
for (Method remoteMethod : rc.getMethods()) {
// we don't test the EJB methods
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome"))
continue;
if (remoteMethod.getName().startsWith("create") || remoteMethod.getName().startsWith("find") || remoteMethod.getName().startsWith("remove"))
continue;
// reset flags from last time thru loop
Class c = Class.forName(descriptor.getEjbClassName(), false, jcl);
// start do while loop here....
do {
for (Method method : c.getDeclaredMethods()) {
isLegalRMIIIOP = false;
homeMethodFound = false;
String methodName = "ejbHome" + Character.toUpperCase(remoteMethod.getName().charAt(0)) + remoteMethod.getName().substring(1);
if (method.getName().equals(methodName)) {
foundAtLeastOne++;
homeMethodFound = true;
// The methods arguments types must be legal types for RMI-IIOP.
homeMethodParameterTypes = method.getParameterTypes();
if (RmiIIOPUtils.isValidRmiIIOPParameters(homeMethodParameterTypes)) {
// these method parameters are valid, continue
isLegalRMIIIOP = true;
}
// method
if (homeMethodFound && isLegalRMIIIOP) {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares ejbHome<Method> method " + "[ {1} ] with valid RMI-IIOP parameter types.", new Object[] { descriptor.getEjbClassName(), method.getName() }));
} else if (homeMethodFound && !isLegalRMIIIOP) {
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: ejbHome<Method> method [ {0} ] was found, " + "but ejbHome<Method> method has illegal parameter " + "values. ejbHome<Method> methods arguments types " + "must be legal types for RMI-IIOP.", new Object[] { method.getName() }));
break;
}
}
}
if (oneFailed == true)
break;
} while (((c = c.getSuperclass()) != null) && (!homeMethodFound));
}
if (foundAtLeastOne == 0) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", " [ {0} ] does not declare any ejbHome<Method> methods. ", new Object[] { descriptor.getEjbClassName() }));
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Remote interface [ {0} ] or bean class [ {1} ] does not " + "exist or is not loadable within bean [ {2} ].", new Object[] { descriptor.getRemoteClassName(), descriptor.getEjbClassName(), descriptor.getName() }));
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else if (foundAtLeastOne == 0) {
result.setStatus(Result.NOT_APPLICABLE);
} else {
result.setStatus(Result.PASSED);
}
return result;
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean or {2} bean, but called with {3}.", new Object[] { getClass(), "Session", "Entity", descriptor.getName() }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.
the class HomeMethodRmiIIOPReturn method check.
/**
* Enterprise Bean's home methods argument RMI IIOP test.
* Each enterprise Bean class must define zero or more home methods.
* The method signatures must follow these rules:
*
* The methods return value must be legal types for RMI-IIOP.
*
* @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();
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
boolean oneFailed = false;
int foundAtLeastOne = 0;
try {
if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", " [ {0} ] does not have a remote home interface. ", new Object[] { descriptor.getEjbClassName() }));
return result;
}
ClassLoader jcl = getVerifierContext().getClassLoader();
Class rc = Class.forName(descriptor.getHomeClassName(), false, jcl);
Class methodReturnType;
boolean homeMethodFound = false;
boolean isLegalRMIIIOPReturn = false;
for (Method remoteMethod : rc.getMethods()) {
// we don't test the EJB methods
if (remoteMethod.getDeclaringClass().getName().equals("javax.ejb.EJBHome"))
continue;
if (remoteMethod.getName().startsWith("create") || remoteMethod.getName().startsWith("find") || remoteMethod.getName().startsWith("remove"))
continue;
// reset flags from last time thru loop
Class c = Class.forName(descriptor.getEjbClassName(), false, jcl);
// start do while loop here....
do {
for (Method method : c.getDeclaredMethods()) {
// reset flags from last time thru loop
homeMethodFound = false;
isLegalRMIIIOPReturn = false;
String methodName = "ejbHome" + Character.toUpperCase(remoteMethod.getName().charAt(0)) + remoteMethod.getName().substring(1);
if (method.getName().equals(methodName)) {
foundAtLeastOne++;
homeMethodFound = true;
// The methods arguments types must be legal types for
// RMI-IIOP. This means that their return values must
// be of valid types for RMI-IIOP,
methodReturnType = method.getReturnType();
if (RmiIIOPUtils.isValidRmiIIOPReturnType(methodReturnType)) {
// this is the right return type for method
isLegalRMIIIOPReturn = true;
}
// method
if (homeMethodFound && isLegalRMIIIOPReturn) {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares ejbHome<METHOD> method [ {1} ] with valid RMI-IIOP return type.", new Object[] { descriptor.getEjbClassName(), method.getName() }));
} else if (homeMethodFound && !isLegalRMIIIOPReturn) {
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: ejbHome<METHOD> method [ {0} ] was found, but ejbHome<METHOD> method has illegal return value. ejbHome<METHOD> methods return type must be legal types for RMI-IIOP.", new Object[] { method.getName() }));
}
}
}
if (oneFailed == true)
break;
} while (((c = c.getSuperclass()) != null) && (!homeMethodFound));
}
if (foundAtLeastOne == 0) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", " [ {0} ] does not declare any ejbHome<METHOD> methods. ", new Object[] { descriptor.getEjbClassName() }));
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
oneFailed = true;
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Remote interface [ {0} ] or bean class [ {1} ] does not exist or is not loadable within bean [ {2} ].", new Object[] { descriptor.getRemoteClassName(), descriptor.getEjbClassName(), descriptor.getName() }));
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else if (foundAtLeastOne == 0) {
result.setStatus(Result.NOT_APPLICABLE);
} else {
result.setStatus(Result.PASSED);
}
return result;
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean or {2} bean, but called with {3}.", new Object[] { getClass(), "Session", "Entity", descriptor.getName() }));
return result;
}
}
use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.
the class HomeMethodTest method check.
/**
* @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();
if (getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp", "Not Applicable because, EJB [ {0} ] has Local Interfaces only.", new Object[] { descriptor.getEjbClassName() }));
return result;
}
if (!(descriptor instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1", "Test apply only to session or entity beans."));
return result;
}
boolean homeMethodFound = false;
try {
// retrieve the remote interface methods
ClassLoader jcl = getVerifierContext().getClassLoader();
Class homeInterfaceClass = Class.forName(getClassName(descriptor), false, jcl);
Vector<Method> v = new Vector<Method>();
while (homeInterfaceClass != null && !homeInterfaceClass.getName().equals(getSuperInterface()) && !homeInterfaceClass.getName().equals("java.lang.Object")) {
Method[] homeInterfaceMethods = homeInterfaceClass.getDeclaredMethods();
for (int i = 0; i < homeInterfaceMethods.length; i++) {
v.add(homeInterfaceMethods[i]);
}
homeInterfaceClass = homeInterfaceClass.getSuperclass();
}
Iterator iterator = v.iterator();
while (iterator.hasNext()) {
Method method = (Method) iterator.next();
String methodName = method.getName();
if (methodName.startsWith("create") || methodName.startsWith("find") || methodName.startsWith("remove"))
continue;
Method m = getMethod(javax.ejb.EJBHome.class, methodName, method.getParameterTypes());
if (m != null) {
// this is an EJBHome method...
continue;
}
homeMethodFound = true;
// if (!runIndividualHomeMethodTest( method,descriptor, result))
// oneFailed = true;
runIndividualHomeMethodTest(method, descriptor, result);
if (result.getStatus() == Result.FAILED)
break;
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
addErrorDetails(result, compName);
result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { getClassName(descriptor), descriptor.getName() }));
}
if (!homeMethodFound) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable2", "Home interface [ {0} ] does not define any home methods", new Object[] { getClassName(descriptor) }));
}
// }
return result;
}
use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.
the class RemoteHomeInterfaceRmiIIOPException method runIndividualHomeMethodTest.
/**
* <p>
* run an individual verifier test against a declared method of the
* remote interface.
* </p>
*
* @param descriptor the deployment descriptor for the bean
* @param method the method to run the test on
*/
protected void runIndividualHomeMethodTest(Method method, EjbDescriptor descriptor, Result result) {
Class[] methodExceptionTypes = method.getExceptionTypes();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
// methods must also throw java.rmi.RemoteException
if (RmiIIOPUtils.isValidRmiIIOPException(methodExceptionTypes)) {
// this is the right exception for method, throws RemoteException
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] method properly throws java.rmi.RemoteException.", new Object[] { method.getName() }));
} else {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] method was found, but does not properly throw " + "java.rmi.RemoteException.", new Object[] { method.getName() }));
}
}
use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.
the class RemoteHomeInterfaceSuperInterface method check.
/**
* Enterprise beans home interface test.
*
* The following are the requirements for the enterprise Bean's home interface
* signature:
*
* The home interface is allowed to have superinterfaces. Use of interface
* inheritance is subject to the RMI-IIOP rules for the definition of remote
* interfaces.
*
* @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();
if (descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp", "Not Applicable because, EJB [ {0} ] has Local Interfaces only.", new Object[] { descriptor.getEjbClassName() }));
return result;
}
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
boolean oneFailed = false;
boolean ok = false;
try {
ClassLoader jcl = getVerifierContext().getClassLoader();
Class c = Class.forName(descriptor.getHomeClassName(), false, jcl);
Class remote = c;
boolean validHomeInterface = false;
// walk up the class tree
do {
Class[] interfaces = c.getInterfaces();
if (interfaces.length == 0) {
ok = true;
}
for (Class intf : interfaces) {
logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { intf.getName() });
// requirement is met if one superinterface complies.
if (!ok) {
ok = RmiIIOPUtils.isValidRmiIIOPInterface(intf);
}
if (RmiIIOPUtils.isValidRmiIIOPInterfaceMethods(intf)) {
// this interface is valid, continue
if (intf.getName().equals("javax.ejb.EJBHome")) {
validHomeInterface = true;
break;
}
} else {
// before you determine if this is EJBHome interface, and break
// out of loop, report status of SuperInterface
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly conform to " + "rules of RMI-IIOP for superinterfaces. All " + "enterprise beans home interfaces are allowed " + "to have superinterfaces that conform to the " + "rules of RMI-IIOP for superinterfaces . [ {1} ] " + "is not a valid home interface.", new Object[] { intf.getName(), descriptor.getHomeClassName() }));
}
}
} while ((((c = c.getSuperclass()) != null) && (!validHomeInterface)));
// check that superinterface check was a success
if (!ok) {
oneFailed = true;
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly conform to rules of " + "RMI-IIOP for superinterfaces. All enterprise beans " + "home interfaces are allowed to have superinterfaces " + "that conform to the rules of RMI-IIOP for superinterfaces . " + " [{1} ] is not a valid home interface.", new Object[] { remote.getName(), descriptor.getHomeClassName() }));
}
//
if (validHomeInterface) {
addGoodDetails(result, compName);
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly conforms to rules of RMI-IIOP for superinterfaces.", new Object[] { descriptor.getHomeClassName() }));
}
} 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[] { descriptor.getHomeClassName(), descriptor.getName() }));
oneFailed = true;
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
return result;
} else {
addNaDetails(result, compName);
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "{0} expected {1} bean or {2} bean, but called with {3}.", new Object[] { getClass(), "Session", "Entity", descriptor.getName() }));
return result;
}
}
Aggregations