use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.
the class ConnectorDDTransformUtils method getConnectorDescriptor.
/**
* Get the ConnectorDescriptor object which represents the ra.xml and
* sun-ra.xml from an exploded rar module.
*
* @param moduleDir Directory where rar is exploded.
* @return ConnectorDescriptor object which
* represents the ra.xml and sun-ra.xml
* @throws ConnectorRuntimeException if ra.xml could not be located or
* invalid. For 1.0 type rar if sun-ra.xml is not present or
* invalid this exception is thrown. For 1.5 type rar sun-ra.xml
* should not be present.
*/
public static ConnectorDescriptor getConnectorDescriptor(String moduleDir, String rarModuleName) throws ConnectorRuntimeException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
File module = new File(moduleDir);
FileArchive fileArchive = new FileArchive();
// directory where rar is exploded
fileArchive.open(module.toURI());
ConnectorRuntime runtime = ConnectorRuntime.getRuntime();
ClassLoader loader;
if (ConnectorsUtil.belongsToSystemRA(rarModuleName)) {
loader = ConnectorRuntime.getRuntime().getSystemRARClassLoader(rarModuleName);
Thread.currentThread().setContextClassLoader(loader);
} else {
loader = runtime.createConnectorClassLoader(moduleDir, null, rarModuleName);
}
ConnectorArchivist connectorArchivist = runtime.getConnectorArchvist();
// TODO V3 what happens to embedded .rar ? as its parent classloader should be application CL
// setting the classloader so that annotation processor can make use of it.
connectorArchivist.setClassLoader(loader);
// fileArchive.entries("META-INF/ra.xml");
// TODO V3 need to check whether ra.xml is present, if so, check the version. process annotations
// only if its 1.6 or above ?
connectorArchivist.setAnnotationProcessingRequested(true);
return connectorArchivist.open(fileArchive);
} catch (IOException ex) {
ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to read the connector deployment descriptors");
cre.initCause(ex);
_logger.log(Level.SEVERE, "rardeployment.connector_descriptor_read_error", moduleDir);
_logger.log(Level.SEVERE, "", cre);
throw cre;
} catch (SAXParseException ex) {
ConnectorRuntimeException cre = new ConnectorRuntimeException("Failed to parse the connector deployment descriptors");
cre.initCause(ex);
_logger.log(Level.SEVERE, "rardeployment.connector_descriptor_parse_error", moduleDir);
_logger.log(Level.SEVERE, "", cre);
throw cre;
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.
the class ResourceAdapterConfigDeployer method undeployResource.
/**
* {@inheritDoc}
*/
public synchronized void undeployResource(Object resource) throws Exception {
ResourceAdapterConfig domainConfig = (ResourceAdapterConfig) resource;
String rarName = domainConfig.getResourceAdapterName();
ConnectorRuntime crt = getConnectorRuntime();
crt.deleteResourceAdapterConfig(rarName);
}
use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.
the class ResourceAdapterConfigDeployer method deployResource.
/**
* {@inheritDoc}
*/
public synchronized void deployResource(Object resource) throws Exception {
ResourceAdapterConfig domainConfig = (ResourceAdapterConfig) resource;
String rarName = domainConfig.getResourceAdapterName();
ConnectorRuntime crt = getConnectorRuntime();
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Calling backend to add resource adapterConfig ", rarName);
}
crt.addResourceAdapterConfig(rarName, domainConfig);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Added resource adapterConfig in backend", rarName);
}
}
use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.
the class AdministeredObjectFactory method getObjectInstance.
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable env) throws Exception {
Reference ref = (Reference) obj;
if (logger.isLoggable(Level.FINE)) {
logger.fine("AdministeredObjectFactory: " + ref + " Name:" + name);
}
AdministeredObjectResource aor = (AdministeredObjectResource) ref.get(0).getContent();
String moduleName = aor.getResourceAdapter();
// If call fom application client, start resource adapter lazily.
// todo: Similar code in ConnectorObjectFactory - to refactor.
ConnectorRuntime runtime = ConnectorNamingUtils.getRuntime();
if (runtime.isACCRuntime() || runtime.isNonACCRuntime()) {
ConnectorDescriptor connectorDescriptor = null;
try {
Context ic = new InitialContext();
String descriptorJNDIName = ConnectorAdminServiceUtils.getReservePrefixedJNDINameForDescriptor(moduleName);
connectorDescriptor = (ConnectorDescriptor) ic.lookup(descriptorJNDIName);
} catch (NamingException ne) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Failed to look up ConnectorDescriptor " + "from JNDI", moduleName);
}
throw new ConnectorRuntimeException("Failed to look up " + "ConnectorDescriptor from JNDI");
}
runtime.createActiveResourceAdapter(connectorDescriptor, moduleName, null);
}
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (runtime.checkAccessibility(moduleName, loader) == false) {
throw new NamingException("Only the application that has the embedded resource" + "adapter can access the resource adapter");
}
if (logger.isLoggable(Level.FINE)) {
logger.fine("[AdministeredObjectFactory] ==> Got AdministeredObjectResource = " + aor);
}
// all RARs except system RARs should have been available now.
if (ConnectorsUtil.belongsToSystemRA(moduleName)) {
// make sure that system rar is started and hence added to connector classloader chain
if (ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName) == null) {
String moduleLocation = ConnectorsUtil.getSystemModuleLocation(moduleName);
runtime.createActiveResourceAdapter(moduleLocation, moduleName, null);
}
loader = ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName).getClassLoader();
} else if (runtime.isServer()) {
if (ConnectorsUtil.isStandAloneRA(moduleName)) {
loader = ConnectorRegistry.getInstance().getActiveResourceAdapter(moduleName).getClassLoader();
}
}
return aor.createAdministeredObject(loader);
}
use of com.sun.enterprise.connectors.ConnectorRuntime in project Payara by payara.
the class ConnectorsRecoveryResourceHandler method createActiveResourceAdapter.
private void createActiveResourceAdapter(String rarModuleName) throws ConnectorRuntimeException {
ConnectorRuntime cr = ConnectorRuntime.getRuntime();
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);
}
}
Aggregations