Search in sources :

Example 86 with Module

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

the class WSRefAnnotationProcessor method elementForInjectionTarget.

private static AnnotatedElement elementForInjectionTarget(final DeploymentUnit unit, final InjectionTarget injectionTarget) throws DeploymentUnitProcessingException {
    final Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final DeploymentReflectionIndex deploymentReflectionIndex = unit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final String injectionTargetClassName = injectionTarget.getClassName();
    final String injectionTargetName = getInjectionTargetName(injectionTarget);
    final AccessibleObject fieldOrMethod = getInjectionTarget(injectionTargetClassName, injectionTargetName, module.getClassLoader(), deploymentReflectionIndex);
    return fieldOrMethod;
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject) Module(org.jboss.modules.Module) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 87 with Module

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

the class ApplicationClientStartProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final ApplicationClientMetaData appClientData = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_META_DATA);
    final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    //setup the callback handler
    final CallbackHandler callbackHandler;
    if (appClientData != null && appClientData.getCallbackHandler() != null && !appClientData.getCallbackHandler().isEmpty()) {
        try {
            final Class<?> callbackClass = ClassLoadingUtils.loadClass(appClientData.getCallbackHandler(), module);
            callbackHandler = new RealmCallbackWrapper((CallbackHandler) callbackClass.newInstance());
        } catch (ClassNotFoundException e) {
            throw AppClientLogger.ROOT_LOGGER.couldNotLoadCallbackClass(appClientData.getCallbackHandler());
        } catch (Exception e) {
            throw AppClientLogger.ROOT_LOGGER.couldNotCreateCallbackHandler(appClientData.getCallbackHandler());
        }
    } else {
        callbackHandler = new DefaultApplicationClientCallbackHandler();
    }
    Boolean activate = deploymentUnit.getAttachment(AppClientAttachments.START_APP_CLIENT);
    if (activate == null || !activate) {
        return;
    }
    final Class<?> mainClass = deploymentUnit.getAttachment(AppClientAttachments.MAIN_CLASS);
    if (mainClass == null) {
        throw AppClientLogger.ROOT_LOGGER.cannotStartAppClient(deploymentUnit.getName());
    }
    final ApplicationClientComponentDescription component = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_COMPONENT);
    Method mainMethod = null;
    Class<?> klass = mainClass;
    while (klass != Object.class) {
        final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(klass);
        mainMethod = index.getMethod(void.class, "main", String[].class);
        if (mainMethod != null) {
            break;
        }
        klass = klass.getSuperclass();
    }
    if (mainMethod == null) {
        throw AppClientLogger.ROOT_LOGGER.cannotStartAppClient(deploymentUnit.getName(), mainClass);
    }
    final ApplicationClientStartService startService;
    final List<SetupAction> setupActions = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.OTHER_EE_SETUP_ACTIONS);
    if (connectionPropertiesUrl != null) {
        try {
            final File file = new File(connectionPropertiesUrl);
            final URL url;
            if (file.exists()) {
                url = file.toURI().toURL();
            } else {
                url = new URL(connectionPropertiesUrl);
            }
            Properties properties = new Properties();
            InputStream stream = null;
            try {
                stream = url.openStream();
                properties.load(stream);
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (IOException e) {
                    //ignore
                    }
                }
            }
            final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
            try {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
                startService = new ApplicationClientStartService(mainMethod, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions);
            } finally {
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
            }
        } catch (Exception e) {
            throw AppClientLogger.ROOT_LOGGER.exceptionLoadingEjbClientPropertiesURL(connectionPropertiesUrl, e);
        }
    } else {
        startService = new ApplicationClientStartService(mainMethod, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions, hostUrl, callbackHandler);
    }
    phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ApplicationClientStartService.SERVICE_NAME), startService).addDependency(ApplicationClientDeploymentService.SERVICE_NAME, ApplicationClientDeploymentService.class, startService.getApplicationClientDeploymentServiceInjectedValue()).addDependency(component.getCreateServiceName(), Component.class, startService.getApplicationClientComponent()).install();
}
Also used : DefaultApplicationClientCallbackHandler(org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler) CallbackHandler(javax.security.auth.callback.CallbackHandler) Properties(java.util.Properties) URL(java.net.URL) RealmCallbackWrapper(org.jboss.as.appclient.service.RealmCallbackWrapper) ApplicationClientComponentDescription(org.jboss.as.appclient.component.ApplicationClientComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) Component(org.jboss.as.ee.component.Component) InputStream(java.io.InputStream) DefaultApplicationClientCallbackHandler(org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) SetupAction(org.jboss.as.server.deployment.SetupAction) Method(java.lang.reflect.Method) IOException(java.io.IOException) ApplicationClientStartService(org.jboss.as.appclient.service.ApplicationClientStartService) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) File(java.io.File)

Example 88 with Module

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

the class JdbcDriverAdd method performRuntime.

protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    final String driverName = PathAddress.pathAddress(address).getLastElement().getValue();
    if (operation.get(DRIVER_NAME.getName()).isDefined() && !driverName.equals(operation.get(DRIVER_NAME.getName()).asString())) {
        throw ConnectorLogger.ROOT_LOGGER.driverNameAndResourceNameNotEquals(operation.get(DRIVER_NAME.getName()).asString(), driverName);
    }
    String moduleName = DRIVER_MODULE_NAME.resolveModelAttribute(context, model).asString();
    final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? DRIVER_MAJOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
    final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? DRIVER_MINOR_VERSION.resolveModelAttribute(context, model).asInt() : null;
    final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? DRIVER_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
    final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
    final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? DRIVER_XA_DATASOURCE_CLASS_NAME.resolveModelAttribute(context, model).asString() : null;
    final ServiceTarget target = context.getServiceTarget();
    final ModuleIdentifier moduleId;
    final Module module;
    String slot = model.hasDefined(MODULE_SLOT.getName()) ? MODULE_SLOT.resolveModelAttribute(context, model).asString() : null;
    try {
        moduleId = ModuleIdentifier.create(moduleName, slot);
        module = Module.getCallerModuleLoader().loadModule(moduleId);
    } catch (ModuleLoadException e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName), e);
    }
    if (driverClassName == null) {
        final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
        boolean driverLoaded = false;
        if (serviceLoader != null) {
            for (Driver driver : serviceLoader) {
                startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
                driverLoaded = true;
                // w/ explicit declaration of driver-class attribute
                break;
            }
        }
        if (!driverLoaded)
            SUBSYSTEM_DATASOURCES_LOGGER.cannotFindDriverClassName(driverName);
    } else {
        try {
            final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
            final Constructor<? extends Driver> constructor = driverClass.getConstructor();
            final Driver driver = constructor.newInstance();
            startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
        } catch (Exception e) {
            SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
            throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.cannotInstantiateDriverClass(driverClassName));
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) Driver(java.sql.Driver) ModuleLoadException(org.jboss.modules.ModuleLoadException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) ModelNode(org.jboss.dmr.ModelNode) Module(org.jboss.modules.Module)

Example 89 with Module

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

the class JdbcDriverRemove method recoverServices.

protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) {
    final String driverName = model.require(DRIVER_NAME.getName()).asString();
    final String moduleName = model.require(DRIVER_MODULE_NAME.getName()).asString();
    final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? model.get(DRIVER_MAJOR_VERSION.getName()).asInt() : null;
    final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? model.get(DRIVER_MINOR_VERSION.getName()).asInt() : null;
    final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? model.get(DRIVER_CLASS_NAME.getName()).asString() : null;
    final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).asString() : null;
    final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).asString() : null;
    final ServiceTarget target = context.getServiceTarget();
    final ModuleIdentifier moduleId;
    final Module module;
    try {
        moduleId = ModuleIdentifier.fromString(moduleName);
        module = Module.getCallerModuleLoader().loadModule(moduleId);
    } catch (ModuleLoadException e) {
        context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName));
        return;
    }
    if (driverClassName == null) {
        final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
        if (serviceLoader != null)
            for (Driver driver : serviceLoader) {
                startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
            }
    } else {
        try {
            final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
            final Constructor<? extends Driver> constructor = driverClass.getConstructor();
            final Driver driver = constructor.newInstance();
            startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
        } catch (Exception e) {
            SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ServiceTarget(org.jboss.msc.service.ServiceTarget) Driver(java.sql.Driver) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleLoadException(org.jboss.modules.ModuleLoadException)

Example 90 with Module

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

the class JPAIdentityStoreService method createEmbeddedEntityManagerFactory.

private EntityManagerFactory createEmbeddedEntityManagerFactory() {
    ROOT_LOGGER.debugf("Creating embedded EntityManagerFactory.");
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Map<Object, Object> properties = new HashMap<Object, Object>();
        String dataSourceJndiUrl = this.storeConfig.getDataSourceJndiUrl();
        if (!isNullOrEmpty(dataSourceJndiUrl)) {
            ROOT_LOGGER.debugf("Using datasource [%s] for embedded EntityManagerFactory.", dataSourceJndiUrl);
            properties.put("javax.persistence.jtaDataSource", dataSourceJndiUrl);
        }
        properties.put(AvailableSettings.JTA_PLATFORM, new JBossAppServerJtaPlatform());
        Module entityModule = this.storeConfig.getEntityModule();
        if (entityModule != null) {
            Thread.currentThread().setContextClassLoader(entityModule.getClassLoader());
        }
        return Persistence.createEntityManagerFactory(this.storeConfig.getEntityModuleUnitName(), properties);
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
}
Also used : HashMap(java.util.HashMap) Module(org.jboss.modules.Module) JBossAppServerJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.JBossAppServerJtaPlatform)

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