Search in sources :

Example 11 with Module

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

the class ParsedServiceDeploymentProcessor method deploy.

/**
     * Process a deployment for JbossService configuration.  Will install a {@code JBossService} for each configured service.
     *
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     */
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final JBossServiceXmlDescriptor serviceXmlDescriptor = deploymentUnit.getAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY);
    if (serviceXmlDescriptor == null) {
        // Skip deployments without a service xml descriptor
        return;
    }
    // assert module
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null)
        throw SarLogger.ROOT_LOGGER.failedToGetAttachment("module", deploymentUnit);
    // assert reflection index
    final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
    if (reflectionIndex == null)
        throw SarLogger.ROOT_LOGGER.failedToGetAttachment("reflection index", deploymentUnit);
    // install services
    final ClassLoader classLoader = module.getClassLoader();
    final List<JBossServiceConfig> serviceConfigs = serviceXmlDescriptor.getServiceConfigs();
    final ServiceTarget target = phaseContext.getServiceTarget();
    final Map<String, ServiceComponentInstantiator> serviceComponents = deploymentUnit.getAttachment(ServiceAttachments.SERVICE_COMPONENT_INSTANTIATORS);
    for (final JBossServiceConfig serviceConfig : serviceConfigs) {
        addServices(target, serviceConfig, classLoader, reflectionIndex, serviceComponents != null ? serviceComponents.get(serviceConfig.getName()) : null, phaseContext);
    }
}
Also used : JBossServiceXmlDescriptor(org.jboss.as.service.descriptor.JBossServiceXmlDescriptor) ServiceTarget(org.jboss.msc.service.ServiceTarget) JBossServiceConfig(org.jboss.as.service.descriptor.JBossServiceConfig) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) ServiceComponentInstantiator(org.jboss.as.service.component.ServiceComponentInstantiator)

Example 12 with Module

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

the class ModuleConfig method visit.

@Override
public void visit(ConfigVisitor visitor) {
    if (moduleName != null) {
        ModuleIdentifier identifier = ModuleIdentifier.fromString(moduleName);
        if (moduleName.startsWith(ServiceModuleLoader.MODULE_PREFIX)) {
            ServiceName serviceName = ServiceModuleLoader.moduleServiceName(identifier);
            visitor.addDependency(serviceName, getInjectedModule());
        } else {
            Module dm = visitor.loadModule(identifier);
            getInjectedModule().setValue(new ImmediateValue<Module>(dm));
        }
    } else {
        getInjectedModule().setValue(new ImmediateValue<Module>(visitor.getModule()));
    }
// no children, no need to visit
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module)

Example 13 with Module

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

the class ServletContainerInitializerDeploymentProcessor method deploy.

