use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class TransactionType method check.
/**
* Session Bean's Transaction demarcation test.
* If the enterprise bean is a Session Bean, the Bean provider must use
* the "transaction-type" element to declare whether the transaction
* demarcation is performed by the enterprise bean or the container.
*
* @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) {
String transactionType = descriptor.getTransactionType();
if (EjbSessionDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType) || EjbSessionDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] is valid transactionType.", new Object[] { transactionType }));
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] is not valid transactionType within bean [ {1} ].", new Object[] { transactionType, descriptor.getName() }));
}
return result;
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Session", "Entity" }));
return result;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class TransientFieldsSerialization method check.
/**
* The Bean Provider must assume that the content of transient fields may be
* lost between the ejbPassivate and ejbActivate notifications. Therefore, the
* Bean Provider should not store in a transient field a reference to any of
* the following objects: SessionContext object; environment JNDI naming
* context and any its subcontexts; home and remote interfaces; and the
* UserTransaction interface. The restrictions on the use of transient fields
* ensure that Containers can use Java Serialization during passivation and
* activation.
*
* @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();
boolean isEjb30 = descriptor.getEjbBundleDescriptor().getSpecVersion().equalsIgnoreCase("3.0");
if (descriptor instanceof EjbSessionDescriptor) {
try {
Class c = Class.forName(((EjbSessionDescriptor) descriptor).getEjbClassName(), false, getVerifierContext().getClassLoader());
// Bean Provider should not store in a transient field a reference to
// any of the following objects: SessionContext object; environment
// JNDI naming context and any its subcontexts; home and remote
// interfaces; and the UserTransaction interface.
Field[] fields = c.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
int modifiers = fields[i].getModifiers();
if (!Modifier.isTransient(modifiers)) {
continue;
} else {
Class fc = fields[i].getType();
// sg133765: do we need to do something for business interface
if ((fc.getName().equals("javax.ejb.SessionContext")) || (fc.getName().equals("javax.transaction.UserTransaction")) || (fc.getName().equals(descriptor.getRemoteClassName())) || (fc.getName().equals(descriptor.getHomeClassName())) || (fc.getName().equals(descriptor.getLocalClassName())) || (fc.getName().equals(descriptor.getLocalHomeClassName())) || (isEjb30 && fc.getName().equals("javax.ejb.EntityManager")) || (isEjb30 && fc.getName().equals("javax.ejb.EntityManagerFactory"))) {
result.failed(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Field [ {0} ] defined within" + " session bean class [ {1} ] is defined as transient. " + "Session bean fields should not store in a " + "transient field a reference to any of the following objects: " + "SessionContext object; environment JNDI naming context and any " + "its subcontexts; home and remote interfaces;" + " and the UserTransaction interface.", new Object[] { fields[i].getName(), ((EjbSessionDescriptor) descriptor).getEjbClassName() }));
}
}
}
} catch (ClassNotFoundException e) {
Verifier.debug(e);
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { ((EjbSessionDescriptor) descriptor).getEjbClassName() }));
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "This session bean class has not stored in a " + "transient field a reference to any of the following objects: " + "SessionContext object; environment JNDI naming context and" + " any its subcontexts; home and remote interfaces; and the " + "UserTransaction interface."));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class TransactionDemarcationBeanManaged method check.
/**
* Session/Entity Bean bean-managed transaction demarcation type test.
* The Application Assembler must not define transaction attributes for an
* enterprise bean with bean-managed transaction demarcation.
*
* @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 {
// enterprise bean with bean-managed transaction demarcation.
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
String transactionType = descriptor.getTransactionType();
if (EjbDescriptor.BEAN_TRANSACTION_TYPE.equals(transactionType)) {
ContainerTransaction containerTransaction = null;
if (!descriptor.getMethodContainerTransactions().isEmpty()) {
for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements(); ) {
MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
containerTransaction = (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);
try {
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(""))) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid. The Application Assembler must not define transaction attributes for an enterprise bean [ {2} ] with bean-managed transaction demarcation.", new Object[] { transactionAttribute, methodDescriptor.getName(), descriptor.getName() }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid: TransactionAttribute [ {0} ] for method [ {1} ] is not defined for an enterprise bean [ {2} ] with bean-managed transaction demarcation.", new Object[] { transactionAttribute, methodDescriptor.getName(), descriptor.getName() }));
}
} catch (NullPointerException e) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Valid: TransactionAttribute is null for method [ {0} ] in bean [ {1} ]", new Object[] { methodDescriptor.getName(), descriptor.getName() }));
return result;
}
}
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed2", "Valid: There are no method permissions within this bean [ {0} ]", new Object[] { descriptor.getName() }));
}
return result;
} else {
// not container managed, but is a session/entity bean
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Bean [ {0} ] is not [ {1} ] managed, it is [ {2} ] managed.", new Object[] { descriptor.getName(), EjbDescriptor.BEAN_TRANSACTION_TYPE, transactionType }));
}
return result;
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
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) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] does not contain class [ {1} ] within bean [ {2} ]", new Object[] { descriptor.getName(), t.getMessage(), descriptor.getName() }));
return result;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class CallbackMethodException method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
ClassLoader cl = getVerifierContext().getClassLoader();
Set<LifecycleCallbackDescriptor> callbackDescs = new HashSet<LifecycleCallbackDescriptor>();
for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
callbackDescs.addAll(interceptor.getPostConstructDescriptors());
callbackDescs.addAll(interceptor.getPreDestroyDescriptors());
callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE));
callbackDescs.addAll(interceptor.getCallbackDescriptors(LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE));
}
if (descriptor.hasPostConstructMethod())
callbackDescs.addAll(descriptor.getPostConstructDescriptors());
if (descriptor.hasPreDestroyMethod())
callbackDescs.addAll(descriptor.getPreDestroyDescriptors());
// session descriptor has two extra interceptor methods.
if (descriptor instanceof EjbSessionDescriptor) {
EjbSessionDescriptor ejbSessionDescriptor = ((EjbSessionDescriptor) descriptor);
if (ejbSessionDescriptor.hasPostActivateMethod())
callbackDescs.addAll(ejbSessionDescriptor.getPostActivateDescriptors());
if (ejbSessionDescriptor.hasPrePassivateMethod())
callbackDescs.addAll(ejbSessionDescriptor.getPrePassivateDescriptors());
}
for (LifecycleCallbackDescriptor callbackDesc : callbackDescs) {
try {
Method method = callbackDesc.getLifecycleCallbackMethodObject(cl);
Class[] excepClasses = method.getExceptionTypes();
for (Class exception : excepClasses) {
if (!(RuntimeException.class.isAssignableFrom(exception) || java.rmi.RemoteException.class.isAssignableFrom(exception))) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString(getClass().getName() + ".failed", "Method [ {0} ] throws an application exception.", new Object[] { method }));
}
}
}// 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 Callback methods."));
}
return result;
}
use of org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor in project Payara by payara.
the class ContainerTransactionMethodExists 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 = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
Map<MethodDescriptor, ContainerTransaction> transactionalMethods = descriptor.getMethodContainerTransactions();
if (transactionalMethods != null) {
for (MethodDescriptor methodDescriptor : transactionalMethods.keySet()) checkMethodStyles(methodDescriptor, descriptor);
}
}
if (result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid container transaction method(s) found."));
}
return result;
}
Aggregations