Search in sources :

Example 6 with ModuleLoadException

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

the class PersistenceUnitServiceHandler method lookupProvider.

/**
     * Look up the persistence provider
     *
     *
     * @param pu
     * @param deploymentUnit
     * @return
     */
private static PersistenceProvider lookupProvider(PersistenceUnitMetadata pu, PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    /**
         * check if the deployment is already associated with the specified persistence provider
         */
    List<PersistenceProvider> providerList = persistenceProviderDeploymentHolder != null ? persistenceProviderDeploymentHolder.getProviders() : null;
    if (providerList != null) {
        for (PersistenceProvider persistenceProvider : providerList) {
            if (persistenceProvider.getClass().getName().equals(pu.getPersistenceProviderClassName())) {
                ROOT_LOGGER.tracef("deployment %s is using %s", deploymentUnit.getName(), pu.getPersistenceProviderClassName());
                return persistenceProvider;
            }
        }
    }
    String configuredPersistenceProviderModule = pu.getProperties().getProperty(Configuration.PROVIDER_MODULE);
    String persistenceProviderClassName = pu.getPersistenceProviderClassName();
    if (persistenceProviderClassName == null) {
        persistenceProviderClassName = Configuration.PROVIDER_CLASS_DEFAULT;
    }
    /**
         * locate persistence provider in specified static module
         */
    if (configuredPersistenceProviderModule != null) {
        List<PersistenceProvider> providers;
        if (Configuration.PROVIDER_MODULE_APPLICATION_SUPPLIED.equals(configuredPersistenceProviderModule)) {
            try {
                // load the persistence provider from the application deployment
                final ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
                PersistenceProvider provider = PersistenceProviderLoader.loadProviderFromDeployment(classLoader, persistenceProviderClassName);
                providers = new ArrayList<>();
                providers.add(provider);
                PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
                return provider;
            } catch (ClassNotFoundException e) {
                throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
            } catch (InstantiationException e) {
                throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
            } catch (IllegalAccessException e) {
                throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, persistenceProviderClassName);
            }
        } else {
            try {
                providers = PersistenceProviderLoader.loadProviderModuleByName(configuredPersistenceProviderModule);
                PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
                PersistenceProvider provider = getProviderByName(pu, providers);
                if (provider != null) {
                    return provider;
                }
            } catch (ModuleLoadException e) {
                throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, configuredPersistenceProviderModule, persistenceProviderClassName);
            }
        }
    }
    // try to determine the static module name based on the persistence provider class name
    String providerNameDerivedFromClassName = Configuration.getProviderModuleNameFromProviderClassName(persistenceProviderClassName);
    // see if the providerNameDerivedFromClassName has been loaded yet
    PersistenceProvider provider = getProviderByName(pu);
    // if we haven't loaded the provider yet, try loading now
    if (provider == null && providerNameDerivedFromClassName != null) {
        try {
            List<PersistenceProvider> providers = PersistenceProviderLoader.loadProviderModuleByName(providerNameDerivedFromClassName);
            PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providers, null);
            provider = getProviderByName(pu, providers);
        } catch (ModuleLoadException e) {
            throw JpaLogger.ROOT_LOGGER.cannotLoadPersistenceProviderModule(e, providerNameDerivedFromClassName, persistenceProviderClassName);
        }
    }
    if (provider == null)
        throw JpaLogger.ROOT_LOGGER.persistenceProviderNotFound(persistenceProviderClassName);
    return provider;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) PersistenceProvider(javax.persistence.spi.PersistenceProvider)

Example 7 with ModuleLoadException

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

the class PersistenceUnitServiceHandler method getPersistenceProviderAdaptor.

/**
     * Get the persistence provider adaptor.  Will load the adapter module if needed.
     *
     *
     * @param pu
     * @param persistenceProviderDeploymentHolder
     *
     * @param provider
     * @param platform
     * @return
     * @throws DeploymentUnitProcessingException
     *
     */
