use of com.sun.enterprise.deployment.EjbMessageBeanDescriptor in project Payara by payara.
the class InboundRecoveryHandler method createRAEjbMapping.
private Map<String, List<EjbDescriptor>> createRAEjbMapping(List<EjbDescriptor> ejbDescriptors) {
Map<String, List<EjbDescriptor>> map = new HashMap<String, List<EjbDescriptor>>();
for (EjbDescriptor ejbDescriptor : ejbDescriptors) {
List<EjbDescriptor> ejbmdbd = new ArrayList<EjbDescriptor>();
String ramid = ((EjbMessageBeanDescriptor) ejbDescriptor).getResourceAdapterMid();
if ((ramid == null) || (ramid.equalsIgnoreCase(""))) {
ramid = ConnectorConstants.DEFAULT_JMS_ADAPTER;
}
// Otherwise, add the RAMid and the current MDB Descriptor to the hashtable
if (map.containsKey(ramid)) {
ejbmdbd = map.get(ramid);
map.remove(ramid);
}
ejbmdbd.add(ejbDescriptor);
map.put(ramid, ejbmdbd);
}
return map;
}
use of com.sun.enterprise.deployment.EjbMessageBeanDescriptor in project Payara by payara.
the class AppSpecificConnectorClassLoaderUtil method processDescriptorForRAReferences.
private void processDescriptorForRAReferences(Application app, Descriptor descriptor, String moduleName) {
if (descriptor instanceof JndiNameEnvironment) {
processDescriptorForRAReferences(app, moduleName, (JndiNameEnvironment) descriptor);
}
// ejb descriptors
if (descriptor instanceof EjbBundleDescriptor) {
EjbBundleDescriptor ejbDesc = (EjbBundleDescriptor) descriptor;
Set<? extends EjbDescriptor> ejbDescriptors = ejbDesc.getEjbs();
for (EjbDescriptor ejbDescriptor : ejbDescriptors) {
processDescriptorForRAReferences(app, moduleName, ejbDescriptor);
if (ejbDescriptor instanceof EjbMessageBeanDescriptor) {
EjbMessageBeanDescriptor messageBeanDesc = (EjbMessageBeanDescriptor) ejbDescriptor;
String raMid = messageBeanDesc.getResourceAdapterMid();
// there seem to be applications that do not specify ra-mid
if (raMid != null) {
app.addResourceAdapter(raMid);
}
}
}
// ejb interceptors
Set<EjbInterceptor> ejbInterceptors = ejbDesc.getInterceptors();
for (EjbInterceptor ejbInterceptor : ejbInterceptors) {
processDescriptorForRAReferences(app, moduleName, ejbInterceptor);
}
}
if (descriptor instanceof BundleDescriptor) {
// managed bean descriptors
Set<ManagedBeanDescriptor> managedBeanDescriptors = ((BundleDescriptor) descriptor).getManagedBeans();
for (ManagedBeanDescriptor mbd : managedBeanDescriptors) {
processDescriptorForRAReferences(app, moduleName, mbd);
}
}
}
use of com.sun.enterprise.deployment.EjbMessageBeanDescriptor in project Payara by payara.
the class ASEjbIsReadOnlyBean method testROBSpecific.
public void testROBSpecific(EjbDescriptor descriptor, IASEjbExtraDescriptors iasEjbExtraDesc, Result result) {
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
try {
// Read only Beans can only be Entity Beans
if (descriptor instanceof EjbEntityDescriptor) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-EJB ejb] : Read Only Beans can only be Entity Beans"));
} else if (descriptor instanceof EjbSessionDescriptor) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-EJB ejb] : Read Only Beans cannot be Session Beans. They can only be Entity Beans"));
return;
} else if (descriptor instanceof EjbMessageBeanDescriptor) {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-EJB ejb] : Read Only Beans cannot be Message Driven Beans. They can only be Entity Beans"));
return;
}
// Only Container Managed Transactions are Allowed
String txnType = descriptor.getTransactionType();
if (txnType.equals(descriptor.CONTAINER_TRANSACTION_TYPE)) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-EJB ejb] : Read Only Beans can only have Container Managed Transactions"));
} else {
oneFailed = true;
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-EJB ejb] : Read Only Beans cannot have Bean Managed Transactions"));
}
// Encourage not to have create/remove methods in Home Interface
String homeName = descriptor.getHomeClassName();
Class homeClass = null;
boolean foundCreateMethod = false;
boolean foundRemoveMethod = false;
homeClass = getVerifierContext().getClassLoader().loadClass(homeName);
Method[] methods = homeClass.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().startsWith("create")) {
foundCreateMethod = true;
break;
}
}
for (int i = 0; i < methods.length; i++) {
if (methods[i].getName().startsWith("remove")) {
foundRemoveMethod = true;
break;
}
}
if (foundCreateMethod) {
oneWarning = true;
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb] : Home interface [ {0} ] should have zero create Methods for Read Only Beans.", new Object[] { homeName }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed3", "PASSED [AS-EJB ejb] : Read Only Bean has zero create Methods"));
}
if (foundRemoveMethod) {
oneWarning = true;
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning1", "WARNING [AS-EJB ejb] : Home interface [ {0} ] should have zero remove Methods for Read Only Beans.", new Object[] { homeName }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed4", "PASSED [AS-EJB ejb] : Read Only Bean has zero remove Methods"));
}
// Refresh Period Test
int refreshPeriod = iasEjbExtraDesc.getRefreshPeriodInSeconds();
if (refreshPeriod != -1) {
long refValue = new Integer(refreshPeriod).longValue();
if (refValue < 0 || refValue > Long.MAX_VALUE) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.failed(smh.getLocalString(getClass().getName() + ".failed4", "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and {0}.", new Object[] { new Long(Long.MAX_VALUE) }));
} else {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed5", "PASSED [AS-EJB ejb] : refresh-period-in-seconds is {0}", new Object[] { new Long(refValue) }));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "NOT APPLICABLE [AS-EJB ejb] refresh-period-in-seconds Element not defined"));
}
if (oneFailed)
result.setStatus(Result.FAILED);
} catch (ClassNotFoundException cnfe) {
oneFailed = true;
} catch (RuntimeException ex) {
oneFailed = true;
}
if (oneFailed) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create a descriptor object"));
}
}
use of com.sun.enterprise.deployment.EjbMessageBeanDescriptor in project Payara by payara.
the class ASEjbBeanPool method check.
public Result check(EjbDescriptor descriptor) {
Result result = getInitializedResult();
ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
IASEjbExtraDescriptors ejbJar = descriptor.getIASEjbExtraDescriptors();
if (ejbJar != null) {
try {
beanPool = ejbJar.getBeanPool();
if (beanPool != null) {
if (descriptor instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) descriptor).getSessionType().equals(EjbSessionDescriptor.STATEFUL)) {
result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.warning(smh.getLocalString(getClass().getName() + ".warning", "WARNING [AS-EJB ejb] : bean-pool should be defined for Stateless Session Beans, Entity Beans or Message Driven Beans"));
} else if (descriptor instanceof EjbMessageBeanDescriptor || (descriptor instanceof EjbSessionDescriptor && ((EjbSessionDescriptor) descriptor).getSessionType().equals(EjbSessionDescriptor.STATELESS)) || descriptor instanceof EjbEntityDescriptor) {
result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-EJB ejb] : bean-pool is correctly defined"));
}
} else {
result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-EJB ejb] : bean-pool element not defined"));
}
return result;
} catch (Exception ex) {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create a beanPool object"));
}
} else {
result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notRun", "NOT RUN [AS-EJB] : Could not create an IASEjbExtraDescriptor object"));
}
return result;
}
use of com.sun.enterprise.deployment.EjbMessageBeanDescriptor in project Payara by payara.
the class InboundRecoveryHandler method recoverInboundTransactions.
private void recoverInboundTransactions(List<XAResource> xaresList) {
List<Application> applications = deployedApplications.getApplications();
try {
_logger.log(Level.INFO, "Recovery of Inbound Transactions started.");
if (applications.size() == 0) {
_logger.log(Level.FINE, "No applications deployed.");
return;
}
// List of CMT enabled MDB descriptors on the application server instance.
List<EjbDescriptor> xaEnabledMDBList = new ArrayList<EjbDescriptor>();
// Done so as to initialize connectors-runtime before loading inbound active RA. need a better way ?
ConnectorRuntime cr = connectorRuntimeProvider.get();
for (Application application : applications) {
Vector ejbDescVec = getEjbDescriptors(application, appsRegistry);
for (int j = 0; j < ejbDescVec.size(); j++) {
EjbDescriptor desc = (EjbDescriptor) ejbDescVec.elementAt(j);
// add it to the list of xaEnabledMDBList.
if (desc instanceof EjbMessageBeanDescriptor && desc.getTransactionType().equals(EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
xaEnabledMDBList.add(desc);
_logger.log(Level.FINE, "Found a CMT MDB: " + desc.getEjbClassName());
}
}
}
if (xaEnabledMDBList.size() == 0) {
_logger.log(Level.FINE, "Found no CMT MDBs in all applications");
return;
}
ConnectorRegistry creg = ConnectorRegistry.getInstance();
// for each RA (key in the map) get the list (value) of MDB Descriptors
Map<String, List<EjbDescriptor>> mappings = createRAEjbMapping(xaEnabledMDBList);
// For each RA
for (Map.Entry entry : mappings.entrySet()) {
String raMid = (String) entry.getKey();
List<EjbDescriptor> respectiveDesc = mappings.get(raMid);
try {
createActiveResourceAdapter(raMid);
} catch (Exception ex) {
_logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", raMid);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, ex.toString(), ex);
}
}
ActiveInboundResourceAdapter activeInboundRA = (ActiveInboundResourceAdapter) creg.getActiveResourceAdapter(raMid);
// assert activeInboundRA instanceof ActiveInboundResourceAdapter;
boolean isSystemJmsRA = false;
if (ConnectorsUtil.isJMSRA(activeInboundRA.getModuleName())) {
isSystemJmsRA = true;
}
javax.resource.spi.ResourceAdapter resourceAdapter = activeInboundRA.getResourceAdapter();
// activationSpecList represents the ActivationSpec[] that would be
// sent to the getXAResources() method.
ArrayList<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
try {
for (int i = 0; i < respectiveDesc.size(); i++) {
try {
// Get a MessageBeanDescriptor from respectiveDesc ArrayList
EjbMessageBeanDescriptor descriptor = (EjbMessageBeanDescriptor) respectiveDesc.get(i);
// to be updated J2EE 1.4 style props.
if (isSystemJmsRA) {
// XXX: Find out the pool descriptor corres to MDB and update
// MDBRuntimeInfo with that.
activeInboundRA.updateMDBRuntimeInfo(descriptor, null);
}
// Get the ActivationConfig Properties from the MDB Descriptor
Set activationConfigProps = RARUtils.getMergedActivationConfigProperties(descriptor);
// get message listener type
String msgListenerType = descriptor.getMessageListenerType();
// start resource adapter and get ActivationSpec class for
// the given message listener type from the ConnectorRuntime
ActivationSpec aspec = (ActivationSpec) (Class.forName(cr.getActivationSpecClass(raMid, msgListenerType), false, resourceAdapter.getClass().getClassLoader()).newInstance());
aspec.setResourceAdapter(resourceAdapter);
// Populate ActivationSpec class with ActivationConfig properties
SetMethodAction sma = new SetMethodAction(aspec, activationConfigProps);
sma.run();
activationSpecList.add(aspec);
} catch (Exception e) {
_logger.log(Level.WARNING, "error.creating.activationspec", e.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, e.toString(), e);
}
}
}
// Get XA resources from RA.
ActivationSpec[] activationSpecArray = activationSpecList.toArray(new ActivationSpec[activationSpecList.size()]);
XAResource[] xar = resourceAdapter.getXAResources(activationSpecArray);
// Add the resources to the xaresList which is used by the RecoveryManager
if (xar != null) {
for (int p = 0; p < xar.length; p++) {
xaresList.add(xar[p]);
}
}
// Catch UnsupportedOperationException if a RA does not support XA
// which is fine.
} catch (UnsupportedOperationException uoex) {
_logger.log(Level.FINE, uoex.getMessage());
// otherwise catch the unexpected exception
} catch (Exception e) {
_logger.log(Level.SEVERE, "exception.during.inbound.resource.acqusition", e);
}
}
} catch (Exception e) {
_logger.log(Level.SEVERE, "exception.during.inbound.recovery", e);
}
}
Aggregations