Search in sources :

Example 21 with EEApplicationClasses

use of org.jboss.as.ee.component.EEApplicationClasses in project wildfly by wildfly.

the class EJBContainerInterceptorsViewConfigurator method doConfigure.

private void doConfigure(final DeploymentPhaseContext context, final EJBComponentDescription ejbComponentDescription, final ViewConfiguration viewConfiguration) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final Map<String, List<InterceptorFactory>> userAroundInvokesByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
    final Map<String, List<InterceptorFactory>> userAroundTimeoutsByInterceptorClass;
    if (ejbComponentDescription.isTimerServiceRequired()) {
        userAroundTimeoutsByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
    } else {
        userAroundTimeoutsByInterceptorClass = null;
    }
    // info
    for (final InterceptorDescription interceptorDescription : ejbComponentDescription.getAllContainerInterceptors()) {
        final String interceptorClassName = interceptorDescription.getInterceptorClassName();
        final Class<?> intereptorClass;
        try {
            intereptorClass = ClassLoadingUtils.loadClass(interceptorClassName, module);
        } catch (ClassNotFoundException e) {
            throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptorClassName);
        }
        // run the interceptor class (and its super class hierarchy) through the InterceptorClassDescriptionTraversal so that it can
        // find the relevant @AroundInvoke/@AroundTimeout methods
        final InterceptorClassDescriptionTraversal interceptorClassDescriptionTraversal = new InterceptorClassDescriptionTraversal(intereptorClass, applicationClasses, deploymentUnit, ejbComponentDescription);
        interceptorClassDescriptionTraversal.run();
        // now that the InterceptorClassDescriptionTraversal has done the relevant processing, keep track of the @AroundInvoke and
        // @AroundTimeout methods applicable for this interceptor class, within a map
        final List<InterceptorFactory> aroundInvokeInterceptorFactories = interceptorClassDescriptionTraversal.getAroundInvokeInterceptorFactories();
        if (aroundInvokeInterceptorFactories != null) {
            userAroundInvokesByInterceptorClass.put(interceptorClassName, aroundInvokeInterceptorFactories);
        }
        if (ejbComponentDescription.isTimerServiceRequired()) {
            final List<InterceptorFactory> aroundTimeoutInterceptorFactories = interceptorClassDescriptionTraversal.getAroundTimeoutInterceptorFactories();
            if (aroundTimeoutInterceptorFactories != null) {
                userAroundTimeoutsByInterceptorClass.put(interceptorClassName, aroundTimeoutInterceptorFactories);
            }
        }
    }
    // At this point we have each interceptor class mapped against their corresponding @AroundInvoke/@AroundTimeout InterceptorFactory(s)
    // Let's now iterate over all the methods of the EJB view and apply the relevant InterceptorFactory(s) to that method
    final List<InterceptorDescription> classLevelContainerInterceptors = ejbComponentDescription.getClassLevelContainerInterceptors();
    final Map<MethodIdentifier, List<InterceptorDescription>> methodLevelContainerInterceptors = ejbComponentDescription.getMethodLevelContainerInterceptors();
    final List<Method> viewMethods = viewConfiguration.getProxyFactory().getCachedMethods();
    for (final Method method : viewMethods) {
        final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes());
        final List<InterceptorFactory> aroundInvokesApplicableForMethod = new ArrayList<InterceptorFactory>();
        final List<InterceptorFactory> aroundTimeoutsApplicableForMethod = new ArrayList<InterceptorFactory>();
        // first add the default interceptors (if not excluded) to the deque
        if (!ejbComponentDescription.isExcludeDefaultContainerInterceptors() && !ejbComponentDescription.isExcludeDefaultContainerInterceptors(methodIdentifier)) {
            for (final InterceptorDescription interceptorDescription : ejbComponentDescription.getDefaultContainerInterceptors()) {
                String interceptorClassName = interceptorDescription.getInterceptorClassName();
                final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                if (aroundInvokesOnInterceptor != null) {
                    aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
                }
                if (ejbComponentDescription.isTimerServiceRequired()) {
                    final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                    if (aroundTimeoutsOnInterceptor != null) {
                        aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
                    }
                }
            }
        }
        // now add class level interceptors (if not excluded) to the deque
        if (!ejbComponentDescription.isExcludeClassLevelContainerInterceptors(methodIdentifier)) {
            for (final InterceptorDescription interceptorDescription : classLevelContainerInterceptors) {
                String interceptorClassName = interceptorDescription.getInterceptorClassName();
                final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                if (aroundInvokesOnInterceptor != null) {
                    aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
                }
                if (ejbComponentDescription.isTimerServiceRequired()) {
                    final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                    if (aroundTimeoutsOnInterceptor != null) {
                        aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
                    }
                }
            }
        }
        // now add method level interceptors for to the deque so that they are triggered after the class interceptors
        final List<InterceptorDescription> interceptorsForMethod = methodLevelContainerInterceptors.get(methodIdentifier);
        if (interceptorsForMethod != null) {
            for (final InterceptorDescription methodLevelInterceptor : interceptorsForMethod) {
                String interceptorClassName = methodLevelInterceptor.getInterceptorClassName();
                final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                if (aroundInvokesOnInterceptor != null) {
                    aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
                }
                if (ejbComponentDescription.isTimerServiceRequired()) {
                    final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                    if (aroundTimeoutsOnInterceptor != null) {
                        aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
                    }
                }
            }
        }
        // apply the interceptors to the view's method.
        viewConfiguration.addViewInterceptor(method, new UserInterceptorFactory(weaved(aroundInvokesApplicableForMethod), weaved(aroundTimeoutsApplicableForMethod)), InterceptorOrder.View.USER_APP_SPECIFIC_CONTAINER_INTERCEPTORS);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) InterceptorFactory(org.jboss.invocation.InterceptorFactory) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) ArrayList(java.util.ArrayList) List(java.util.List) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 22 with EEApplicationClasses

