use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.
the class ConnectorMessageBeanClient method getActivationSpec.
private ActivationSpec getActivationSpec(ActiveInboundResourceAdapter aira, String activationSpecClassName) throws Exception {
ClassLoader cl = aira.getClassLoader();
Class aClass = cl.loadClass(activationSpecClassName);
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "classloader = " + aClass.getClassLoader());
logger.log(Level.FINEST, "classloader parent = " + aClass.getClassLoader().getParent());
}
ActivationSpec activationSpec = (ActivationSpec) aClass.newInstance();
Set props = ConnectorsUtil.getMergedActivationConfigProperties(getDescriptor());
AccessController.doPrivileged(new SetMethodAction(activationSpec, props));
return activationSpec;
}
use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.
the class ActiveJmsResourceAdapter method createManagedConnectionFactory.
/**
* Creates ManagedConnection Factory instance. For any property that is
* for supporting AS7 imq properties, resource adapter has a set method
* setProperty(String,String). All as7 properties starts with "imq".
* MQ Adapter supports this only for backward compatibility.
*
* @param cpr <code>ConnectorConnectionPool</code> object
* @param loader Class Loader.
* @return
*/
@Override
public ManagedConnectionFactory createManagedConnectionFactory(com.sun.enterprise.connectors.ConnectorConnectionPool cpr, ClassLoader loader) {
ManagedConnectionFactory mcf = super.createManagedConnectionFactory(cpr, loader);
if (mcf != null) {
Set s = cpr.getConnectorDescriptorInfo().getMCFConfigProperties();
Iterator it = s.iterator();
while (it.hasNext()) {
ConnectorConfigProperty prop = (ConnectorConfigProperty) it.next();
String propName = prop.getName();
// setProperty(String,String) method.
if (propName.startsWith("imq") && !"".equals(prop.getValue())) {
try {
Method meth = mcf.getClass().getMethod(SETTER, new Class[] { java.lang.String.class, java.lang.String.class });
meth.invoke(mcf, new Object[] { prop.getName(), prop.getValueObject() });
} catch (NoSuchMethodException ex) {
if (_logger.isLoggable(Level.WARNING)) {
_logger.log(Level.WARNING, JMSLoggerInfo.NO_SUCH_METHOD, new Object[] { SETTER, mcf.getClass().getName() });
}
} catch (Exception ex) {
LogHelper.log(_logger, Level.SEVERE, JMSLoggerInfo.ERROR_EXECUTE_METHOD, ex, SETTER, mcf.getClass().getName());
}
}
}
// CR 6591307- Fix for properties getting overridden when setRA is called. Resetting the properties if the RA is the JMS RA
String moduleName = this.getModuleName();
if (ConnectorAdminServiceUtils.isJMSRA(moduleName)) {
try {
Set configProperties = cpr.getConnectorDescriptorInfo().getMCFConfigProperties();
Object[] array = configProperties.toArray();
for (int i = 0; i < array.length; i++) {
if (array[i] instanceof ConnectorConfigProperty) {
ConnectorConfigProperty property = (ConnectorConfigProperty) array[i];
if (ActiveJmsResourceAdapter.ADDRESSLIST.equals(property.getName())) {
if (property.getValue() == null || "".equals(property.getValue()) || "localhost".equals(property.getValue())) {
_logger.log(Level.FINE, "raraddresslist.default.value : " + property.getValue());
configProperties.remove(property);
}
}
}
}
SetMethodAction setMethodAction = new SetMethodAction(mcf, configProperties);
setMethodAction.run();
} catch (Exception Ex) {
final String mcfClass = cpr.getConnectorDescriptorInfo().getManagedConnectionFactoryClass();
if (_logger.isLoggable(Level.WARNING)) {
_logger.log(Level.WARNING, JMSLoggerInfo.RARDEPLOYMENT_MCF_ERROR, new Object[] { mcfClass, Ex.getMessage() });
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "rardeployment.mcfcreation_error", Ex);
}
}
}
}
return mcf;
}
use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.
the class ActiveJmsResourceAdapter method createManagedConnectionFactories.
/**
* This is a temporay solution for obtaining all the MCFs
* corresponding to a JMS RA pool, this is to facilitate the
* recovery process where the XA resources of all RMs in the
* broker cluster are required. Should be removed when a permanent
* solutuion is available from the broker.
* @param cpr <code>ConnectorConnectionPool</code> object
* @param loader Class Loader.
* @return
*/
@Override
public ManagedConnectionFactory[] createManagedConnectionFactories(com.sun.enterprise.connectors.ConnectorConnectionPool cpr, ClassLoader loader) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "RECOVERY : Entering createMCFS in AJMSRA");
}
ArrayList mcfs = new ArrayList();
if (getAddressListCount() < 2) {
mcfs.add(createManagedConnectionFactory(cpr, loader));
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Brokers are not clustered,So doing normal recovery");
}
} else {
String addlist = null;
Set s = cpr.getConnectorDescriptorInfo().getMCFConfigProperties();
Iterator tmpit = s.iterator();
while (tmpit.hasNext()) {
ConnectorConfigProperty prop = (ConnectorConfigProperty) tmpit.next();
String propName = prop.getName();
if (propName.equalsIgnoreCase("imqAddressList") || propName.equalsIgnoreCase("Addresslist")) {
addlist = prop.getValue();
}
}
StringTokenizer tokenizer = null;
if ((addlist == null) || (addlist.trim().equalsIgnoreCase("localhost"))) {
tokenizer = new StringTokenizer(addressList, ",");
} else {
tokenizer = new StringTokenizer(addlist, ",");
}
_logger.log(Level.FINE, "No of addresses found " + tokenizer.countTokens());
while (tokenizer.hasMoreTokens()) {
String brokerurl = tokenizer.nextToken();
ManagedConnectionFactory mcf = super.createManagedConnectionFactory(cpr, loader);
Iterator it = s.iterator();
while (it.hasNext()) {
ConnectorConfigProperty prop = (ConnectorConfigProperty) it.next();
String propName = prop.getName();
String propValue = prop.getValue();
if (propName.startsWith("imq") && !"".equals(propValue)) {
try {
Method meth = mcf.getClass().getMethod(SETTER, new Class[] { java.lang.String.class, java.lang.String.class });
if (propName.trim().equalsIgnoreCase("imqAddressList")) {
meth.invoke(mcf, new Object[] { prop.getName(), brokerurl });
} else {
meth.invoke(mcf, new Object[] { prop.getName(), prop.getValueObject() });
}
} catch (NoSuchMethodException ex) {
if (_logger.isLoggable(Level.WARNING)) {
_logger.log(Level.WARNING, JMSLoggerInfo.NO_SUCH_METHOD, new Object[] { SETTER, mcf.getClass().getName() });
}
} catch (Exception ex) {
LogHelper.log(_logger, Level.SEVERE, JMSLoggerInfo.ERROR_EXECUTE_METHOD, ex, SETTER, mcf.getClass().getName());
}
}
}
ConnectorConfigProperty addressProp3 = new ConnectorConfigProperty(ADDRESSLIST, brokerurl, "Address List", "java.lang.String");
// todo: need to remove log statement
if (_logger.isLoggable(Level.INFO)) {
_logger.log(Level.INFO, JMSLoggerInfo.ADDRESSLIST, new Object[] { brokerurl });
}
HashSet addressProp = new HashSet();
addressProp.add(addressProp3);
SetMethodAction setMethodAction = new SetMethodAction(mcf, addressProp);
try {
setMethodAction.run();
} catch (Exception e) {
;
}
mcfs.add(mcf);
}
}
return (ManagedConnectionFactory[]) mcfs.toArray(new ManagedConnectionFactory[mcfs.size()]);
}
use of com.sun.enterprise.connectors.util.SetMethodAction 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);
}
}
use of com.sun.enterprise.connectors.util.SetMethodAction in project Payara by payara.
the class ActiveResourceAdapterImpl method createManagedConnectionFactory.
/**
* Creates managed Connection factory instance.
*
* @param ccp Connector connection pool which contains the pool properties
* and ra.xml values pertaining to managed connection factory
* class. These values are used in MCF creation.
* @param jcl Classloader used to managed connection factory class.
* @return ManagedConnectionFactory created managed connection factory
* instance
*/
public ManagedConnectionFactory createManagedConnectionFactory(ConnectorConnectionPool ccp, ClassLoader jcl) {
final String mcfClass = ccp.getConnectorDescriptorInfo().getManagedConnectionFactoryClass();
try {
ManagedConnectionFactory mcf = null;
mcf = instantiateMCF(mcfClass, jcl);
if (mcf instanceof ConfigurableTransactionSupport) {
TransactionSupport ts = ConnectionPoolObjectsUtils.getTransactionSupport(ccp.getTransactionSupport());
((ConfigurableTransactionSupport) mcf).setTransactionSupport(ts);
}
SetMethodAction setMethodAction = new SetMethodAction(mcf, ccp.getConnectorDescriptorInfo().getMCFConfigProperties());
setMethodAction.run();
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Created MCF object : ", mcfClass);
}
return mcf;
} catch (ClassNotFoundException Ex) {
_logger.log(Level.SEVERE, "rardeployment.class_not_found", new Object[] { mcfClass, Ex.getMessage() });
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "rardeployment.class_not_found", Ex);
}
return null;
} catch (InstantiationException Ex) {
_logger.log(Level.SEVERE, "rardeployment.class_instantiation_error", new Object[] { mcfClass, Ex.getMessage() });
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "rardeployment.class_instantiation_error", Ex);
}
return null;
} catch (IllegalAccessException Ex) {
_logger.log(Level.SEVERE, "rardeployment.illegalaccess_error", new Object[] { mcfClass, Ex.getMessage() });
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "rardeployment.illegalaccess_error", Ex);
}
return null;
} catch (Exception Ex) {
_logger.log(Level.SEVERE, "rardeployment.mcfcreation_error", new Object[] { mcfClass, Ex.getMessage() });
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "rardeployment.mcfcreation_error", Ex);
}
return null;
}
}
Aggregations