private static Class unwrapClass(ModelNode classModel) throws OperationFailedException { String className = classModel.get(NAME).asString(); String moduleName = classModel.get(MODULE).asString(); try { ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName); Module module = Module.getCallerModuleLoader().loadModule(moduleID); Class<?> clazz = module.getClassLoader().loadClass(className); return clazz; } catch (Exception e) { throw ROOT_LOGGER.unableToLoadClassFromModule(className, moduleName); } } }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final ModuleLoader moduleLoader = Module.getBootModuleLoader(); // for (final ModuleIdentifier moduleIdentifier : DEPENDENCIES) { moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, true, false, true, false)); } }
private ClassLoader _getClassLoader(Class<?> proxiedBeanType) { if (proxiedBeanType.getName().startsWith("java")) { return module.getClassLoader(); } else if(proxiedBeanType.getClassLoader() instanceof ModuleClassLoader) { final ModuleClassLoader loader = (ModuleClassLoader)proxiedBeanType.getClassLoader(); if(loader.getModule().getModuleLoader() instanceof ServiceModuleLoader) { final Module definingModule = loader.getModule(); Boolean hasWeldDependencies = processedStaticModules.get(definingModule.getIdentifier()); boolean logWarning = false; // only log for the first class in the module logWarning = processedStaticModules.putIfAbsent(definingModule.getIdentifier(), hasWeldDependencies) == null; WeldLogger.ROOT_LOGGER.loadingProxiesUsingDeploymentClassLoader(definingModule.getIdentifier(), Arrays.toString(REQUIRED_WELD_DEPENDENCIES)); return this.module.getClassLoader();
protected Class<?> getHandlerClass(String className, String moduleName) { ModuleLoader moduleLoader = Module.getBootModuleLoader(); try { Module filterModule = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName)); return filterModule.getClassLoader().loadClassLocal(className); } catch (ModuleLoadException | ClassNotFoundException e) { throw UndertowLogger.ROOT_LOGGER.couldNotLoadHandlerFromModule(className,moduleName,e); } }
static ClassLoader loadModule(String moduleName) throws ConfigXMLParseException { try { return Module.getModuleFromCallerModuleLoader(ModuleIdentifier.fromString(moduleName)).getClassLoader(); } catch (ModuleLoadException e) { throw new ConfigXMLParseException(e); } } }
/** * Create a ModuleReference from a target class name and factory class. * * @param className The class name for the reference * @param factoryClass The factory class * @return A ModularReference */ public static ModularReference create(final String className, final Class<?> factoryClass) { return new ModularReference(className, factoryClass.getName(), Module.forClass(factoryClass).getIdentifier()); }
if (deploymentUnit.getParent() == null && CdiAnnotationMarker.cdiAnnotationsPresent(deploymentUnit)) { WeldLogger.DEPLOYMENT_LOGGER.cdiAnnotationsButNotBeanArchive(deploymentUnit.getName()); WeldLogger.DEPLOYMENT_LOGGER.startingServicesForCDIDeployment(phaseContext.getDeploymentUnit().getName()); final Module module = deploymentUnit.getAttachment(Attachments.MODULE); final BeanDeploymentModule rootBeanDeploymentModule = deploymentUnit.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE); putIfValueNotNull(eeModuleDescriptors, module.getIdentifier(), rootBeanDeploymentModule.getModuleDescriptor()); bdmsByIdentifier.put(module.getIdentifier(), rootBeanDeploymentModule); moduleSpecByIdentifier.put(module.getIdentifier(), moduleSpecification); continue; subDeploymentLoaders.add(subDeploymentModule.getClassLoader()); final ModuleSpecification subDeploymentModuleSpec = subDeployment.getAttachment(Attachments.MODULE_SPECIFICATION); bdmsByIdentifier.put(subDeploymentModule.getIdentifier(), bdm); moduleSpecByIdentifier.put(subDeploymentModule.getIdentifier(), subDeploymentModuleSpec); putIfValueNotNull(eeModuleDescriptors, subDeploymentModule.getIdentifier(), bdm.getModuleDescriptor()); continue; // the root module only has access to itself startService.setInstance(new WeldStartService(bootstrapSupplier, setupActions, module.getClassLoader(), Utils.getRootDeploymentUnit(deploymentUnit).getServiceName())); startService.install();
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); final ServiceModuleLoader loader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER); if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) { return; // Skip non web deployments WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY); assert warMetaData != null; final Module module = deploymentUnit.getAttachment(Attachments.MODULE); throw UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit); final ClassLoader classLoader = module.getClassLoader(); ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY); if (scisMetaData == null) { for (ModuleDependency dependency : moduleSpecification.getAllDependencies()) { if (!dependency.isImportServices()) { continue; Module depModule = loader.loadModule(dependency.getIdentifier()); ServiceLoader<ServletContainerInitializer> serviceLoader = depModule.loadService(ServletContainerInitializer.class); for (ServletContainerInitializer service : serviceLoader) { if(sciClasses.add(service.getClass())) { if (!dependency.isOptional()) { throw UndertowLogger.ROOT_LOGGER.errorLoadingSCIFromModule(dependency.getIdentifier().toString(), e);
private boolean isEnvEntryType(final String type, final Module module) { if (SIMPLE_ENTRIES.contains(type)) { return true; } try { return module.getClassLoader().loadClass(type).isEnum(); } catch (ClassNotFoundException e) { return false; } }
/** * Add dependencies for modules required for ra deployments * * @param phaseContext the deployment unit context * @throws DeploymentUnitProcessingException * */ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ModuleLoader moduleLoader = Module.getBootModuleLoader(); final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, RESOURCE_API_ID, false, false, false, false)); if (phaseContext.getDeploymentUnit().getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY) == null) { return; // Skip non ra deployments } //if a module depends on a rar it also needs a dep on all the rar's "local dependencies" moduleSpecification.setLocalDependenciesTransitive(true); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JMS_ID, false, false, false, false)); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, VALIDATION_ID, false, false, false, false)); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, IRON_JACAMAR_ID, false, false, false, false)); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, IRON_JACAMAR_IMPL_ID, false, true, false, false)); moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, HIBERNATE_VALIDATOR_ID, false, false, true, false)); if (! appclient) phaseContext.addDeploymentDependency(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, ResourceAdaptersSubsystemService.ATTACHMENT_KEY); }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final Module module = deploymentUnit.getAttachment(Attachments.MODULE); final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION); if(module == null || moduleDescription == null) { return; } final LazyValidatorFactory factory = new LazyValidatorFactory(module.getClassLoader()); deploymentUnit.putAttachment(BeanValidationAttachments.VALIDATOR_FACTORY, factory); bindFactoryToJndi(factory,deploymentUnit,phaseContext,moduleDescription); }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); final ServiceName paViewServiceName = getProcessApplicationViewServiceName(paComponent); Module module = deploymentUnit.getAttachment(Attachments.MODULE); final String moduleName = module.getIdentifier().toString(); final ServiceName paStartServiceName = ServiceNames.forProcessApplicationStartService(moduleName); final ServiceName paStopServiceName = ServiceNames.forProcessApplicationStopService(moduleName); ServiceBuilder<ProcessApplicationStopService> stopServiceBuilder = phaseContext.getServiceTarget().addService(paStopServiceName, paStopService) .addDependency(phaseContext.getPhaseServiceName()) .addDependency(ServiceNames.forBpmPlatformPlugins(), BpmPlatformPlugins.class, paStopService.getPlatformPluginsInjector()) .setInitialMode(Mode.ACTIVE); ServiceName deploymentServiceName = ServiceNames.forProcessApplicationDeploymentService(deploymentUnit.getName(), processArachiveName); ServiceBuilder<ProcessApplicationDeploymentService> serviceBuilder = phaseContext.getServiceTarget().addService(deploymentServiceName, deploymentService) .addDependency(phaseContext.getPhaseServiceName())
/** {@inheritDoc} */ public Class<?> resolveClass(final Unmarshaller unmarshaller, final String className, final long serialVersionUID) throws IOException, ClassNotFoundException { final String name = (String) unmarshaller.readObject(); if (name == null) { return Class.forName(className, false, MODULE_CLASS_LOADER); } final String slot = (String) unmarshaller.readObject(); final ModuleIdentifier identifier = ModuleIdentifier.create(name, slot); try { final ClassLoader classLoader; final Module module = moduleLoader.loadModule(identifier); if (System.getSecurityManager() == null) { classLoader = module.getClassLoader(); } else { classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { @Override public ClassLoader run() { return module.getClassLoader(); } }); } return Class.forName(className, false, classLoader); } catch (ModuleLoadException e) { final InvalidClassException ce = new InvalidClassException(className, "Module load failed"); ce.initCause(e); throw ce; } }
@Override public void getResourceValue(final ResolutionContext resolutionContext, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException { final ClassLoader classLoader = phaseContext.getDeploymentUnit().getAttachment(Attachments.MODULE).getClassLoader(); injector.inject(new ValidatorJndiInjectable(new LazyValidatorFactory(classLoader))); } }
moduleId = ModuleIdentifier.create(moduleName, slot); module = Module.getCallerModuleLoader().loadModule(moduleId); } catch (ModuleNotFoundException e) { throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.missingDependencyInModuleDriver(moduleName, e.getMessage()), e); Class<? extends DataSource> dsCls; try { dsCls = module.getClassLoader().loadClass(dataSourceClassName).asSubclass(DataSource.class); } catch (ClassNotFoundException | ClassCastException e) { throw SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(dataSourceClassName, e); Class<? extends XADataSource> dsCls; try { dsCls = module.getClassLoader().loadClass(xaDataSourceClassName).asSubclass(XADataSource.class); } catch (ClassNotFoundException | ClassCastException e) { throw SUBSYSTEM_DATASOURCES_LOGGER.failedToLoadDataSourceClass(xaDataSourceClassName, e); final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class); boolean driverLoaded = false; if (serviceLoader != null) { } else { try { final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName) .asSubclass(Driver.class); final Constructor<? extends Driver> constructor = driverClass.getConstructor();
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); WeldLogger.DEPLOYMENT_LOGGER.processingWeldDeployment(deploymentUnit.getName()); for (ResourceRoot resourceRoot : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) { if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) { if (isClassesRoot(resourceRoot)) { bdaMap.put(handler.deploymentResourceRoot, bda); deploymentUnit.putAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE, bdaMap.get(handler.deploymentResourceRoot)); final BeanDeploymentModule bdm = new BeanDeploymentModule(handler.module.getIdentifier().toString(), deploymentUnit, bdaMap.values()); deploymentUnit.putAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE, bdm);
static Class<? extends Protocol> findProtocolClass(OperationContext context, String protocolName, String moduleName) throws OperationFailedException { String className = protocolName; if (moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix)) { className = String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, protocolName); } try { return Module.getContextModuleLoader().loadModule(moduleName).getClassLoader().loadClass(className).asSubclass(Protocol.class); } catch (ClassNotFoundException | ModuleLoadException e) { throw JGroupsLogger.ROOT_LOGGER.unableToLoadProtocolClass(className); } } }
private void processModuleDescription(final EEModuleDescription moduleDescription, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext) { final ConcurrentContext concurrentContext = moduleDescription.getConcurrentContext(); // setup context setupConcurrentContext(concurrentContext, moduleDescription.getApplicationName(), moduleDescription.getModuleName(), null, deploymentUnit.getAttachment(MODULE).getClassLoader(), moduleDescription.getNamespaceContextSelector(), deploymentUnit, phaseContext.getServiceTarget()); // add setup action for web modules final ConcurrentContextSetupAction setupAction = new ConcurrentContextSetupAction(concurrentContext); deploymentUnit.getAttachmentList(Attachments.WEB_SETUP_ACTIONS).add(setupAction); }
public List<TldMetaData> getSharedTlds(DeploymentUnit deploymentUnit) { final List<TldMetaData> metadata = new ArrayList<TldMetaData>(); try { ModuleClassLoader jstl = Module.getModuleFromCallerModuleLoader(ModuleIdentifier.create("javax.servlet.jstl.api")).getClassLoader(); for (String tld : JSTL_TAGLIBS) { InputStream is = jstl.getResourceAsStream("META-INF/" + tld); if (is != null) { TldMetaData tldMetaData = parseTLD(is); metadata.add(tldMetaData); } } } catch (ModuleLoadException e) { // Ignore } catch (Exception e) { // Ignore } List<TldMetaData> additionalSharedTlds = deploymentUnit.getAttachment(ATTACHMENT_KEY); if (additionalSharedTlds != null) { metadata.addAll(additionalSharedTlds); } return metadata; }
private void loadFractionConfigurations() throws Exception { Module m1 = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("swarm.application")); ServiceLoader<RuntimeModuleProvider> providerLoader = m1.loadService(RuntimeModuleProvider.class); Iterator<RuntimeModuleProvider> providerIter = providerLoader.iterator(); if (!providerIter.hasNext()) { providerLoader = ServiceLoader.load(RuntimeModuleProvider.class, ClassLoader.getSystemClassLoader()); providerIter = providerLoader.iterator(); } while (providerIter.hasNext()) { RuntimeModuleProvider provider = providerIter.next(); Module module = Module.getBootModuleLoader().loadModule(ModuleIdentifier.create(provider.getModuleName(), provider.getSlotName())); ServiceLoader<ServerConfiguration> configLoaders = module.loadService(ServerConfiguration.class); for (ServerConfiguration serverConfig : configLoaders) { this.configByFractionType.put(serverConfig.getType(), serverConfig); this.configList.add(serverConfig); } } }