Search in sources :

Example 21 with Module

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

the class RaOperationUtil method installRaServicesAndDeployFromModule.

public static void installRaServicesAndDeployFromModule(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, String fullModuleName, final List<ServiceController<?>> newControllers) throws OperationFailedException {
    ServiceName raServiceName = installRaServices(context, name, resourceAdapter, newControllers);
    final boolean resolveProperties = true;
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final String moduleName;
    //load module
    String slot = "main";
    if (fullModuleName.contains(":")) {
        slot = fullModuleName.substring(fullModuleName.indexOf(":") + 1);
        moduleName = fullModuleName.substring(0, fullModuleName.indexOf(":"));
    } else {
        moduleName = fullModuleName;
    }
    Module module;
    try {
        ModuleIdentifier moduleId = ModuleIdentifier.create(moduleName, slot);
        module = Module.getCallerModuleLoader().loadModule(moduleId);
    } catch (ModuleLoadException e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
    }
    URL path = module.getExportedResource("META-INF/ra.xml");
    Closeable closable = null;
    try {
        VirtualFile child;
        if (path.getPath().contains("!")) {
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.compressedRarNotSupportedInModuleRA(moduleName));
        } else {
            child = VFS.getChild(path.getPath().split("META-INF")[0]);
            closable = VFS.mountReal(new File(path.getPath().split("META-INF")[0]), child);
        }
        //final Closeable closable = VFS.mountZip((InputStream) new JarInputStream(new FileInputStream(path.getPath().split("!")[0].split(":")[1])), path.getPath().split("!")[0].split(":")[1], child, TempFileProviderService.provider());
        final MountHandle mountHandle = new MountHandle(closable);
        final ResourceRoot resourceRoot = new ResourceRoot(child, mountHandle);
        final VirtualFile deploymentRoot = resourceRoot.getRoot();
        if (deploymentRoot == null || !deploymentRoot.exists())
            return;
        ConnectorXmlDescriptor connectorXmlDescriptor = RaDeploymentParsingProcessor.process(resolveProperties, deploymentRoot, null, name);
        IronJacamarXmlDescriptor ironJacamarXmlDescriptor = IronJacamarDeploymentParsingProcessor.process(deploymentRoot, resolveProperties);
        RaNativeProcessor.process(deploymentRoot);
        Map<ResourceRoot, Index> annotationIndexes = new HashMap<ResourceRoot, Index>();
        ResourceRootIndexer.indexResourceRoot(resourceRoot);
        Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
        if (index != null) {
            annotationIndexes.put(resourceRoot, index);
        }
        if (ironJacamarXmlDescriptor != null) {
            ConnectorLogger.SUBSYSTEM_RA_LOGGER.forceIJToNull();
            ironJacamarXmlDescriptor = null;
        }
        final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
        final ServiceController<?> deployerService = context.getServiceRegistry(true).getService(deployerServiceName);
        if (deployerService == null) {
            ServiceBuilder builder = ParsedRaDeploymentProcessor.process(connectorXmlDescriptor, ironJacamarXmlDescriptor, module.getClassLoader(), serviceTarget, annotationIndexes, RAR_MODULE.append(name), null, null);
            newControllers.add(builder.addDependency(raServiceName).setInitialMode(ServiceController.Mode.ACTIVE).install());
        }
        String rarName = resourceAdapter.getArchive();
        if (fullModuleName.equals(rarName)) {
            ServiceName serviceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(name);
            InactiveResourceAdapterDeploymentService service = new InactiveResourceAdapterDeploymentService(connectorXmlDescriptor, module, name, name, RAR_MODULE.append(name), null, serviceTarget, null);
            newControllers.add(serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).install());
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleRA(moduleName), e);
    } finally {
        if (closable != null) {
            try {
                closable.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) VirtualFile(org.jboss.vfs.VirtualFile) InactiveResourceAdapterDeploymentService(org.jboss.as.connector.services.resourceadapters.deployment.InactiveResourceAdapterDeploymentService) MountHandle(org.jboss.as.server.deployment.module.MountHandle) HashMap(java.util.HashMap) ServiceTarget(org.jboss.msc.service.ServiceTarget) Closeable(java.io.Closeable) OperationFailedException(org.jboss.as.controller.OperationFailedException) ConnectorXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor) Index(org.jboss.jandex.Index) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleLoadException(org.jboss.modules.ModuleLoadException) ValidateException(org.jboss.jca.common.api.validator.ValidateException) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ServiceName(org.jboss.msc.service.ServiceName) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) IronJacamarXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor) Module(org.jboss.modules.Module) File(java.io.File) VirtualFile(org.jboss.vfs.VirtualFile)

