Search in sources :

Example 36 with ModuleLoadException

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);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleLoader(org.jboss.modules.ModuleLoader) PredicatedHandler(io.undertow.server.handlers.builder.PredicatedHandler) Module(org.jboss.modules.Module)

Example 37 with ModuleLoadException

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);
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) WarMetaData(org.jboss.as.web.common.WarMetaData) Resource(org.jboss.modules.Resource) ArrayList(java.util.ArrayList) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet)

Example 38 with ModuleLoadException

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());
        }
    }
}
Also used : EJBClientInterceptor(org.jboss.ejb.client.EJBClientInterceptor) ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module)

Example 39 with ModuleLoadException

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));
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) Index(org.jboss.jandex.Index) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) AroundTimeout(javax.interceptor.AroundTimeout) Module(org.jboss.modules.Module) AroundInvoke(javax.interceptor.AroundInvoke)

Example 40 with ModuleLoadException

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));
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) XADataSource(javax.sql.XADataSource) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) Driver(java.sql.Driver) ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) OperationFailedException(org.jboss.as.controller.OperationFailedException) XADataSource(javax.sql.XADataSource) DataSource(javax.sql.DataSource) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) ModelNode(org.jboss.dmr.ModelNode) Module(org.jboss.modules.Module)

Aggregations

ModuleLoadException (org.jboss.modules.ModuleLoadException)62 Module (org.jboss.modules.Module)30 IOException (java.io.IOException)17 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)13 ModuleSpec (org.jboss.modules.ModuleSpec)12 ModuleLoader (org.jboss.modules.ModuleLoader)10 Test (org.junit.Test)9 URL (java.net.URL)8 File (java.io.File)7 InputStream (java.io.InputStream)7 ArrayList (java.util.ArrayList)7 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)7 HashSet (java.util.HashSet)6 OperationFailedException (org.jboss.as.controller.OperationFailedException)6 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)6 ModelNode (org.jboss.dmr.ModelNode)6 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)5 TldMetaData (org.jboss.metadata.web.spec.TldMetaData)5 ModuleNotFoundException (org.jboss.modules.ModuleNotFoundException)5 HashMap (java.util.HashMap)4