use of org.jboss.as.ee.component.EEApplicationClasses in project wildfly by wildfly.

the class SingletonComponentDescription method createConfiguration.

@Override
public ComponentConfiguration createConfiguration(final ClassReflectionIndex classIndex, final ClassLoader moduleClassLoader, final ModuleLoader moduleLoader) {
    ComponentConfiguration singletonComponentConfiguration = new ComponentConfiguration(this, classIndex, moduleClassLoader, moduleLoader);
    // setup the component create service
    singletonComponentConfiguration.setComponentCreateServiceFactory(new SingletonComponentCreateServiceFactory(this.isInitOnStartup(), dependsOn));
    if (isExplicitSecurityDomainConfigured()) {
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
                String contextID = deploymentUnit.getName();
                if (deploymentUnit.getParent() != null) {
                    contextID = deploymentUnit.getParent().getName() + "!" + contextID;
                }
                EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
                if (isSecurityDomainKnown()) {
                    final HashMap<Integer, InterceptorFactory> elytronInterceptorFactories = getElytronInterceptorFactories(contextID, ejbComponentDescription.isEnableJacc());
                    elytronInterceptorFactories.forEach((priority, elytronInterceptorFactory) -> configuration.addPostConstructInterceptor(elytronInterceptorFactory, priority));
                } else {
                    configuration.addPostConstructInterceptor(new SecurityContextInterceptorFactory(isExplicitSecurityDomainConfigured(), false, contextID), InterceptorOrder.View.SECURITY_CONTEXT);
                }
            }
        });
    }
    getConfigurators().add(new ComponentConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
            if (isInitOnStartup()) {
                final StartupCountdown startupCountdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
                configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new StartupCountDownInterceptor(startupCountdown)), InterceptorOrder.ComponentPostConstruct.STARTUP_COUNTDOWN_INTERCEPTOR);
            }
        }
    });
    if (getTransactionManagementType().equals(TransactionManagementType.CONTAINER)) {
        //we need to add the transaction interceptor to the lifecycle methods
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final EEApplicationClasses applicationClasses = context.getDeploymentUnit().getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
                InterceptorClassDescription interceptorConfig = ComponentDescription.mergeInterceptorConfig(configuration.getComponentClass(), applicationClasses.getClassByName(description.getComponentClassName()), description, MetadataCompleteMarker.isMetadataComplete(context.getDeploymentUnit()));
                if (interceptorConfig.getPostConstruct() != null) {
                    configuration.addPostConstructInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPostConstruct(), true), InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
                }
                configuration.addPreDestroyInterceptor(new LifecycleCMTTxInterceptor.Factory(interceptorConfig.getPreDestroy(), true), InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
                configuration.addTimeoutViewInterceptor(TimerCMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
            }
        });
    } else {
        // add the bmt interceptor
        getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                configuration.addPostConstructInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
                configuration.addPreDestroyInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
                // add the bmt interceptor factory
                configuration.addComponentInterceptor(EjbBMTInterceptor.FACTORY, InterceptorOrder.Component.BMT_TRANSACTION_INTERCEPTOR, false);
            }
        });
    }
    return singletonComponentConfiguration;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ConcurrencyManagementType(javax.ejb.ConcurrencyManagementType) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) LifecycleCMTTxInterceptor(org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor) HashMap(java.util.HashMap) WriteReplaceInterface(org.jboss.as.ee.component.serialization.WriteReplaceInterface) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) StatelessWriteReplaceInterceptor(org.jboss.as.ejb3.component.session.StatelessWriteReplaceInterceptor) ArrayList(java.util.ArrayList) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) InterceptorOrder(org.jboss.as.ee.component.interceptors.InterceptorOrder) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) Method(java.lang.reflect.Method) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) ModuleLoader(org.jboss.modules.ModuleLoader) MetadataCompleteMarker(org.jboss.as.ee.metadata.MetadataCompleteMarker) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ContainerManagedConcurrencyInterceptorFactory(org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptorFactory) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown) StatelessRemoteViewInstanceFactory(org.jboss.as.ejb3.component.session.StatelessRemoteViewInstanceFactory) SecurityContextInterceptorFactory(org.jboss.as.ejb3.security.SecurityContextInterceptorFactory) TimerCMTTxInterceptor(org.jboss.as.ejb3.tx.TimerCMTTxInterceptor) EjbBMTInterceptor(org.jboss.as.ejb3.tx.EjbBMTInterceptor) Attachments(org.jboss.as.ee.component.Attachments) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) List(java.util.List) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EjbLogger(org.jboss.as.ejb3.logging.EjbLogger) ServiceName(org.jboss.msc.service.ServiceName) ViewDescription(org.jboss.as.ee.component.ViewDescription) Collections(java.util.Collections) TransactionManagementType(javax.ejb.TransactionManagementType) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) HashMap(java.util.HashMap) ComponentTypeIdentityInterceptorFactory(org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ContainerManagedConcurrencyInterceptorFactory(org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptorFactory) StatelessRemoteViewInstanceFactory(org.jboss.as.ejb3.component.session.StatelessRemoteViewInstanceFactory) SecurityContextInterceptorFactory(org.jboss.as.ejb3.security.SecurityContextInterceptorFactory) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) SecurityContextInterceptorFactory(org.jboss.as.ejb3.security.SecurityContextInterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown)

