use of com.sun.appserv.connectors.internal.api.ConnectorRuntime in project Payara by payara.
the class InboundRecoveryHandler method createActiveResourceAdapter.
private void createActiveResourceAdapter(String rarModuleName) throws ConnectorRuntimeException {
ConnectorRuntime cr = connectorRuntimeProvider.get();
ConnectorRegistry creg = ConnectorRegistry.getInstance();
if (creg.isRegistered(rarModuleName))
return;
if (ConnectorAdminServiceUtils.isEmbeddedConnectorModule(rarModuleName)) {
cr.createActiveResourceAdapterForEmbeddedRar(rarModuleName);
} else {
String moduleDir;
if (ConnectorsUtil.belongsToSystemRA(rarModuleName)) {
moduleDir = ConnectorsUtil.getSystemModuleLocation(rarModuleName);
} else {
moduleDir = configBeansUtilities.getLocation(rarModuleName);
}
ClassLoader loader = cr.createConnectorClassLoader(moduleDir, null, rarModuleName);
cr.createActiveResourceAdapter(moduleDir, rarModuleName, loader);
}
}
use of com.sun.appserv.connectors.internal.api.ConnectorRuntime 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.appserv.connectors.internal.api.ConnectorRuntime in project Payara by payara.
the class JDBCRealm method init.
/**
* Initialize a realm with some properties. This can be used when instantiating realms from their descriptions. This
* method may only be called a single time.
*
* @param props
* Initialization parameters used by this realm.
* @exception BadRealmException
* If the configuration parameters identify a corrupt realm.
* @exception NoSuchRealmException
* If the configuration parameters specify a realm which doesn't exist.
*/
@SuppressWarnings("unchecked")
public synchronized void init(Properties props) throws BadRealmException, NoSuchRealmException {
super.init(props);
String jaasCtx = props.getProperty(IASRealm.JAAS_CONTEXT_PARAM);
String dbUser = props.getProperty(PARAM_DB_USER);
String dbPassword = props.getProperty(PARAM_DB_PASSWORD);
String dsJndi = props.getProperty(PARAM_DATASOURCE_JNDI);
String digestAlgorithm = props.getProperty(PARAM_DIGEST_ALGORITHM, getDefaultDigestAlgorithm());
String encoding = props.getProperty(PARAM_ENCODING);
String charset = props.getProperty(PARAM_CHARSET);
String userTable = props.getProperty(PARAM_USER_TABLE);
String userNameColumn = props.getProperty(PARAM_USER_NAME_COLUMN);
String passwordColumn = props.getProperty(PARAM_PASSWORD_COLUMN);
String groupTable = props.getProperty(PARAM_GROUP_TABLE);
String groupNameColumn = props.getProperty(PARAM_GROUP_NAME_COLUMN);
String groupTableUserNameColumn = props.getProperty(PARAM_GROUP_TABLE_USER_NAME_COLUMN, userNameColumn);
cr = (ActiveDescriptor<ConnectorRuntime>) Util.getDefaultHabitat().getBestDescriptor(BuilderHelper.createContractFilter(ConnectorRuntime.class.getName()));
if (jaasCtx == null) {
throw new BadRealmException(sm.getString("realm.missingprop", IASRealm.JAAS_CONTEXT_PARAM, "JDBCRealm"));
}
if (dsJndi == null) {
throw new BadRealmException(sm.getString("realm.missingprop", PARAM_DATASOURCE_JNDI, "JDBCRealm"));
}
if (userTable == null) {
throw new BadRealmException(sm.getString("realm.missingprop", PARAM_USER_TABLE, "JDBCRealm"));
}
if (groupTable == null) {
throw new BadRealmException(sm.getString("realm.missingprop", PARAM_GROUP_TABLE, "JDBCRealm"));
}
if (userNameColumn == null) {
throw new BadRealmException(sm.getString("realm.missingprop", PARAM_USER_NAME_COLUMN, "JDBCRealm"));
}
if (passwordColumn == null) {
throw new BadRealmException(sm.getString("realm.missingprop", PARAM_PASSWORD_COLUMN, "JDBCRealm"));
}
if (groupNameColumn == null) {
throw new BadRealmException(sm.getString("realm.missingprop", PARAM_GROUP_NAME_COLUMN, "JDBCRealm"));
}
passwordQuery = "SELECT " + passwordColumn + " FROM " + userTable + " WHERE " + userNameColumn + " = ?";
groupQuery = "SELECT " + groupNameColumn + " FROM " + groupTable + " WHERE " + groupTableUserNameColumn + " = ? ";
if (!NONE.equalsIgnoreCase(digestAlgorithm)) {
try {
md = MessageDigest.getInstance(digestAlgorithm);
} catch (NoSuchAlgorithmException e) {
throw new BadRealmException(sm.getString("jdbcrealm.notsupportdigestalg", digestAlgorithm));
}
}
if (md != null && encoding == null) {
encoding = DEFAULT_ENCODING;
}
this.setProperty(IASRealm.JAAS_CONTEXT_PARAM, jaasCtx);
if (dbUser != null && dbPassword != null) {
this.setProperty(PARAM_DB_USER, dbUser);
this.setProperty(PARAM_DB_PASSWORD, dbPassword);
}
this.setProperty(PARAM_DATASOURCE_JNDI, dsJndi);
this.setProperty(PARAM_DIGEST_ALGORITHM, digestAlgorithm);
if (encoding != null) {
this.setProperty(PARAM_ENCODING, encoding);
}
if (charset != null) {
this.setProperty(PARAM_CHARSET, charset);
}
if (_logger.isLoggable(Level.FINEST)) {
_logger.finest("JDBCRealm : " + IASRealm.JAAS_CONTEXT_PARAM + "= " + jaasCtx + ", " + PARAM_DATASOURCE_JNDI + " = " + dsJndi + ", " + PARAM_DB_USER + " = " + dbUser + ", " + PARAM_DIGEST_ALGORITHM + " = " + digestAlgorithm + ", " + PARAM_ENCODING + " = " + encoding + ", " + PARAM_CHARSET + " = " + charset);
}
groupCache = new HashMap<String, Vector>();
emptyVector = new Vector<String>();
}
use of com.sun.appserv.connectors.internal.api.ConnectorRuntime in project Payara by payara.
the class JDBCRealm method getConnection.
/**
* Return a connection from the properties configured
*
* @return a connection
*/
private Connection getConnection() throws LoginException {
final String dsJndi = this.getProperty(PARAM_DATASOURCE_JNDI);
final String dbUser = this.getProperty(PARAM_DB_USER);
final String dbPassword = this.getProperty(PARAM_DB_PASSWORD);
try {
ConnectorRuntime connectorRuntime = Util.getDefaultHabitat().getServiceHandle(cr).getService();
final DataSource dataSource = (DataSource) connectorRuntime.lookupNonTxResource(dsJndi, false);
Connection connection = null;
if (dbUser != null && dbPassword != null) {
connection = dataSource.getConnection(dbUser, dbPassword);
} else {
connection = dataSource.getConnection();
}
return connection;
} catch (Exception ex) {
LoginException loginEx = new LoginException(sm.getString("jdbcrealm.cantconnect", dsJndi, dbUser));
loginEx.initCause(ex);
throw loginEx;
}
}
use of com.sun.appserv.connectors.internal.api.ConnectorRuntime in project Payara by payara.
the class DeploymentHelper method getConnection.
/**
* Get a Connection from the resource specified by the JNDI name
* of a CMP resource.
* This connection is aquired from a non-transactional resource which does not
* go through transaction enlistment/delistment.
* The deployment processing is required to use only those connections.
*
* @param name JNDI name of a cmp-resource for the connection.
* @return a Connection.
* @throws JDOFatalUserException if name cannot be looked up, or we
* cannot get a connection based on the name.
* @throws SQLException if can not get a Connection.
*/
public static Connection getConnection(String name) throws SQLException {
if (logger.isLoggable(logger.FINE)) {
// NOI18N
logger.fine("ejb.DeploymentHelper.getconnection", name);
}
// TODO - pass Habitat or ConnectorRuntime as an argument.
ServiceLocator habitat = Globals.getDefaultHabitat();
DataSource ds = null;
try {
ConnectorRuntime connectorRuntime = habitat.getService(ConnectorRuntime.class);
ds = DataSource.class.cast(connectorRuntime.lookupNonTxResource(name, true));
} catch (Exception e) {
throw new JDOFatalUserException(I18NHelper.getMessage(messages, "ejb.jndi.lookupfailed", // NOI18N
name));
}
return ds.getConnection();
}
Aggregations