/**
     * Process SCIs.
     */
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    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)) {
        // Skip non web deployments
        return;
    }
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    assert warMetaData != null;
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        throw UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit);
    }
    final ClassLoader classLoader = module.getClassLoader();
    ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY);
    if (scisMetaData == null) {
        scisMetaData = new ScisMetaData();
        deploymentUnit.putAttachment(ScisMetaData.ATTACHMENT_KEY, scisMetaData);
    }
    Set<ServletContainerInitializer> scis = scisMetaData.getScis();
    Set<Class<? extends ServletContainerInitializer>> sciClasses = new HashSet<>();
    if (scis == null) {
        scis = new HashSet<ServletContainerInitializer>();
        scisMetaData.setScis(scis);
    }
    Map<ServletContainerInitializer, Set<Class<?>>> handlesTypes = scisMetaData.getHandlesTypes();
    if (handlesTypes == null) {
        handlesTypes = new HashMap<ServletContainerInitializer, Set<Class<?>>>();
        scisMetaData.setHandlesTypes(handlesTypes);
    }
    // Find the SCIs from shared modules
    for (ModuleDependency dependency : moduleSpecification.getAllDependencies()) {
        try {
            Module depModule = loader.loadModule(dependency.getIdentifier());
            ServiceLoader<ServletContainerInitializer> serviceLoader = depModule.loadService(ServletContainerInitializer.class);
            for (ServletContainerInitializer service : serviceLoader) {
                if (sciClasses.add(service.getClass())) {
                    scis.add(service);
                }
            }
        } catch (ModuleLoadException e) {
            if (dependency.isOptional() == false) {
                throw UndertowLogger.ROOT_LOGGER.errorLoadingSCIFromModule(dependency.getIdentifier(), e);
            }
        }
    }
    // Find local ServletContainerInitializer services
    List<String> order = warMetaData.getOrder();
    Map<String, VirtualFile> localScis = warMetaData.getScis();
    if (order != null && localScis != null) {
        for (String jar : order) {
            VirtualFile sci = localScis.get(jar);
            if (sci != null) {
                scis.addAll(loadSci(classLoader, sci, jar, true, sciClasses));
            }
        }
    }
    // Process HandlesTypes for ServletContainerInitializer
    Map<Class<?>, Set<ServletContainerInitializer>> typesMap = new HashMap<Class<?>, Set<ServletContainerInitializer>>();
    for (ServletContainerInitializer service : scis) {
        if (service.getClass().isAnnotationPresent(HandlesTypes.class)) {
            HandlesTypes handlesTypesAnnotation = service.getClass().getAnnotation(HandlesTypes.class);
            Class<?>[] typesArray = handlesTypesAnnotation.value();
            if (typesArray != null) {
                for (Class<?> type : typesArray) {
                    Set<ServletContainerInitializer> servicesSet = typesMap.get(type);
                    if (servicesSet == null) {
                        servicesSet = new HashSet<ServletContainerInitializer>();
                        typesMap.put(type, servicesSet);
                    }
                    servicesSet.add(service);
                    handlesTypes.put(service, new HashSet<Class<?>>());
                }
            }
        }
    }
    Class<?>[] typesArray = typesMap.keySet().toArray(new Class<?>[0]);
    final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (index == null) {
        throw UndertowLogger.ROOT_LOGGER.unableToResolveAnnotationIndex(deploymentUnit);
    }
    //WFLY-4205, look in the parent as well as the war
    CompositeIndex parentIndex = deploymentUnit.getParent() == null ? null : deploymentUnit.getParent().getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    // Find classes which extend, implement, or are annotated by HandlesTypes
    for (Class<?> type : typesArray) {
        DotName className = DotName.createSimple(type.getName());
        Set<ClassInfo> classInfos = new HashSet<>();
        classInfos.addAll(processHandlesType(className, type, index));
        if (parentIndex != null) {
            classInfos.addAll(processHandlesType(className, type, parentIndex));
        }
        Set<Class<?>> classes = loadClassInfoSet(classInfos, classLoader);
        Set<ServletContainerInitializer> sciSet = typesMap.get(type);
        for (ServletContainerInitializer sci : sciSet) {
            handlesTypes.get(sci).addAll(classes);
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) VirtualFile(org.jboss.vfs.VirtualFile) HashSet(java.util.HashSet) Set(java.util.Set) ModuleDependency(org.jboss.as.server.deployment.module.ModuleDependency) HashMap(java.util.HashMap) WarMetaData(org.jboss.as.web.common.WarMetaData) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) ServletContainerInitializer(javax.servlet.ServletContainerInitializer) HandlesTypes(javax.servlet.annotation.HandlesTypes) HashSet(java.util.HashSet) ServiceModuleLoader(org.jboss.as.server.moduleservice.ServiceModuleLoader) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ClassInfo(org.jboss.jandex.ClassInfo)

Example 14 with Module

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

