Search in sources :

Example 1 with ServiceModuleLoader

use of org.jboss.as.server.moduleservice.ServiceModuleLoader in project wildfly by wildfly.

the class EJBClientDescriptorParsingProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final XMLMapper mapper = createMapper(deploymentUnit);
    final ResourceRoot resourceRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
    final ServiceModuleLoader moduleLoader = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.SERVICE_MODULE_LOADER);
    VirtualFile descriptorFile = null;
    for (final String loc : EJB_CLIENT_DESCRIPTOR_LOCATIONS) {
        final VirtualFile file = resourceRoot.getRoot().getChild(loc);
        if (file.exists()) {
            descriptorFile = file;
            break;
        }
    }
    if (descriptorFile == null) {
        return;
    }
    if (deploymentUnit.getParent() != null) {
        EeLogger.ROOT_LOGGER.subdeploymentIgnored(descriptorFile.getPathName());
        return;
    }
    final File ejbClientDeploymentDescriptorFile;
    try {
        ejbClientDeploymentDescriptorFile = descriptorFile.getPhysicalFile();
    } catch (IOException e) {
        throw EeLogger.ROOT_LOGGER.failedToProcessEJBClientDescriptor(e);
    }
    final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = parse(ejbClientDeploymentDescriptorFile, mapper);
    EeLogger.ROOT_LOGGER.debugf("Successfully parsed jboss-ejb-client.xml for deployment unit %s", deploymentUnit);
    // attach the metadata
    deploymentUnit.putAttachment(Attachments.EJB_CLIENT_METADATA, ejbClientDescriptorMetaData);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLMapper(org.jboss.staxmapper.XMLMapper) EJBClientDescriptorMetaData(org.jboss.as.ee.metadata.EJBClientDescriptorMetaData) ServiceModuleLoader(org.jboss.as.server.moduleservice.ServiceModuleLoader) IOException(java.io.IOException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) File(java.io.File) VirtualFile(org.jboss.vfs.VirtualFile)

Example 2 with ServiceModuleLoader

use of org.jboss.as.server.moduleservice.ServiceModuleLoader 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 LinkedHashSet<>();
        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()) {
        // Should not include SCI if services is not included
        if (!dependency.isImportServices()) {
            continue;
        }
        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()) {
                throw UndertowLogger.ROOT_LOGGER.errorLoadingSCIFromModule(dependency.getIdentifier().toString(), 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));
            }
        }
    }
    // SCI's deployed in the war itself
    if (localScis != null) {
        VirtualFile warDeployedScis = localScis.get("classes");
        if (warDeployedScis != null) {
            scis.addAll(loadSci(classLoader, warDeployedScis, deploymentUnit.getName(), true, sciClasses));
        }
    }
    // Process HandlesTypes for ServletContainerInitializer
    Map<Class<?>, Set<ServletContainerInitializer>> typesMap = new HashMap<Class<?>, Set<ServletContainerInitializer>>();
    for (ServletContainerInitializer service : scis) {
        try {
            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<?>>());
                    }
                }
            }
        } catch (ArrayStoreException e) {
            // Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
            throw UndertowLogger.ROOT_LOGGER.missingClassInAnnotation(HandlesTypes.class.getSimpleName(), service.getClass().getName());
        }
    }
    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);
    }
    final CompositeIndex parent;
    if (deploymentUnit.getParent() != null) {
        parent = deploymentUnit.getParent().getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    } else {
        parent = null;
    }
    // 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, parent));
        if (parentIndex != null) {
            classInfos.addAll(processHandlesType(className, type, parentIndex, parent));
        }
        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) LinkedHashSet(java.util.LinkedHashSet) 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) LinkedHashSet(java.util.LinkedHashSet) 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 3 with ServiceModuleLoader

use of org.jboss.as.server.moduleservice.ServiceModuleLoader in project wildfly by wildfly.

the class GetInstalledDriverOperationHandler method execute.

@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    validator.validate(operation);
    final String name = operation.require(DRIVER_NAME.getName()).asString();
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
                ServiceRegistry registry = context.getServiceRegistry(false);
                DriverRegistry driverRegistry = (DriverRegistry) registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue();
                ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader) registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue();
                ModelNode result = new ModelNode();
                InstalledDriver driver = driverRegistry.getInstalledDriver(name);
                ModelNode driverNode = new ModelNode();
                driverNode.get(DRIVER_NAME.getName()).set(driver.getDriverName());
                if (driver.isFromDeployment()) {
                    driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName());
                    driverNode.get(DRIVER_MODULE_NAME.getName());
                    driverNode.get(MODULE_SLOT.getName());
                    driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName());
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName());
                } else {
                    driverNode.get(DEPLOYMENT_NAME.getName());
                    driverNode.get(DRIVER_MODULE_NAME.getName()).set(driver.getModuleName().getName());
                    driverNode.get(MODULE_SLOT.getName()).set(driver.getModuleName() != null ? driver.getModuleName().getSlot() : "");
                    driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).set(driver.getDataSourceClassName() != null ? driver.getDataSourceClassName() : "");
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).set(driver.getXaDataSourceClassName() != null ? driver.getXaDataSourceClassName() : "");
                }
                driverNode.get(DATASOURCE_CLASS_INFO.getName()).set(dsClsInfoNode(serviceModuleLoader, driver.getModuleName(), driver.getDataSourceClassName(), driver.getXaDataSourceClassName()));
                driverNode.get(DRIVER_CLASS_NAME.getName()).set(driver.getDriverClassName());
                driverNode.get(DRIVER_MAJOR_VERSION.getName()).set(driver.getMajorVersion());
                driverNode.get(DRIVER_MINOR_VERSION.getName()).set(driver.getMinorVersion());
                driverNode.get(JDBC_COMPLIANT.getName()).set(driver.isJdbcCompliant());
                result.add(driverNode);
                context.getResult().set(result);
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ServiceModuleLoader(org.jboss.as.server.moduleservice.ServiceModuleLoader) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

ServiceModuleLoader (org.jboss.as.server.moduleservice.ServiceModuleLoader)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 VirtualFile (org.jboss.vfs.VirtualFile)2 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 ServletContainerInitializer (javax.servlet.ServletContainerInitializer)1 HandlesTypes (javax.servlet.annotation.HandlesTypes)1 InstalledDriver (org.jboss.as.connector.services.driver.InstalledDriver)1 DriverRegistry (org.jboss.as.connector.services.driver.registry.DriverRegistry)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)1 EJBClientDescriptorMetaData (org.jboss.as.ee.metadata.EJBClientDescriptorMetaData)1 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)1 ModuleDependency (org.jboss.as.server.deployment.module.ModuleDependency)1 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)1