use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class ExpressionFilterDefinition method createHttpHandler.
@Override
public HttpHandler createHttpHandler(Predicate predicate, ModelNode model, HttpHandler next) {
String expression = model.get(EXPRESSION.getName()).asString();
String moduleName = null;
if (model.hasDefined(MODULE.getName())) {
moduleName = model.get(MODULE.getName()).asString();
}
ClassLoader classLoader;
if (moduleName == null) {
classLoader = getClass().getClassLoader();
} else {
try {
ModuleLoader moduleLoader = Module.getBootModuleLoader();
Module filterModule = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName));
classLoader = filterModule.getClassLoader();
} catch (ModuleLoadException e) {
throw UndertowLogger.ROOT_LOGGER.couldNotLoadHandlerFromModule(expression, moduleName, e);
}
}
List<PredicatedHandler> handlers = PredicatedHandlersParser.parse(expression, classLoader);
UndertowLogger.ROOT_LOGGER.debugf("Creating http handler %s from module %s", expression, moduleName);
if (predicate != null) {
return Handlers.predicate(predicate, Handlers.predicates(handlers, next), next);
} else {
return Handlers.predicates(handlers, next);
}
}
use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class ExternalTldParsingDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
if (warMetaData == null || warMetaData.getMergedJBossWebMetaData() == null) {
return;
}
TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
Map<String, TldMetaData> tlds = tldsMetaData.getTlds();
Set<String> sharedTldUris = new HashSet<>();
for (TldMetaData shared : tldsMetaData.getSharedTlds(deploymentUnit)) {
sharedTldUris.add(shared.getUri());
}
Module module = deploymentUnit.getAttachment(Attachments.MODULE);
try {
Iterator<Resource> resources = module.globResources("META-INF/**.tld");
while (resources.hasNext()) {
final Resource resource = resources.next();
// waste time re-parsing them
if (resource.getURL().toString().contains("com/sun/jsf-impl/main")) {
continue;
}
if (resource.getName().startsWith("META-INF/")) {
if (tlds.containsKey(resource.getName())) {
continue;
}
if (resource.getURL().getProtocol().equals("vfs")) {
continue;
}
final TldMetaData value = parseTLD(resource);
if (sharedTldUris.contains(value.getUri())) {
// don't re-include shared TLD's
continue;
}
String key = "/" + resource.getName();
if (!tlds.containsKey(key)) {
tlds.put(key, value);
}
if (!tlds.containsKey(value.getUri())) {
tlds.put(value.getUri(), value);
}
if (value.getListeners() != null) {
for (ListenerMetaData l : value.getListeners()) {
List<ListenerMetaData> listeners = warMetaData.getMergedJBossWebMetaData().getListeners();
if (listeners == null) {
warMetaData.getMergedJBossWebMetaData().setListeners(listeners = new ArrayList<ListenerMetaData>());
}
listeners.add(l);
}
}
}
}
} catch (ModuleLoadException e) {
throw new DeploymentUnitProcessingException(e);
}
}
use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class ClientInterceptorCache method loadClientInterceptors.
private void loadClientInterceptors() {
clientInterceptors = new ArrayList<>();
for (final ServerInterceptorMetaData si : serverInterceptorMetaData) {
final Class<? extends EJBClientInterceptor> interceptorClass;
final ModuleIdentifier moduleId = ModuleIdentifier.create(si.getModule());
try {
final Module module = Module.getCallerModuleLoader().loadModule(moduleId);
clientInterceptors.add(ClassLoadingUtils.loadClass(si.getClazz(), module).asSubclass(EJBClientInterceptor.class));
} catch (ModuleLoadException e) {
throw EjbLogger.ROOT_LOGGER.cannotLoadServerInterceptorModule(moduleId, e);
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, si.getClazz());
}
}
}
use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.
the class ServerInterceptorCache method loadServerInterceptors.
private void loadServerInterceptors() {
serverInterceptorsAroundInvoke = new ArrayList<>();
serverInterceptorsAroundTimeout = new ArrayList<>();
for (final ServerInterceptorMetaData si : serverInterceptorMetaData) {
final Class<?> interceptorClass;
final ModuleIdentifier moduleId = ModuleIdentifier.create(si.getModule());
try {
final Module module = Module.getCallerModuleLoader().loadModule(moduleId);
interceptorClass = ClassLoadingUtils.loadClass(si.getClazz(), module);
} catch (ModuleLoadException e) {
throw EjbLogger.ROOT_LOGGER.cannotLoadServerInterceptorModule(moduleId, e);
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, si.getClazz());
}
final Index index = buildIndexForClass(interceptorClass);
serverInterceptorsAroundInvoke.addAll(findAnnotatedMethods(interceptorClass, index, AroundInvoke.class));
serverInterceptorsAroundTimeout.addAll(findAnnotatedMethods(interceptorClass, index, AroundTimeout.class));
}
}
use of org.jboss.modules.ModuleLoadException 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));
}
}
}
Aggregations