the class SharedSessionManagerDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    SharedSessionManagerConfig sharedConfig = deploymentUnit.getAttachment(UndertowAttachments.SHARED_SESSION_MANAGER_CONFIG);
    if (sharedConfig == null) {
        return;
    }
    ServiceTarget target = phaseContext.getServiceTarget();
    ServiceName deploymentServiceName = deploymentUnit.getServiceName();
    ServiceName managerServiceName = deploymentServiceName.append(SharedSessionManagerConfig.SHARED_SESSION_MANAGER_SERVICE_NAME);
    DistributableSessionManagerFactoryBuilder builder = new DistributableSessionManagerFactoryBuilderValue().getValue();
    if (builder != null) {
        CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
        Module module = deploymentUnit.getAttachment(Attachments.MODULE);
        builder.build(support, target, managerServiceName, new SimpleDistributableSessionManagerConfiguration(sharedConfig, deploymentUnit.getName(), module)).setInitialMode(Mode.ON_DEMAND).install();
    } else {
        InMemorySessionManager manager = new InMemorySessionManager(deploymentUnit.getName(), sharedConfig.getMaxActiveSessions());
        if (sharedConfig.getSessionConfig() != null) {
            if (sharedConfig.getSessionConfig().getSessionTimeoutSet()) {
                manager.setDefaultSessionTimeout(sharedConfig.getSessionConfig().getSessionTimeout());
            }
        }
        SessionManagerFactory factory = new ImmediateSessionManagerFactory(manager);
        target.addService(managerServiceName, new ValueService<>(new ImmediateValue<>(factory))).setInitialMode(Mode.ON_DEMAND).install();
    }
    ServiceName codecServiceName = deploymentServiceName.append(SharedSessionManagerConfig.SHARED_SESSION_IDENTIFIER_CODEC_SERVICE_NAME);
    DistributableSessionIdentifierCodecBuilder sessionIdentifierCodecBuilder = new DistributableSessionIdentifierCodecBuilderValue().getValue();
    if (sessionIdentifierCodecBuilder != null) {
        sessionIdentifierCodecBuilder.build(target, codecServiceName, deploymentUnit.getName()).setInitialMode(Mode.ON_DEMAND).install();
    } else {
        // Fallback to simple codec if server does not support clustering
        SimpleSessionIdentifierCodecService.build(target, codecServiceName).setInitialMode(Mode.ON_DEMAND).install();
    }
}
Also used : DistributableSessionIdentifierCodecBuilderValue(org.wildfly.extension.undertow.session.DistributableSessionIdentifierCodecBuilderValue) ServiceTarget(org.jboss.msc.service.ServiceTarget) DistributableSessionManagerFactoryBuilderValue(org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilderValue) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ImmediateValue(org.jboss.msc.value.ImmediateValue) DistributableSessionIdentifierCodecBuilder(org.wildfly.extension.undertow.session.DistributableSessionIdentifierCodecBuilder) SharedSessionManagerConfig(org.wildfly.extension.undertow.session.SharedSessionManagerConfig) SimpleDistributableSessionManagerConfiguration(org.wildfly.extension.undertow.session.SimpleDistributableSessionManagerConfiguration) DistributableSessionManagerFactoryBuilder(org.wildfly.extension.undertow.session.DistributableSessionManagerFactoryBuilder) ServiceName(org.jboss.msc.service.ServiceName) SessionManagerFactory(io.undertow.servlet.api.SessionManagerFactory) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) InMemorySessionManager(io.undertow.server.session.InMemorySessionManager)

Example 15 with Module

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

the class UndertowHandlersDeploymentProcessor method handleJbossWebXml.

private void handleJbossWebXml(DeploymentUnit deploymentUnit, Module module) throws DeploymentUnitProcessingException {
    WarMetaData warMetadata = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetadata == null) {
        return;
    }
    JBossWebMetaData merged = warMetadata.getMergedJBossWebMetaData();
    if (merged == null) {
        return;
    }
    List<HttpHandlerMetaData> handlers = merged.getHandlers();
    if (handlers == null) {
        return;
    }
    for (HttpHandlerMetaData hander : handlers) {
        try {
            ClassLoader cl = module.getClassLoader();
            if (hander.getModule() != null) {
                Module handlerModule = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER).loadModule(ModuleIdentifier.fromString(hander.getModule()));
                cl = handlerModule.getClassLoader();
            }
            Class<?> handlerClass = cl.loadClass(hander.getHandlerClass());
            Map<String, String> params = new HashMap<>();
            if (hander.getParams() != null) {
                for (ParamValueMetaData param : hander.getParams()) {
                    params.put(param.getParamName(), param.getParamValue());
                }
            }
            deploymentUnit.addToAttachmentList(UndertowAttachments.UNDERTOW_OUTER_HANDLER_CHAIN_WRAPPERS, new ConfiguredHandlerWrapper(handlerClass, params));
        } catch (Exception e) {
            throw UndertowLogger.ROOT_LOGGER.failedToConfigureHandlerClass(hander.getHandlerClass(), e);
        }
    }
}
Also used : ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) HashMap(java.util.HashMap) WarMetaData(org.jboss.as.web.common.WarMetaData) IOException(java.io.IOException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HttpHandlerMetaData(org.jboss.metadata.web.jboss.HttpHandlerMetaData) Module(org.jboss.modules.Module)

Aggregations

Module (org.jboss.modules.Module)100 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)58 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)28 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)27 ServiceName (org.jboss.msc.service.ServiceName)21 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)19 HashMap (java.util.HashMap)17 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)17 ServiceTarget (org.jboss.msc.service.ServiceTarget)17 HashSet (java.util.HashSet)16 ArrayList (java.util.ArrayList)13 ModuleLoadException (org.jboss.modules.ModuleLoadException)11 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)10 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)9 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)8 Method (java.lang.reflect.Method)7 Map (java.util.Map)7 IOException (java.io.IOException)6 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)6 ContextNames (org.jboss.as.naming.deployment.ContextNames)6