Example 22 with Module

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

the class DefaultComponentViewConfigurator method configure.

public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final ProxyMetadataSource proxyReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.PROXY_REFLECTION_INDEX);
    //views
    for (ViewDescription view : description.getViews()) {
        Class<?> viewClass;
        try {
            viewClass = module.getClassLoader().loadClass(view.getViewClassName());
        } catch (ClassNotFoundException e) {
            throw EeLogger.ROOT_LOGGER.cannotLoadViewClass(e, view.getViewClassName(), configuration);
        }
        final ViewConfiguration viewConfiguration;
        final ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
        if (viewClass.getName().startsWith("java.")) {
            proxyConfiguration.setProxyName("org.jboss.proxy.java.lang." + viewClass.getSimpleName() + "$$$view" + PROXY_ID.incrementAndGet());
        } else {
            proxyConfiguration.setProxyName(viewClass.getName() + "$$$view" + PROXY_ID.incrementAndGet());
        }
        proxyConfiguration.setClassLoader(module.getClassLoader());
        proxyConfiguration.setProtectionDomain(viewClass.getProtectionDomain());
        proxyConfiguration.setMetadataSource(proxyReflectionIndex);
        if (view.isSerializable()) {
            proxyConfiguration.addAdditionalInterface(Serializable.class);
            if (view.isUseWriteReplace()) {
                proxyConfiguration.addAdditionalInterface(WriteReplaceInterface.class);
            }
        }
        //we define it in the modules class loader to prevent permgen leaks
        if (viewClass.isInterface()) {
            proxyConfiguration.setSuperClass(Object.class);
            proxyConfiguration.addAdditionalInterface(viewClass);
            viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
        } else {
            proxyConfiguration.setSuperClass(viewClass);
            viewConfiguration = view.createViewConfiguration(viewClass, configuration, new ProxyFactory(proxyConfiguration));
        }
        for (final ViewConfigurator configurator : view.getConfigurators()) {
            configurator.configure(context, configuration, view, viewConfiguration);
        }
        configuration.getViews().add(viewConfiguration);
    }
    configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

        @Override
        public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
            for (final Map.Entry<ServiceName, ServiceBuilder.DependencyType> entry : description.getDependencies().entrySet()) {
                serviceBuilder.addDependency(entry.getValue(), entry.getKey());
            }
        }
    });
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ProxyFactory(org.jboss.invocation.proxy.ProxyFactory) ProxyMetadataSource(org.jboss.as.server.deployment.reflect.ProxyMetadataSource) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ProxyConfiguration(org.jboss.invocation.proxy.ProxyConfiguration) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 23 with Module

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

