boolean copyConnectionLibraries, File tmpDir) throws Exception {
if (connection == null) {
try {
//Configuration pluginConfig = this.resourceContext.getPluginConfiguration();
ConnectionSettings connectionSettings = new ConnectionSettings();
String connectionTypeDescriptorClass = pluginConfig.getSimple(CONNECTOR_DESCRIPTOR_TYPE)
.getStringValue();
PropertySimple serverUrl = pluginConfig.getSimple(CONNECTOR_ADDRESS);
connectionSettings.initializeConnectionType((ConnectionTypeDescriptor) Class.forName(
connectionTypeDescriptorClass).newInstance());
// if not provided use the default serverUrl
if (null != serverUrl) {
connectionSettings.setServerUrl(serverUrl.getStringValue());
}
connectionSettings.setPrincipal(pluginConfig.getSimpleValue(CONNECTOR_PRINCIPAL, null));
connectionSettings.setCredentials(pluginConfig.getSimpleValue(CONNECTOR_CREDENTIALS, null));
connectionSettings.setLibraryURI(pluginConfig.getSimpleValue(JBOSS_HOME_DIR, null));
if (connectionSettings.getAdvancedProperties() == null) {
connectionSettings.setAdvancedProperties(new Properties());
}
connectionSettings.getAdvancedProperties().setProperty(ConnectionFactory.USE_CONTEXT_CLASSLOADER,
"true");
connectionSettings.getAdvancedProperties().setProperty(JNP_DISABLE_DISCOVERY_JNP_INIT_PROP, "true");
// Make sure the timeout always happens, even if the JBoss server is hung.
connectionSettings.getAdvancedProperties().setProperty("jnp.timeout", String.valueOf(JNP_TIMEOUT));
connectionSettings.getAdvancedProperties().setProperty("jnp.sotimeout", String.valueOf(JNP_SO_TIMEOUT));
// Tell EMS "don't bother creating your own classloader, I (the caller of EMS) already created
// an isolated classloader for you, with all necessary jars - just use the context classloader
// and don't bother creating a new one for yourself"
connectionSettings.getAdvancedProperties().setProperty(ConnectionFactory.USE_CONTEXT_CLASSLOADER,
Boolean.TRUE.toString());
if (copyConnectionLibraries) {
// Tell EMS to make copies of jar files so that the ems classloader doesn't lock
// application files (making us unable to update them) Bug: JBNADM-670
connectionSettings.getControlProperties().setProperty(ConnectionFactory.COPY_JARS_TO_TEMP,
String.valueOf(Boolean.TRUE));
}
// Tell EMS to use the plugin's temp dir, so the PC will be able to clean it up and so an access control
// policy can easily be defined for the dir. EMS will use this for connection libraries (i.e. client
// jars) if COPY_JARS control prop is true, but it will also use it for the ems-mpl jar no matter what,
// so we need to always set it.
connectionSettings.getControlProperties().setProperty(ConnectionFactory.JAR_TEMP_DIR,
tmpDir.getAbsolutePath());
connectionSettings.getAdvancedProperties().setProperty(InternalVMTypeDescriptor.DEFAULT_DOMAIN_SEARCH,
"jboss");
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.discoverServerClasses(connectionSettings);