Example 23 with EEApplicationClasses

use of org.jboss.as.ee.component.EEApplicationClasses in project wildfly by wildfly.

the class Utils method registerAsComponent.

public static void registerAsComponent(String listener, DeploymentUnit deploymentUnit) {
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final EEModuleDescription module = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final WebComponentDescription componentDescription = new WebComponentDescription(listener, listener, module, deploymentUnit.getServiceName(), applicationClasses);
    module.addComponent(componentDescription);
    deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, componentDescription.getStartServiceName());
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses)

Example 24 with EEApplicationClasses

use of org.jboss.as.ee.component.EEApplicationClasses in project wildfly by wildfly.

the class ServiceComponentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final JBossServiceXmlDescriptor serviceXmlDescriptor = deploymentUnit.getAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY);
    if (serviceXmlDescriptor == null) {
        // Skip deployments without a service xml descriptor
        return;
    }
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        // not an EE deployment
        return;
    }
    final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final Map<String, ServiceComponentInstantiator> serviceComponents = new HashMap<String, ServiceComponentInstantiator>();
    for (final JBossServiceConfig serviceConfig : serviceXmlDescriptor.getServiceConfigs()) {
        ServiceComponentDescription componentDescription = new ServiceComponentDescription(serviceConfig.getName(), serviceConfig.getCode(), moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
        moduleDescription.addComponent(componentDescription);
        serviceComponents.put(serviceConfig.getName(), new ServiceComponentInstantiator(deploymentUnit, componentDescription));
    }
    deploymentUnit.putAttachment(ServiceAttachments.SERVICE_COMPONENT_INSTANTIATORS, serviceComponents);
}
Also used : JBossServiceXmlDescriptor(org.jboss.as.service.descriptor.JBossServiceXmlDescriptor) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) HashMap(java.util.HashMap) JBossServiceConfig(org.jboss.as.service.descriptor.JBossServiceConfig) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)24 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)19 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)18 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)9 Module (org.jboss.modules.Module)9 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)7 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)6 HashMap (java.util.HashMap)5 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)5 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)4 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)4 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)4 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)3 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)3 ComponentTypeIdentityInterceptorFactory (org.jboss.as.ejb3.component.interceptors.ComponentTypeIdentityInterceptorFactory)3 AnnotationInstance (org.jboss.jandex.AnnotationInstance)3