private static PersistenceProviderAdaptor getPersistenceProviderAdaptor(final PersistenceUnitMetadata pu, final PersistenceProviderDeploymentHolder persistenceProviderDeploymentHolder, final DeploymentUnit deploymentUnit, final PersistenceProvider provider, final Platform platform) throws DeploymentUnitProcessingException {
    String adapterClass = pu.getProperties().getProperty(Configuration.ADAPTER_CLASS);
    /**
         * use adapter packaged in application deployment.
         */
    if (persistenceProviderDeploymentHolder != null && adapterClass != null) {
        List<PersistenceProviderAdaptor> persistenceProviderAdaptors = persistenceProviderDeploymentHolder.getAdapters();
        for (PersistenceProviderAdaptor persistenceProviderAdaptor : persistenceProviderAdaptors) {
            if (adapterClass.equals(persistenceProviderAdaptor.getClass().getName())) {
                return persistenceProviderAdaptor;
            }
        }
    }
    String adaptorModule = pu.getProperties().getProperty(Configuration.ADAPTER_MODULE);
    PersistenceProviderAdaptor adaptor;
    adaptor = getPerDeploymentSharedPersistenceProviderAdaptor(deploymentUnit, adaptorModule, provider);
    if (adaptor == null) {
        try {
            // are handled externally via properties or code in the persistence provider).
            if (adaptorModule != null) {
                // legacy way of loading adapter module
                adaptor = PersistenceProviderAdaptorLoader.loadPersistenceAdapterModule(adaptorModule, platform, createManager(deploymentUnit));
            } else {
                adaptor = PersistenceProviderAdaptorLoader.loadPersistenceAdapter(provider, platform, createManager(deploymentUnit));
            }
        } catch (ModuleLoadException e) {
            throw JpaLogger.ROOT_LOGGER.persistenceProviderAdaptorModuleLoadError(e, adaptorModule);
        }
        adaptor = savePerDeploymentSharedPersistenceProviderAdaptor(deploymentUnit, adaptorModule, adaptor, provider);
    }
    if (adaptor == null) {
        throw JpaLogger.ROOT_LOGGER.failedToGetAdapter(pu.getPersistenceProviderClassName());
    }
    return adaptor;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 8 with ModuleLoadException

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

the class JSFSharedTldsProcessor method init.

private void init() {
    JSFModuleIdFactory moduleFactory = JSFModuleIdFactory.getInstance();
    List<String> jsfSlotNames = moduleFactory.getActiveJSFVersions();
    for (String slot : jsfSlotNames) {
        final List<TldMetaData> jsfTlds = new ArrayList<TldMetaData>();
        try {
            ModuleClassLoader jsf = Module.getModuleFromCallerModuleLoader(moduleFactory.getImplModId(slot)).getClassLoader();
            for (String tld : JSF_TAGLIBS) {
                InputStream is = jsf.getResourceAsStream("META-INF/" + tld);
                if (is != null) {
                    TldMetaData tldMetaData = parseTLD(is);
                    jsfTlds.add(tldMetaData);
                }
            }
        } catch (ModuleLoadException e) {
        // Ignore
        } catch (Exception e) {
        // Ignore
        }
        jsfTldMap.put(slot, jsfTlds);
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 9 with ModuleLoadException

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

the class JMSBridgeAdd method createJMSBridge.

private JMSBridge createJMSBridge(OperationContext context, ModelNode model) throws OperationFailedException {
    final Properties sourceContextProperties = resolveContextProperties(JMSBridgeDefinition.SOURCE_CONTEXT, context, model);
    final String sourceConnectionFactoryName = JMSBridgeDefinition.SOURCE_CONNECTION_FACTORY.resolveModelAttribute(context, model).asString();
    final ConnectionFactoryFactory sourceCff = new JNDIConnectionFactoryFactory(sourceContextProperties, sourceConnectionFactoryName);
    final String sourceDestinationName = JMSBridgeDefinition.SOURCE_DESTINATION.resolveModelAttribute(context, model).asString();
    final DestinationFactory sourceDestinationFactory = new JNDIDestinationFactory(sourceContextProperties, sourceDestinationName);
    final Properties targetContextProperties = resolveContextProperties(JMSBridgeDefinition.TARGET_CONTEXT, context, model);
    final String targetConnectionFactoryName = JMSBridgeDefinition.TARGET_CONNECTION_FACTORY.resolveModelAttribute(context, model).asString();
    final ConnectionFactoryFactory targetCff = new JNDIConnectionFactoryFactory(targetContextProperties, targetConnectionFactoryName);
    final String targetDestinationName = JMSBridgeDefinition.TARGET_DESTINATION.resolveModelAttribute(context, model).asString();
    final DestinationFactory targetDestinationFactory = new JNDIDestinationFactory(targetContextProperties, targetDestinationName);
    final String sourceUsername = resolveAttribute(JMSBridgeDefinition.SOURCE_USER, context, model);
    final String sourcePassword = resolveAttribute(JMSBridgeDefinition.SOURCE_PASSWORD, context, model);
    final String targetUsername = resolveAttribute(JMSBridgeDefinition.TARGET_USER, context, model);
    final String targetPassword = resolveAttribute(JMSBridgeDefinition.TARGET_PASSWORD, context, model);
    final String selector = resolveAttribute(CommonAttributes.SELECTOR, context, model);
    final long failureRetryInterval = JMSBridgeDefinition.FAILURE_RETRY_INTERVAL.resolveModelAttribute(context, model).asLong();
    final int maxRetries = JMSBridgeDefinition.MAX_RETRIES.resolveModelAttribute(context, model).asInt();
    final QualityOfServiceMode qosMode = QualityOfServiceMode.valueOf(JMSBridgeDefinition.QUALITY_OF_SERVICE.resolveModelAttribute(context, model).asString());
    final int maxBatchSize = JMSBridgeDefinition.MAX_BATCH_SIZE.resolveModelAttribute(context, model).asInt();
    final long maxBatchTime = JMSBridgeDefinition.MAX_BATCH_TIME.resolveModelAttribute(context, model).asLong();
    final String subName = resolveAttribute(JMSBridgeDefinition.SUBSCRIPTION_NAME, context, model);
    final String clientID = resolveAttribute(JMSBridgeDefinition.CLIENT_ID, context, model);
    final boolean addMessageIDInHeader = JMSBridgeDefinition.ADD_MESSAGE_ID_IN_HEADER.resolveModelAttribute(context, model).asBoolean();
    final String moduleName = resolveAttribute(JMSBridgeDefinition.MODULE, context, model);
    final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        // will use the correct class loader to execute its threads
        if (moduleName != null) {
            ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName);
            Module module = Module.getCallerModuleLoader().loadModule(moduleID);
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
        }
        return new JMSBridgeImpl(sourceCff, targetCff, sourceDestinationFactory, targetDestinationFactory, sourceUsername, sourcePassword, targetUsername, targetPassword, selector, failureRetryInterval, maxRetries, qosMode, maxBatchSize, maxBatchTime, subName, clientID, addMessageIDInHeader);
    } catch (ModuleLoadException e) {
        throw MessagingLogger.ROOT_LOGGER.unableToLoadModule(moduleName, e);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) JNDIDestinationFactory(org.apache.activemq.artemis.jms.bridge.impl.JNDIDestinationFactory) DestinationFactory(org.apache.activemq.artemis.jms.bridge.DestinationFactory) JNDIConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.impl.JNDIConnectionFactoryFactory) JMSBridgeImpl(org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl) QualityOfServiceMode(org.apache.activemq.artemis.jms.bridge.QualityOfServiceMode) Properties(java.util.Properties) JNDIDestinationFactory(org.apache.activemq.artemis.jms.bridge.impl.JNDIDestinationFactory) JNDIConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.impl.JNDIConnectionFactoryFactory) ConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module)

