use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project jersey by jersey.
the class EjbComponentProvider method registerEjbInterceptor.
private void registerEjbInterceptor() {
try {
final Object interceptor = new EjbComponentInterceptor(injectionManager);
initialContext = getInitialContext();
final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance();
final ApplicationInfo appInfo = getApplicationInfo(ejbUtil);
final List<String> tempLibNames = new LinkedList<>();
for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
final String jarName = moduleInfo.getName();
if (jarName.endsWith(".jar") || jarName.endsWith(".war")) {
final String moduleName = jarName.substring(0, jarName.length() - 4);
tempLibNames.add(moduleName);
final Object bundleDescriptor = moduleInfo.getMetaData(EjbBundleDescriptorImpl.class.getName());
if (bundleDescriptor instanceof EjbBundleDescriptorImpl) {
final Collection<EjbDescriptor> ejbs = ((EjbBundleDescriptorImpl) bundleDescriptor).getEjbs();
for (final EjbDescriptor ejb : ejbs) {
final BaseContainer ejbContainer = EjbContainerUtilImpl.getInstance().getContainer(ejb.getUniqueId());
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
final Method registerInterceptorMethod = BaseContainer.class.getDeclaredMethod("registerSystemInterceptor", java.lang.Object.class);
registerInterceptorMethod.setAccessible(true);
registerInterceptorMethod.invoke(ejbContainer, interceptor);
return null;
}
});
} catch (PrivilegedActionException pae) {
final Throwable cause = pae.getCause();
LOGGER.log(Level.WARNING, LocalizationMessages.EJB_INTERCEPTOR_BINDING_WARNING(ejb.getEjbClassName()), cause);
}
}
}
}
}
libNames.addAll(tempLibNames);
final Object interceptorBinder = initialContext.lookup("java:org.glassfish.ejb.container.interceptor_binding_spi");
// the name
if (interceptorBinder == null) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE());
}
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
Method interceptorBinderMethod = interceptorBinder.getClass().getMethod("registerInterceptor", java.lang.Object.class);
interceptorBinderMethod.invoke(interceptorBinder, interceptor);
EjbComponentProvider.this.ejbInterceptorRegistered = true;
LOGGER.log(Level.CONFIG, LocalizationMessages.EJB_INTERCEPTOR_BOUND());
return null;
}
});
} catch (PrivilegedActionException pae) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_ERROR(), pae.getCause());
}
} catch (NamingException ex) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE(), ex);
} catch (LinkageError ex) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_LINKAGE_ERROR(), ex);
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor 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 org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class CmpFields method check.
/**
* Container-managed fields valid type test.
*
* The Bean Provider must ensure that the Java types assigned to the
* container-managed fields are one of the following: Java primitive types,
* Java serializable types, or references to enterprise beans' remote or home
* 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 instanceof EjbEntityDescriptor) {
String persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType();
if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistentType)) {
// this test apply only to 1.x cmp beans, in 2.x fields are virtual fields only
if (EjbCMPEntityDescriptor.CMP_1_1 != ((EjbCMPEntityDescriptor) descriptor).getCMPVersion()) {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.notApplicable3", "Test do not apply to this cmp-version of container managed persistence EJBs"));
return result;
}
VerifierTestContext context = getVerifierContext();
ClassLoader jcl = context.getClassLoader();
// RULE: container-managed fields are one of the following:
// Java primitive types, Java serializable types, or references
// to enterprise beans' remote or home interfaces.
Set persistentFields = ((EjbCMPEntityDescriptor) descriptor).getPersistenceDescriptor().getCMPFields();
Iterator iterator = persistentFields.iterator();
Descriptor persistentField;
Field field;
boolean oneFailed = false;
while (iterator.hasNext()) {
persistentField = (Descriptor) iterator.next();
boolean foundField = false;
try {
Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
// start do while loop here....
do {
try {
Field f = c.getDeclaredField(persistentField.getName());
foundField = true;
Class persistentFieldClassType = f.getType();
if (descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()) && descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName())) {
if (RmiIIOPUtils.isPersistentFieldTypeValid(persistentFieldClassType, descriptor.getHomeClassName(), descriptor.getRemoteClassName())) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned to container managed field [ {0} ] found in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), c.getName() }));
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned to container managed field [ {0} ] found in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), c.getName() }));
}
}
if (descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName()) && descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) {
if (RmiIIOPUtils.isPersistentFieldTypeValid(persistentFieldClassType, descriptor.getLocalHomeClassName(), descriptor.getLocalClassName())) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned to container managed field [ {0} ] found in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), c.getName() }));
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned to container managed field [ {0} ] found in bean [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), c.getName() }));
}
}
} catch (NoSuchFieldException e) {
foundField = false;
}
} while (((c = c.getSuperclass()) != null) && (!foundField));
if (!foundField) {
if (!oneFailed) {
oneFailed = true;
}
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException1", "Error: field [ {0} ] not found in class [ {1} ]", new Object[] { ((Descriptor) persistentField).getName(), 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[] { descriptor.getEjbClassName() }));
}
}
if (oneFailed) {
result.setStatus(Result.FAILED);
} else {
result.setStatus(Result.PASSED);
}
} else {
// if (BEAN_PERSISTENCE.equals(persistentType))
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Expected persistence type [ {0} ], but [ {1} ] bean has persistence type [ {2} ]", new Object[] { EjbEntityDescriptor.CONTAINER_PERSISTENCE, descriptor.getName(), persistentType }));
}
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(), "Entity", "Session" }));
return result;
}
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class CmrFields method runIndividualCmrTest.
/**
* run an individual verifier test of a declated cmr field of the class
*
* @param entity the descriptor for the entity bean containing the cmp-field
* @param info the descriptor for the declared cmr field
* @param c the class owning the cmp field
* @parma r the result object to use to put the test results in
*
* @return true if the test passed
*/
protected boolean runIndividualCmrTest(Descriptor descriptor, RelationRoleDescriptor role, Class c, Result result) {
boolean foundIt = false;
CMRFieldInfo info = null;
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
try {
info = role.getCMRFieldInfo();
} catch (Exception e) {
addErrorDetails(result, compName);
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: No Local interfaces defined for EJB [ {0} ]", new Object[] { descriptor.getName() }));
return false;
}
if (role.getPartner().getIsMany()) {
// must be one the collection interface
if (info.type.getName().equals("java.util.Collection") || info.type.getName().equals("java.util.Set")) {
foundIt = true;
}
} else {
EjbBundleDescriptorImpl bundle = ((EjbDescriptor) descriptor).getEjbBundleDescriptor();
if (((EjbDescriptor) descriptor).getLocalClassName() != null && !"".equals(((EjbDescriptor) descriptor).getLocalClassName())) {
if (isValidInterface(info.type, bundle.getEjbs())) {
foundIt = true;
}
} else {
if ((role.getRelationshipDescriptor()).getIsBidirectional()) {
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
return false;
} else
foundIt = true;
}
}
if (foundIt) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
} else {
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Invalid type assigned for container managed relationship [ {0} ] in bean [ {1} ]", new Object[] { info.name, descriptor.getName() }));
}
return foundIt;
}
use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.
the class DependentValueClassModifiers method runIndividualCmpFieldTest.
/**
* run an individual verifier test of a declated cmp field of the class
*
* @param entity the descriptor for the entity bean containing the cmp-field
* @param f the descriptor for the declared cmp field
* @param c the class owning the cmp field
* @parma r the result object to use to put the test results in
*
* @return true if the test passed
*/
protected boolean runIndividualCmpFieldTest(Descriptor entity, Descriptor persistentField, Class c, Result result) {
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
String fieldName = persistentField.getName();
String getMethodName = "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
Method getMethod = getMethod(c, getMethodName, null);
if (getMethod != null) {
Class returnType = getMethod.getReturnType();
// check if this is a reference to a primitive or an array of primitive type
if (returnType.isArray()) {
returnType = returnType.getComponentType();
}
if (returnType.isPrimitive()) {
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.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
return true;
}
if (returnType.isInterface()) {
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.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
return true;
}
if (returnType.toString().startsWith("class java.")) {
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.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
return true;
}
// it must be a reference to a bean's home or remote interface
EjbBundleDescriptorImpl bundle = ((EjbDescriptor) entity).getEjbBundleDescriptor();
if ((isValidInterface(returnType, bundle.getEjbs(), MethodDescriptor.EJB_REMOTE)) || (isValidInterface(returnType, bundle.getEjbs(), MethodDescriptor.EJB_LOCAL))) {
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.CMPTest.DependentValueClassModifiers.notApplicable", "Field [ {0} ] is not a dependent value class reference", new Object[] { fieldName }));
return true;
}
// this is a reference to a dependent value class
int modifiers = returnType.getModifiers();
if (Modifier.isPublic(modifiers) && Modifier.isAbstract(modifiers) == false && EjbUtils.isValidSerializableType(returnType)) {
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.CMPTest.DependentValueClassModifiers.passed", "Dependent value class [ {0} ] reference by cmp field [ {1} ] is public, not abstract and serializable", new Object[] { returnType.getName(), fieldName }));
return true;
} else {
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addWarningDetails(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.entity.cmp2.CMPTest.DependentValueClassModifiers.failed", "Verifier cannot find out if [ {0} ] is a Dependent value class (reference by cmp field [ {1} ]) ", new Object[] { returnType.getName(), fieldName }));
return false;
}
} 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.CMPTest.isAccessorDeclared.failed2", "Error : Cannot find accessor [ {0} ] method for [ {1} ] field ", new Object[] { getMethodName, fieldName }));
return false;
}
}
Aggregations