the class JaxrsScanningProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!JaxrsDeploymentMarker.isJaxrsDeployment(deploymentUnit)) {
        return;
    }
    final DeploymentUnit parent = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
    final Map<ModuleIdentifier, ResteasyDeploymentData> deploymentData;
    if (deploymentUnit.getParent() == null) {
        deploymentData = Collections.synchronizedMap(new HashMap<ModuleIdentifier, ResteasyDeploymentData>());
        deploymentUnit.putAttachment(JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA, deploymentData);
    } else {
        deploymentData = parent.getAttachment(JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA);
    }
    final ModuleIdentifier moduleIdentifier = deploymentUnit.getAttachment(Attachments.MODULE_IDENTIFIER);
    ResteasyDeploymentData resteasyDeploymentData = new ResteasyDeploymentData();
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    try {
        if (warMetaData == null) {
            resteasyDeploymentData.setScanAll(true);
            scan(deploymentUnit, module.getClassLoader(), resteasyDeploymentData);
            deploymentData.put(moduleIdentifier, resteasyDeploymentData);
        } else {
            scanWebDeployment(deploymentUnit, warMetaData.getMergedJBossWebMetaData(), module.getClassLoader(), resteasyDeploymentData);
            scan(deploymentUnit, module.getClassLoader(), resteasyDeploymentData);
        }
        deploymentUnit.putAttachment(JaxrsAttachments.RESTEASY_DEPLOYMENT_DATA, resteasyDeploymentData);
        List<String> rootRestClasses = new ArrayList<>(resteasyDeploymentData.getScannedResourceClasses());
        Collections.sort(rootRestClasses);
        for (String cls : rootRestClasses) {
            addManagement(deploymentUnit, cls);
        }
    } catch (ModuleLoadException e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashMap(java.util.HashMap) WarMetaData(org.jboss.as.web.common.WarMetaData) ArrayList(java.util.ArrayList) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 24 with Module

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

the class JaxrsSpringProcessor method getResteasySpringVirtualFile.

/**
     * Lookup Seam integration resource loader.
     *
     * @return the Seam integration resource loader
     * @throws DeploymentUnitProcessingException
     *          for any error
     */
protected synchronized VirtualFile getResteasySpringVirtualFile() throws DeploymentUnitProcessingException {
    if (resourceRoot != null) {
        return resourceRoot;
    }
    try {
        Module module = Module.getBootModuleLoader().loadModule(MODULE);
        URL fileUrl = module.getClassLoader().getResource(JAR_LOCATION);
        if (fileUrl == null) {
            throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
        }
        File dir = new File(fileUrl.toURI());
        File file = null;
        for (String jar : dir.list()) {
            if (jar.endsWith(".jar")) {
                file = new File(dir, jar);
                break;
            }
        }
        if (file == null) {
            throw JaxrsLogger.JAXRS_LOGGER.noSpringIntegrationJar();
        }
        VirtualFile vf = VFS.getChild(file.toURI());
        final Closeable mountHandle = VFS.mountZip(file, vf, TempFileProviderService.provider());
        Service<Closeable> mountHandleService = new Service<Closeable>() {

            public void start(StartContext startContext) throws StartException {
            }

            public void stop(StopContext stopContext) {
                VFSUtils.safeClose(mountHandle);
            }

            public Closeable getValue() throws IllegalStateException, IllegalArgumentException {
                return mountHandle;
            }
        };
        ServiceBuilder<Closeable> builder = serviceTarget.addService(ServiceName.JBOSS.append(SERVICE_NAME), mountHandleService);
        builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
        resourceRoot = vf;
        return resourceRoot;
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) StopContext(org.jboss.msc.service.StopContext) Closeable(java.io.Closeable) Service(org.jboss.msc.service.Service) TempFileProviderService(org.jboss.as.server.deployment.module.TempFileProviderService) URL(java.net.URL) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) StartException(org.jboss.msc.service.StartException) StartContext(org.jboss.msc.service.StartContext) Module(org.jboss.modules.Module) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File)

Example 25 with Module

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

the class JaxrsCdiIntegrationProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (!JaxrsDeploymentMarker.isJaxrsDeployment(deploymentUnit)) {
        return;
    }
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        return;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    final JBossWebMetaData webdata = warMetaData.getMergedJBossWebMetaData();
    try {
        module.getClassLoader().loadClass(CDI_INJECTOR_FACTORY_CLASS);
        // don't set this param if CDI is not in classpath
        if (WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
            JAXRS_LOGGER.debug("Found CDI, adding injector factory class");
            setContextParameter(webdata, "resteasy.injector.factory", CDI_INJECTOR_FACTORY_CLASS);
        }
    } catch (ClassNotFoundException ignored) {
    }
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

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