Search in sources :

Example 21 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException 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;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleNotFoundException(org.jboss.modules.ModuleNotFoundException) ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module)

Example 22 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.

the class JSFDependencyProcessor method addJSFInjection.

private void addJSFInjection(String jsfVersion, ModuleSpecification moduleSpecification, ModuleLoader moduleLoader) throws DeploymentUnitProcessingException {
    if (jsfVersion.equals(JsfVersionMarker.WAR_BUNDLES_JSF_IMPL))
        return;
    ModuleIdentifier jsfInjectionModule = moduleIdFactory.getInjectionModId(jsfVersion);
    ModuleDependency jsfInjectionDependency = new ModuleDependency(moduleLoader, jsfInjectionModule, false, true, true, false);
    try {
        if (isJSF12(jsfInjectionDependency, jsfInjectionModule.toString())) {
            JSFLogger.ROOT_LOGGER.loadingJsf12();
            jsfInjectionDependency.addImportFilter(PathFilters.is("META-INF/faces-config.xml"), false);
            jsfInjectionDependency.addImportFilter(PathFilters.is("META-INF/1.2/faces-config.xml"), true);
        } else {
            JSFLogger.ROOT_LOGGER.loadingJsf2x();
            jsfInjectionDependency.addImportFilter(PathFilters.getMetaInfFilter(), true);
            // Exclude Faces 1.2 faces-config.xml to make extra sure it won't interfere with JSF 2.0 deployments
            jsfInjectionDependency.addImportFilter(PathFilters.is("META-INF/1.2/faces-config.xml"), false);
        }
    } catch (ModuleLoadException e) {
        throw JSFLogger.ROOT_LOGGER.jsfInjectionFailed(jsfVersion, e);
    }
    moduleSpecification.addSystemDependency(jsfInjectionDependency);
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) ModuleIdentifier(org.jboss.modules.ModuleIdentifier)

Example 23 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.

the class JSFSharedTldsProcessor method getMap.

private Map<String, List<TldMetaData>> getMap() {
    final Map<String, List<TldMetaData>> jsfTldMap = new HashMap<>();
    JSFModuleIdFactory moduleFactory = JSFModuleIdFactory.getInstance();
    List<String> jsfSlotNames = moduleFactory.getActiveJSFVersions();
    for (String slot : jsfSlotNames) {
        final List<TldMetaData> jsfTlds = new ArrayList<TldMetaData>();
        try {
            ModuleClassLoader jsf = Module.getModuleFromCallerModuleLoader(moduleFactory.getImplModId(slot)).getClassLoader();
            for (String tld : JSF_TAGLIBS) {
                InputStream is = jsf.getResourceAsStream("META-INF/" + tld);
                if (is != null) {
                    TldMetaData tldMetaData = parseTLD(is);
                    jsfTlds.add(tldMetaData);
                }
            }
        } catch (ModuleLoadException e) {
        // Ignore
        } catch (Exception e) {
        // Ignore
        }
        jsfTldMap.put(slot, jsfTlds);
    }
    return jsfTldMap;
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ModuleLoadException(org.jboss.modules.ModuleLoadException) HashMap(java.util.HashMap) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.

the class JPAExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    SubsystemRegistration registration = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION);
    final ManagementResourceRegistration nodeRegistration = registration.registerSubsystemModel(JPADefinition.INSTANCE);
    nodeRegistration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE);
    registration.registerXMLElementWriter(new JPASubsystemElementParser1_1());
    try {
        PersistenceProviderLoader.loadDefaultProvider();
    } catch (ModuleLoadException e) {
        ROOT_LOGGER.errorPreloadingDefaultProvider(e);
    }
    if (context.isRuntimeOnlyRegistrationValid()) {
        registration.registerDeploymentModel(JPADefinition.DEPLOYMENT_INSTANCE);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) SubsystemRegistration(org.jboss.as.controller.SubsystemRegistration)

Example 25 with ModuleLoadException

use of org.jboss.modules.ModuleLoadException in project wildfly by wildfly.

the class HostExcludesTestCase method retrieveAvailableExtensions.

/**
 * Retrieve the list of all modules which export locally a resource that implements a org.jboss.as.controller.Extension.
 * This list is considered the list of all available extensions that can be added to a server.
 *
 * It is assumed that the module which is added as an extension has the org.jboss.as.controller.Extension service as
 * a local resource.
 */
private Set<String> retrieveAvailableExtensions() throws IOException {
    final Set<String> result = new HashSet<>();
    LocalModuleLoader ml = new LocalModuleLoader(getModuleRoots());
    Iterator<String> moduleNames = ml.iterateModules((String) null, true);
    while (moduleNames.hasNext()) {
        String moduleName = moduleNames.next();
        Module module;
        try {
            module = ml.loadModule(moduleName);
            List<Resource> resources = module.getClassLoader().loadResourceLocal("META-INF/services/org.jboss.as.controller.Extension");
            if (!resources.isEmpty()) {
                result.add(moduleName);
            }
        } catch (ModuleLoadException e) {
            Logger.getLogger(HostExcludesTestCase.class).warn("Failed to load module " + moduleName + " to check if it is an extension", e);
        }
    }
    return result;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) Resource(org.jboss.modules.Resource) Module(org.jboss.modules.Module) LocalModuleLoader(org.jboss.modules.LocalModuleLoader) HashSet(java.util.HashSet)

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