Search in sources :

Example 6 with Module

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

the class JSFAnnotationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Map<Class<? extends Annotation>, Set<Class<?>>> instances = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        // Can not continue without index
        return;
    }
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        // Can not continue without module
        return;
    }
    final ClassLoader classLoader = module.getClassLoader();
    for (FacesAnnotation annotation : FacesAnnotation.values()) {
        final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName);
        if (annotationInstances == null || annotationInstances.isEmpty()) {
            continue;
        }
        final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
        instances.put(annotation.annotationClass, discoveredClasses);
        for (AnnotationInstance annotationInstance : annotationInstances) {
            final AnnotationTarget target = annotationInstance.target();
            if (target instanceof ClassInfo) {
                final DotName className = ClassInfo.class.cast(target).name();
                final Class<?> annotatedClass;
                try {
                    annotatedClass = classLoader.loadClass(className.toString());
                } catch (ClassNotFoundException e) {
                    throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.classLoadingFailed(className));
                }
                discoveredClasses.add(annotatedClass);
            } else {
                throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidAnnotationLocation(annotation, target));
            }
        }
    }
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) Annotation(java.lang.annotation.Annotation) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 7 with Module

use of org.jboss.modules.Module 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 8 with Module

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

the class JMSBridgeService method startBridge.

public void startBridge() throws Exception {
    final Module module;
    if (moduleName != null) {
        ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName);
        module = Module.getContextModuleLoader().loadModule(moduleID);
    } else {
        module = Module.forClass(JMSBridgeService.class);
    }
    ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
        setJMSBridgePasswordsFromCredentialSource();
        bridge.start();
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
    MessagingLogger.ROOT_LOGGER.startedService("JMS Bridge", bridgeName);
}
Also used : ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module)

Example 9 with Module

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

the class ObjectFactoryBuilder method factoryFromModularReference.

private ObjectFactory factoryFromModularReference(ModularReference modularReference, final Hashtable<?, ?> environment) throws Exception {
    final Module module = Module.getCallerModuleLoader().loadModule(modularReference.getModuleIdentifier());
    final ClassLoader classLoader = module.getClassLoader();
    return factoryFromReference(modularReference, classLoader, environment);
}
Also used : Module(org.jboss.modules.Module)

Example 10 with Module

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

the class ExternalContextObjectFactory method createContext.

private Context createContext(final Hashtable<?, ?> environment, boolean useProxy) throws NamingException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, ModuleLoadException {
    String initialContextClassName = (String) environment.get(INITIAL_CONTEXT_CLASS);
    String initialContextModule = (String) environment.get(INITIAL_CONTEXT_MODULE);
    final boolean useStringLokup = useStringLookup(environment);
    final Hashtable<?, ?> newEnvironment = new Hashtable<>(environment);
    newEnvironment.remove(CACHE_CONTEXT);
    newEnvironment.remove(INITIAL_CONTEXT_CLASS);
    newEnvironment.remove(INITIAL_CONTEXT_MODULE);
    newEnvironment.remove(LOOKUP_BY_STRING);
    ClassLoader loader;
    if (!WildFlySecurityManager.isChecking()) {
        loader = getClass().getClassLoader();
    } else {
        loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

            @Override
            public ClassLoader run() {
                return getClass().getClassLoader();
            }
        });
    }
    Class initialContextClass = null;
    final Context loadedContext;
    if (initialContextModule == null) {
        initialContextClass = Class.forName(initialContextClassName);
        Constructor ctor = initialContextClass.getConstructor(Hashtable.class);
        loadedContext = (Context) ctor.newInstance(newEnvironment);
    } else {
        Module module = Module.getBootModuleLoader().loadModule(ModuleIdentifier.fromString(initialContextModule));
        loader = module.getClassLoader();
        final ClassLoader currentClassLoader = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
        try {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(loader);
            initialContextClass = Class.forName(initialContextClassName, true, loader);
            Constructor ctor = initialContextClass.getConstructor(Hashtable.class);
            loadedContext = (Context) ctor.newInstance(newEnvironment);
        } finally {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(currentClassLoader);
        }
    }
    final Context context;
    if (useStringLokup) {
        context = new LookupByStringContext(loadedContext);
    } else {
        context = loadedContext;
    }
    if (!useProxy) {
        return context;
    }
    ProxyConfiguration config = new ProxyConfiguration();
    config.setClassLoader(loader);
    config.setSuperClass(initialContextClass);
    config.setProxyName(initialContextClassName + "$$$$Proxy" + PROXY_ID.incrementAndGet());
    config.setProtectionDomain(context.getClass().getProtectionDomain());
    ProxyFactory<?> factory = new ProxyFactory<Object>(config);
    return (Context) factory.newInstance(new CachedContext(context));
}
Also used : Context(javax.naming.Context) ProxyFactory(org.jboss.invocation.proxy.ProxyFactory) Hashtable(java.util.Hashtable) Constructor(java.lang.reflect.Constructor) ProxyConfiguration(org.jboss.invocation.proxy.ProxyConfiguration) PrivilegedAction(java.security.PrivilegedAction) 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