Example 10 with ModuleLoadException

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

the class NamingBindingAdd method createObjectFactory.

private ObjectFactory createObjectFactory(OperationContext context, ModelNode model) throws OperationFailedException {
    final ModuleIdentifier moduleID = ModuleIdentifier.fromString(NamingBindingResourceDefinition.MODULE.resolveModelAttribute(context, model).asString());
    final String className = NamingBindingResourceDefinition.CLASS.resolveModelAttribute(context, model).asString();
    final Module module;
    try {
        module = Module.getBootModuleLoader().loadModule(moduleID);
    } catch (ModuleLoadException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotLoadModule(moduleID);
    }
    final ObjectFactory objectFactoryClassInstance;
    final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
        final Class<?> clazz = module.getClassLoader().loadClass(className);
        objectFactoryClassInstance = (ObjectFactory) clazz.newInstance();
    } catch (ClassNotFoundException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotLoadClassFromModule(className, moduleID);
    } catch (InstantiationException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
    } catch (IllegalAccessException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
    } catch (ClassCastException e) {
        throw NamingLogger.ROOT_LOGGER.notAnInstanceOfObjectFactory(className, moduleID);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
    }
    return objectFactoryClassInstance;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module)

Aggregations

ModuleLoadException (org.jboss.modules.ModuleLoadException)18 Module (org.jboss.modules.Module)11 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)6 IOException (java.io.IOException)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)3 WarMetaData (org.jboss.as.web.common.WarMetaData)3 ModuleClassLoader (org.jboss.modules.ModuleClassLoader)3 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Driver (java.sql.Driver)2 HashSet (java.util.HashSet)2 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)2 ModelNode (org.jboss.dmr.ModelNode)2 TldMetaData (org.jboss.metadata.web.spec.TldMetaData)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 VirtualFile (org.jboss.vfs.VirtualFile)2