use of org.jboss.modules.ModuleNotFoundException in project wildfly by wildfly.
the class RaOperationUtil method installRaServicesAndDeployFromModule.
public static void installRaServicesAndDeployFromModule(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, String fullModuleName, final List<ServiceController<?>> newControllers) throws OperationFailedException {
ServiceName raServiceName = installRaServices(context, name, resourceAdapter, newControllers);
final boolean resolveProperties = true;
final ServiceTarget serviceTarget = context.getServiceTarget();
final String moduleName;
final CapabilityServiceSupport support = context.getCapabilityServiceSupport();
// load module
String slot = "main";
if (fullModuleName.contains(":")) {
slot = fullModuleName.substring(fullModuleName.indexOf(":") + 1);
moduleName = fullModuleName.substring(0, fullModuleName.indexOf(":"));
} else {
moduleName = fullModuleName;
}
Module module;
try {
ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleNotFoundException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.raModuleNotFound(moduleName, e.getMessage()), e);
} catch (ModuleLoadException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
}
URL path = module.getExportedResource("META-INF/ra.xml");
Closeable closable = null;
try {
VirtualFile child;
if (path.getPath().contains("!")) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.compressedRarNotSupportedInModuleRA(moduleName));
} else {
child = VFS.getChild(path.getPath().split("META-INF")[0]);
closable = VFS.mountReal(new File(path.getPath().split("META-INF")[0]), child);
}
// final Closeable closable = VFS.mountZip((InputStream) new JarInputStream(new FileInputStream(path.getPath().split("!")[0].split(":")[1])), path.getPath().split("!")[0].split(":")[1], child, TempFileProviderService.provider());
final MountHandle mountHandle = new MountHandle(closable);
final ResourceRoot resourceRoot = new ResourceRoot(child, mountHandle);
final VirtualFile deploymentRoot = resourceRoot.getRoot();
if (deploymentRoot == null || !deploymentRoot.exists())
return;
ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolveProperties, deploymentRoot, null, name);
IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRoot, resolveProperties);
RaNativeProcessor.process(deploymentRoot);
Map<ResourceRoot, Index> annotationIndexes = new HashMap<ResourceRoot, Index>();
ResourceRootIndexer.indexResourceRoot(resourceRoot);
Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
if (index != null) {
annotationIndexes.put(resourceRoot, index);
}
if (ironJacamarXmlDescriptor != null) {
ConnectorLogger.SUBSYSTEM_RA_LOGGER.forceIJToNull();
ironJacamarXmlDescriptor = null;
}
final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName);
if (deployerService == null) {
ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptor, ironJacamarXmlDescriptor, module.getClassLoader(), serviceTarget, annotationIndexes, RAR_MODULE.append(name), null, null, support);
builder.requires(raServiceName);
newControllers.add(builder.setInitialMode(ServiceController.Mode.ACTIVE).install());
}
String rarName = resourceAdapter.getArchive();
if (fullModuleName.equals(rarName)) {
ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(name);
InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, name, name, RAR_MODULE.append(name), null, serviceTarget, null);
newControllers.add(serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
} catch (Exception e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
} finally {
if (closable != null) {
try {
closable.close();
} catch (IOException e) {
}
}
}
}
use of org.jboss.modules.ModuleNotFoundException in project wildfly by wildfly.
the class NamingBindingAdd method createObjectFactory.
private ObjectFactory createObjectFactory(OperationContext context, ModelNode model) throws OperationFailedException {
final ModuleIdentifier moduleID = ModuleIdentifier.fromString(NamingBindingResourceDefinition.MODULE.resolveModelAttribute(context, model).asString());
final String className = NamingBindingResourceDefinition.CLASS.resolveModelAttribute(context, model).asString();
final Module module;
try {
module = Module.getBootModuleLoader().loadModule(moduleID);
} catch (ModuleNotFoundException e) {
throw NamingLogger.ROOT_LOGGER.moduleNotFound(moduleID, e.getMessage());
} catch (ModuleLoadException e) {
throw NamingLogger.ROOT_LOGGER.couldNotLoadModule(moduleID);
}
final ObjectFactory objectFactoryClassInstance;
final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
final Class<?> clazz = module.getClassLoader().loadClass(className);
objectFactoryClassInstance = (ObjectFactory) clazz.newInstance();
} catch (ClassNotFoundException e) {
throw NamingLogger.ROOT_LOGGER.couldNotLoadClassFromModule(className, moduleID);
} catch (InstantiationException e) {
throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
} catch (IllegalAccessException e) {
throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
} catch (ClassCastException e) {
throw NamingLogger.ROOT_LOGGER.notAnInstanceOfObjectFactory(className, moduleID);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
}
return objectFactoryClassInstance;
}
use of org.jboss.modules.ModuleNotFoundException in project wildfly by wildfly.
the class JMSBridgeAdd method createJMSBridge.
private JMSBridge createJMSBridge(OperationContext context, ModelNode model) throws OperationFailedException {
final Properties sourceContextProperties = resolveContextProperties(JMSBridgeDefinition.SOURCE_CONTEXT, context, model);
final String sourceConnectionFactoryName = JMSBridgeDefinition.SOURCE_CONNECTION_FACTORY.resolveModelAttribute(context, model).asString();
final ConnectionFactoryFactory sourceCff = new JNDIConnectionFactoryFactory(sourceContextProperties, sourceConnectionFactoryName);
final String sourceDestinationName = JMSBridgeDefinition.SOURCE_DESTINATION.resolveModelAttribute(context, model).asString();
final DestinationFactory sourceDestinationFactory = new JNDIDestinationFactory(sourceContextProperties, sourceDestinationName);
final Properties targetContextProperties = resolveContextProperties(JMSBridgeDefinition.TARGET_CONTEXT, context, model);
final String targetConnectionFactoryName = JMSBridgeDefinition.TARGET_CONNECTION_FACTORY.resolveModelAttribute(context, model).asString();
final ConnectionFactoryFactory targetCff = new JNDIConnectionFactoryFactory(targetContextProperties, targetConnectionFactoryName);
final String targetDestinationName = JMSBridgeDefinition.TARGET_DESTINATION.resolveModelAttribute(context, model).asString();
final DestinationFactory targetDestinationFactory = new JNDIDestinationFactory(targetContextProperties, targetDestinationName);
final String sourceUsername = resolveAttribute(JMSBridgeDefinition.SOURCE_USER, context, model);
final String sourcePassword = resolveAttribute(JMSBridgeDefinition.SOURCE_PASSWORD, context, model);
final String targetUsername = resolveAttribute(JMSBridgeDefinition.TARGET_USER, context, model);
final String targetPassword = resolveAttribute(JMSBridgeDefinition.TARGET_PASSWORD, context, model);
final String selector = resolveAttribute(CommonAttributes.SELECTOR, context, model);
final long failureRetryInterval = JMSBridgeDefinition.FAILURE_RETRY_INTERVAL.resolveModelAttribute(context, model).asLong();
final int maxRetries = JMSBridgeDefinition.MAX_RETRIES.resolveModelAttribute(context, model).asInt();
final QualityOfServiceMode qosMode = QualityOfServiceMode.valueOf(JMSBridgeDefinition.QUALITY_OF_SERVICE.resolveModelAttribute(context, model).asString());
final int maxBatchSize = JMSBridgeDefinition.MAX_BATCH_SIZE.resolveModelAttribute(context, model).asInt();
final long maxBatchTime = JMSBridgeDefinition.MAX_BATCH_TIME.resolveModelAttribute(context, model).asLong();
final String subName = resolveAttribute(JMSBridgeDefinition.SUBSCRIPTION_NAME, context, model);
final String clientID = resolveAttribute(JMSBridgeDefinition.CLIENT_ID, context, model);
final boolean addMessageIDInHeader = JMSBridgeDefinition.ADD_MESSAGE_ID_IN_HEADER.resolveModelAttribute(context, model).asBoolean();
final String moduleName = resolveAttribute(JMSBridgeDefinition.MODULE, context, model);
final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
// will use the correct class loader to execute its threads
if (moduleName != null) {
Module module = Module.getCallerModuleLoader().loadModule(ModuleIdentifier.fromString(moduleName));
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
}
return new JMSBridgeImpl(sourceCff, targetCff, sourceDestinationFactory, targetDestinationFactory, sourceUsername, sourcePassword, targetUsername, targetPassword, selector, failureRetryInterval, maxRetries, qosMode, maxBatchSize, maxBatchTime, subName, clientID, addMessageIDInHeader).setBridgeName(context.getCurrentAddressValue());
} catch (ModuleNotFoundException e) {
throw MessagingLogger.ROOT_LOGGER.moduleNotFound(moduleName, e.getMessage(), e);
} catch (ModuleLoadException e) {
throw MessagingLogger.ROOT_LOGGER.unableToLoadModule(moduleName, e);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
}
use of org.jboss.modules.ModuleNotFoundException in project wildfly by wildfly.
the class JdbcDriverAdd method performRuntime.
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final ModelNode address = operation.require(OP_ADDR);
final String driverName = PathAddress.pathAddress(address).getLastElement().getValue();
if (operation.get(DRIVER_NAME.getName()).isDefined() && !driverName.equals(operation.get(DRIVER_NAME.getName()).asString())) {
throw ConnectorLogger.ROOT_LOGGER.driverNameAndResourceNameNotEquals(operation.get(DRIVER_NAME.getName()).asString(), driverName);
}
String moduleName = DRIVER_MODULE_NAME.resolveModelAttribute(context, model).asString();
final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? DRIVER_MAJOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? DRIVER_MINOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? DRIVER_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_XA_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
final ServiceTarget target = context.getServiceTarget();
final ModuleIdentifier moduleId;
final Module module;
String slot = model.hasDefined(MODULE_SLOT.getName()) ? MODULE_SLOT.resolveModelAttribute(context, model).asString() : null;
try {
moduleId = ModuleIdentifier.create(moduleName, slot);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleNotFoundException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage()), e);
} catch (ModuleLoadException e) {
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName), e);
}
if (dataSourceClassName != null) {
Class<? extends DataSource> dsCls;
try {
dsCls = module.getClassLoader().loadClass(dataSourceClassName).asSubclass(DataSource.class);
} catch (ClassNotFoundException e) {
throw SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(dataSourceClassName, e);
} catch (ClassCastException e) {
throw SUBSYSTEM_DATASOURCES_LOGGER.notAValidDataSourceClass(dataSourceClassName, DataSource.class.getName());
}
checkDSCls(dsCls, DataSource.class);
}
if (xaDataSourceClassName != null) {
Class<? extends XADataSource> dsCls;
try {
dsCls = module.getClassLoader().loadClass(xaDataSourceClassName).asSubclass(XADataSource.class);
} catch (ClassNotFoundException e) {
throw SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(xaDataSourceClassName, e);
} catch (ClassCastException e) {
throw SUBSYSTEM_DATASOURCES_LOGGER.notAValidDataSourceClass(dataSourceClassName, DataSource.class.getName());
}
checkDSCls(dsCls, XADataSource.class);
}
if (driverClassName == null) {
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
boolean driverLoaded = false;
if (serviceLoader != null) {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(module.getClassLoader());
try {
for (Driver driver : serviceLoader) {
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
driverLoaded = true;
// w/ explicit declaration of driver-class attribute
break;
}
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
if (!driverLoaded)
SUBSYSTEM_DATASOURCES_LOGGER.cannotFindDriverClassName(driverName);
} else {
try {
final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Driver driver = null;
try {
Thread.currentThread().setContextClassLoader(module.getClassLoader());
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
driver = constructor.newInstance();
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
} catch (Exception e) {
SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.cannotInstantiateDriverClass(driverClassName));
}
}
}
use of org.jboss.modules.ModuleNotFoundException in project wildfly by wildfly.
the class JdbcDriverRemove method recoverServices.
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) {
final String driverName = model.require(DRIVER_NAME.getName()).asString();
final String moduleName = model.require(DRIVER_MODULE_NAME.getName()).asString();
final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? model.get(DRIVER_MAJOR_VERSION.getName()).asInt() : null;
final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? model.get(DRIVER_MINOR_VERSION.getName()).asInt() : null;
final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? model.get(DRIVER_CLASS_NAME.getName()).asString() : null;
final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).asString() : null;
final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).asString() : null;
final ServiceTarget target = context.getServiceTarget();
final ModuleIdentifier moduleId;
final Module module;
try {
moduleId = ModuleIdentifier.fromString(moduleName);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleNotFoundException e) {
context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage()));
return;
} catch (ModuleLoadException e) {
context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName));
return;
}
if (driverClassName == null) {
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
if (serviceLoader != null)
for (Driver driver : serviceLoader) {
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
}
} else {
try {
final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
final Driver driver = constructor.newInstance();
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
} catch (Exception e) {
SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
}
}
}
Aggregations