Search in sources :

Example 6 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class SecurityDomainMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription description) throws DeploymentUnitProcessingException {
    String securityDomain = getJBossAppSecurityDomain(deploymentUnit);
    String globalSecurityDomain = null;
    final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbJarMetaData != null) {
        final AssemblyDescriptorMetaData assemblyMetadata = ejbJarMetaData.getAssemblyDescriptor();
        if (assemblyMetadata != null) {
            final List<EJBBoundSecurityMetaData> securityMetaDatas = assemblyMetadata.getAny(EJBBoundSecurityMetaData.class);
            if (securityMetaDatas != null) {
                for (final EJBBoundSecurityMetaData securityMetaData : securityMetaDatas) {
                    if (securityMetaData.getEjbName().equals(description.getComponentName())) {
                        securityDomain = securityMetaData.getSecurityDomain();
                        break;
                    }
                    // check global security domain
                    if (securityMetaData.getEjbName().equals("*")) {
                        globalSecurityDomain = securityMetaData.getSecurityDomain();
                        continue;
                    }
                }
            }
        }
    }
    if (securityDomain != null)
        description.setSecurityDomain(securityDomain);
    else if (globalSecurityDomain != null)
        description.setSecurityDomain(globalSecurityDomain);
}
Also used : EJBBoundSecurityMetaData(org.jboss.as.ejb3.security.metadata.EJBBoundSecurityMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) AssemblyDescriptorMetaData(org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData)

Example 7 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class AbstractEjbXmlDescriptorProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    // get the deployment unit
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // find the EJB jar metadata and start processing it
    EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbJarMetaData == null) {
        return;
    }
    // process EJBs
    EnterpriseBeansMetaData ejbs = ejbJarMetaData.getEnterpriseBeans();
    if (ejbs != null && !ejbs.isEmpty()) {
        for (EnterpriseBeanMetaData ejb : ejbs) {
            if (this.getMetaDataType().isInstance(ejb)) {
                this.processBeanMetaData((T) ejb, phaseContext);
            }
        }
    }
}
Also used : EnterpriseBeansMetaData(org.jboss.metadata.ejb.spec.EnterpriseBeansMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) EnterpriseBeanMetaData(org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 8 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class ContainerInterceptorBindingsDDProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (metaData == null || metaData.getAssemblyDescriptor() == null) {
        return;
    }
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final DeploymentReflectionIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    // fetch the container-interceptors
    final List<ContainerInterceptorsMetaData> containerInterceptorConfigurations = metaData.getAssemblyDescriptor().getAny(ContainerInterceptorsMetaData.class);
    if (containerInterceptorConfigurations == null || containerInterceptorConfigurations.isEmpty()) {
        return;
    }
    final ContainerInterceptorsMetaData containerInterceptorsMetaData = containerInterceptorConfigurations.get(0);
    if (containerInterceptorsMetaData == null) {
        return;
    }
    final InterceptorBindingsMetaData containerInterceptorBindings = containerInterceptorsMetaData.getInterceptorBindings();
    // no interceptor-binding == nothing to do
    if (containerInterceptorBindings == null || containerInterceptorBindings.isEmpty()) {
        return;
    }
    // we have now found some container interceptors which are bound to certain EJBs, start the real work!
    final Map<String, List<InterceptorBindingMetaData>> bindingsPerEJB = new HashMap<String, List<InterceptorBindingMetaData>>();
    final List<InterceptorBindingMetaData> bindingsForAllEJBs = new ArrayList<InterceptorBindingMetaData>();
    for (final InterceptorBindingMetaData containerInterceptorBinding : containerInterceptorBindings) {
        if (containerInterceptorBinding.getEjbName().equals("*")) {
            // since all EJBs having the same method is not really practical
            if (containerInterceptorBinding.getMethod() != null) {
                throw EjbLogger.ROOT_LOGGER.defaultInterceptorsNotBindToMethod();
            }
            if (containerInterceptorBinding.getInterceptorOrder() != null) {
                throw EjbLogger.ROOT_LOGGER.defaultInterceptorsNotSpecifyOrder();
            }
            // Make a note that this container interceptor binding is applicable for all EJBs
            bindingsForAllEJBs.add(containerInterceptorBinding);
        } else {
            // fetch existing container interceptor bindings for the EJB, if any.
            List<InterceptorBindingMetaData> bindings = bindingsPerEJB.get(containerInterceptorBinding.getEjbName());
            if (bindings == null) {
                bindings = new ArrayList<InterceptorBindingMetaData>();
                bindingsPerEJB.put(containerInterceptorBinding.getEjbName(), bindings);
            }
            // Make a note that the container interceptor binding is applicable for this specific EJB
            bindings.add(containerInterceptorBinding);
        }
    }
    // At this point we now know which container interceptor bindings have been configured for which EJBs.
    // Next, we create InterceptorDescription(s) out of those.
    final List<InterceptorDescription> interceptorDescriptionsForAllEJBs = new ArrayList<InterceptorDescription>();
    // first process container interceptors applicable for all EJBs
    for (InterceptorBindingMetaData binding : bindingsForAllEJBs) {
        if (binding.getInterceptorClasses() != null) {
            for (final String clazz : binding.getInterceptorClasses()) {
                interceptorDescriptionsForAllEJBs.add(new InterceptorDescription(clazz));
            }
        }
    }
    // Now process container interceptors for each EJB
    for (final ComponentDescription componentDescription : eeModuleDescription.getComponentDescriptions()) {
        if (!(componentDescription instanceof EJBComponentDescription)) {
            continue;
        }
        final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
        final Class<?> componentClass;
        try {
            componentClass = module.getClassLoader().loadClass(ejbComponentDescription.getComponentClassName());
        } catch (ClassNotFoundException e) {
            throw EjbLogger.ROOT_LOGGER.failToLoadComponentClass(e, ejbComponentDescription.getComponentClassName());
        }
        final List<InterceptorBindingMetaData> bindingsApplicableForCurrentEJB = bindingsPerEJB.get(ejbComponentDescription.getComponentName());
        final Map<Method, List<InterceptorBindingMetaData>> methodInterceptors = new HashMap<Method, List<InterceptorBindingMetaData>>();
        final List<InterceptorBindingMetaData> classLevelBindings = new ArrayList<InterceptorBindingMetaData>();
        // we only want to exclude default and class level interceptors if every binding
        // has the exclude element.
        boolean classLevelExcludeDefaultInterceptors = false;
        Map<Method, Boolean> methodLevelExcludeDefaultInterceptors = new HashMap<Method, Boolean>();
        Map<Method, Boolean> methodLevelExcludeClassInterceptors = new HashMap<Method, Boolean>();
        // if an absolute order has been defined at any level then absolute ordering takes precedence
        boolean classLevelAbsoluteOrder = false;
        final Map<Method, Boolean> methodLevelAbsoluteOrder = new HashMap<Method, Boolean>();
        if (bindingsApplicableForCurrentEJB != null) {
            for (final InterceptorBindingMetaData binding : bindingsApplicableForCurrentEJB) {
                if (binding.getMethod() == null) {
                    // The container interceptor is expected to be fired for all methods of that EJB
                    classLevelBindings.add(binding);
                    // if even one binding does not say exclude default then we do not exclude
                    if (binding.isExcludeDefaultInterceptors()) {
                        classLevelExcludeDefaultInterceptors = true;
                    }
                    if (binding.isTotalOrdering()) {
                        if (classLevelAbsoluteOrder) {
                            throw EjbLogger.ROOT_LOGGER.twoEjbBindingsSpecifyAbsoluteOrder(componentClass.toString());
                        } else {
                            classLevelAbsoluteOrder = true;
                        }
                    }
                } else {
                    // Method level bindings
                    // First find the right method
                    final NamedMethodMetaData methodData = binding.getMethod();
                    final ClassReflectionIndex classIndex = index.getClassIndex(componentClass);
                    Method resolvedMethod = null;
                    if (methodData.getMethodParams() == null) {
                        final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName());
                        if (methods.isEmpty()) {
                            throw EjbLogger.ROOT_LOGGER.failToFindMethodInEjbJarXml(componentClass.getName(), methodData.getMethodName());
                        } else if (methods.size() > 1) {
                            throw EjbLogger.ROOT_LOGGER.multipleMethodReferencedInEjbJarXml(methodData.getMethodName(), componentClass.getName());
                        }
                        resolvedMethod = methods.iterator().next();
                    } else {
                        final Collection<Method> methods = classIndex.getAllMethods(methodData.getMethodName(), methodData.getMethodParams().size());
                        for (final Method method : methods) {
                            boolean match = true;
                            for (int i = 0; i < method.getParameterTypes().length; ++i) {
                                if (!method.getParameterTypes()[i].getName().equals(methodData.getMethodParams().get(i))) {
                                    match = false;
                                    break;
                                }
                            }
                            if (match) {
                                resolvedMethod = method;
                                break;
                            }
                        }
                        if (resolvedMethod == null) {
                            throw EjbLogger.ROOT_LOGGER.failToFindMethodWithParameterTypes(componentClass.getName(), methodData.getMethodName(), methodData.getMethodParams());
                        }
                    }
                    List<InterceptorBindingMetaData> methodSpecificInterceptorBindings = methodInterceptors.get(resolvedMethod);
                    if (methodSpecificInterceptorBindings == null) {
                        methodSpecificInterceptorBindings = new ArrayList<InterceptorBindingMetaData>();
                        methodInterceptors.put(resolvedMethod, methodSpecificInterceptorBindings);
                    }
                    methodSpecificInterceptorBindings.add(binding);
                    if (binding.isExcludeDefaultInterceptors()) {
                        methodLevelExcludeDefaultInterceptors.put(resolvedMethod, true);
                    }
                    if (binding.isExcludeClassInterceptors()) {
                        methodLevelExcludeClassInterceptors.put(resolvedMethod, true);
                    }
                    if (binding.isTotalOrdering()) {
                        if (methodLevelAbsoluteOrder.containsKey(resolvedMethod)) {
                            throw EjbLogger.ROOT_LOGGER.twoEjbBindingsSpecifyAbsoluteOrder(resolvedMethod.toString());
                        } else {
                            methodLevelAbsoluteOrder.put(resolvedMethod, true);
                        }
                    }
                }
            }
        }
        // Now we have all the bindings in a format we can use
        // Build the list of default interceptors
        ejbComponentDescription.setDefaultContainerInterceptors(interceptorDescriptionsForAllEJBs);
        if (classLevelExcludeDefaultInterceptors) {
            ejbComponentDescription.setExcludeDefaultContainerInterceptors(true);
        }
        final List<InterceptorDescription> classLevelInterceptors = new ArrayList<InterceptorDescription>();
        if (classLevelAbsoluteOrder) {
            // We have an absolute ordering for the class level interceptors
            for (final InterceptorBindingMetaData binding : classLevelBindings) {
                // specify an ordering
                if (binding.isTotalOrdering()) {
                    for (final String interceptor : binding.getInterceptorOrder()) {
                        classLevelInterceptors.add(new InterceptorDescription(interceptor));
                    }
                    break;
                }
            }
            // We have merged the default interceptors into the class interceptors
            ejbComponentDescription.setExcludeDefaultContainerInterceptors(true);
        } else {
            for (InterceptorBindingMetaData binding : classLevelBindings) {
                if (binding.getInterceptorClasses() != null) {
                    for (final String interceptor : binding.getInterceptorClasses()) {
                        classLevelInterceptors.add(new InterceptorDescription(interceptor));
                    }
                }
            }
        }
        // We now know about the class level container interceptors for this EJB
        ejbComponentDescription.setClassLevelContainerInterceptors(classLevelInterceptors);
        // Now process method level container interceptors for the EJB
        for (Map.Entry<Method, List<InterceptorBindingMetaData>> entry : methodInterceptors.entrySet()) {
            final Method method = entry.getKey();
            final List<InterceptorBindingMetaData> methodBindings = entry.getValue();
            boolean totalOrder = methodLevelAbsoluteOrder.containsKey(method);
            final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
            Boolean excludeDefaultInterceptors = methodLevelExcludeDefaultInterceptors.get(method);
            excludeDefaultInterceptors = excludeDefaultInterceptors == null ? false : excludeDefaultInterceptors;
            if (!excludeDefaultInterceptors) {
                excludeDefaultInterceptors = ejbComponentDescription.isExcludeDefaultContainerInterceptors() || ejbComponentDescription.isExcludeDefaultContainerInterceptors(methodIdentifier);
            }
            Boolean excludeClassInterceptors = methodLevelExcludeClassInterceptors.get(method);
            excludeClassInterceptors = excludeClassInterceptors == null ? false : excludeClassInterceptors;
            if (!excludeClassInterceptors) {
                excludeClassInterceptors = ejbComponentDescription.isExcludeClassLevelContainerInterceptors(methodIdentifier);
            }
            final List<InterceptorDescription> methodLevelInterceptors = new ArrayList<InterceptorDescription>();
            if (totalOrder) {
                // If there is a total order we just use it
                for (final InterceptorBindingMetaData binding : methodBindings) {
                    if (binding.isTotalOrdering()) {
                        for (final String interceptor : binding.getInterceptorOrder()) {
                            methodLevelInterceptors.add(new InterceptorDescription(interceptor));
                        }
                    }
                }
            } else {
                // the method specific interceptors
                if (!excludeDefaultInterceptors) {
                    methodLevelInterceptors.addAll(interceptorDescriptionsForAllEJBs);
                }
                if (!excludeClassInterceptors) {
                    for (InterceptorDescription interceptor : classLevelInterceptors) {
                        methodLevelInterceptors.add(interceptor);
                    }
                }
                for (final InterceptorBindingMetaData binding : methodBindings) {
                    if (binding.getInterceptorClasses() != null) {
                        for (final String interceptor : binding.getInterceptorClasses()) {
                            methodLevelInterceptors.add(new InterceptorDescription(interceptor));
                        }
                    }
                }
            }
            // We have already taken component and default interceptors into account
            ejbComponentDescription.excludeClassLevelContainerInterceptors(methodIdentifier);
            ejbComponentDescription.excludeDefaultContainerInterceptors(methodIdentifier);
            ejbComponentDescription.setMethodContainerInterceptors(methodIdentifier, methodLevelInterceptors);
        }
    }
}
Also used : EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) HashMap(java.util.HashMap) InterceptorBindingMetaData(org.jboss.metadata.ejb.spec.InterceptorBindingMetaData) ArrayList(java.util.ArrayList) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ArrayList(java.util.ArrayList) List(java.util.List) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) NamedMethodMetaData(org.jboss.metadata.ejb.spec.NamedMethodMetaData) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) InterceptorBindingsMetaData(org.jboss.metadata.ejb.spec.InterceptorBindingsMetaData) Method(java.lang.reflect.Method) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) ContainerInterceptorsMetaData(org.jboss.as.ejb3.interceptor.ContainerInterceptorsMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class InterceptorClassDeploymentDescriptorProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (metaData == null) {
        return;
    }
    if (metaData.getInterceptors() == null) {
        return;
    }
    for (InterceptorMetaData interceptor : metaData.getInterceptors()) {
        String interceptorClassName = interceptor.getInterceptorClass();
        AroundInvokesMetaData aroundInvokes = interceptor.getAroundInvokes();
        if (aroundInvokes != null) {
            for (AroundInvokeMetaData aroundInvoke : aroundInvokes) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = aroundInvoke.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class);
                builder.setAroundInvoke(methodIdentifier);
                if (aroundInvoke.getClassName() == null || aroundInvoke.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(aroundInvoke.getClassName(), builder.build());
                }
            }
        }
        AroundTimeoutsMetaData aroundTimeouts = interceptor.getAroundTimeouts();
        if (aroundTimeouts != null) {
            for (AroundTimeoutMetaData aroundTimeout : aroundTimeouts) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = aroundTimeout.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class);
                builder.setAroundTimeout(methodIdentifier);
                if (aroundTimeout.getClassName() == null || aroundTimeout.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(aroundTimeout.getClassName(), builder.build());
                }
            }
        }
        // post-construct(s) of the interceptor configured (if any) in the deployment descriptor
        LifecycleCallbacksMetaData postConstructs = interceptor.getPostConstructs();
        if (postConstructs != null) {
            for (LifecycleCallbackMetaData postConstruct : postConstructs) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = postConstruct.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
                builder.setPostConstruct(methodIdentifier);
                if (postConstruct.getClassName() == null || postConstruct.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(postConstruct.getClassName(), builder.build());
                }
            }
        }
        // pre-destroy(s) of the interceptor configured (if any) in the deployment descriptor
        LifecycleCallbacksMetaData preDestroys = interceptor.getPreDestroys();
        if (preDestroys != null) {
            for (LifecycleCallbackMetaData preDestroy : preDestroys) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = preDestroy.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
                builder.setPreDestroy(methodIdentifier);
                if (preDestroy.getClassName() == null || preDestroy.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(preDestroy.getClassName(), builder.build());
                }
            }
        }
        // pre-passivates(s) of the interceptor configured (if any) in the deployment descriptor
        LifecycleCallbacksMetaData prePassivates = interceptor.getPrePassivates();
        if (prePassivates != null) {
            for (LifecycleCallbackMetaData prePassivate : prePassivates) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = prePassivate.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
                builder.setPrePassivate(methodIdentifier);
                if (prePassivate.getClassName() == null || prePassivate.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(prePassivate.getClassName(), builder.build());
                }
            }
        }
        // pre-passivates(s) of the interceptor configured (if any) in the deployment descriptor
        LifecycleCallbacksMetaData postActivates = interceptor.getPostActivates();
        if (postActivates != null) {
            for (LifecycleCallbackMetaData postActivate : postActivates) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = postActivate.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
                builder.setPostActivate(methodIdentifier);
                if (postActivate.getClassName() == null || postActivate.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(postActivate.getClassName(), builder.build());
                }
            }
        }
        if (interceptor.getJndiEnvironmentRefsGroup() != null) {
            final DeploymentDescriptorEnvironment environment = new DeploymentDescriptorEnvironment("java:comp/env", interceptor.getJndiEnvironmentRefsGroup());
            eeModuleDescription.addInterceptorEnvironment(interceptor.getInterceptorClass(), new InterceptorEnvironment(environment));
        }
    }
}
Also used : AroundInvokesMetaData(org.jboss.metadata.ejb.spec.AroundInvokesMetaData) AroundTimeoutsMetaData(org.jboss.metadata.ejb.spec.AroundTimeoutsMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) AroundInvokeMetaData(org.jboss.metadata.ejb.spec.AroundInvokeMetaData) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) InterceptorMetaData(org.jboss.metadata.ejb.spec.InterceptorMetaData) LifecycleCallbacksMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) LifecycleCallbackMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData) AroundTimeoutMetaData(org.jboss.metadata.ejb.spec.AroundTimeoutMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) InterceptorEnvironment(org.jboss.as.ee.component.InterceptorEnvironment)

Example 10 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class TimerServiceDeploymentProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    ServiceName defaultTimerPersistenceService = TimerPersistence.SERVICE_NAME.append(defaultTimerDataStore);
    final Map<String, ServiceName> timerPersistenceServices = new HashMap<String, ServiceName>();
    // if this is an EJB deployment then create an EJB module level TimerServiceRegistry which can be used by the timer services
    // of all EJB components that belong to this EJB module.
    final TimerServiceRegistry timerServiceRegistry = EjbDeploymentMarker.isEjbDeployment(deploymentUnit) ? new TimerServiceRegistry() : null;
    if (ejbJarMetaData != null && ejbJarMetaData.getAssemblyDescriptor() != null) {
        List<TimerServiceMetaData> timerService = ejbJarMetaData.getAssemblyDescriptor().getAny(TimerServiceMetaData.class);
        if (timerService != null) {
            for (TimerServiceMetaData data : timerService) {
                if (data.getEjbName().equals("*")) {
                    defaultTimerPersistenceService = TimerPersistence.SERVICE_NAME.append(data.getDataStoreName());
                } else {
                    timerPersistenceServices.put(data.getEjbName(), TimerPersistence.SERVICE_NAME.append(data.getDataStoreName()));
                }
            }
        }
    }
    final ServiceName finalDefaultTimerPersistenceService = defaultTimerPersistenceService;
    for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
        if (componentDescription.isTimerServiceApplicable()) {
            if (componentDescription.isTimerServiceRequired()) {
                //the component has timeout methods, it needs a 'real' timer service
                final String deploymentName;
                if (moduleDescription.getDistinctName() == null || moduleDescription.getDistinctName().length() == 0) {
                    deploymentName = moduleDescription.getApplicationName() + "." + moduleDescription.getModuleName();
                } else {
                    deploymentName = moduleDescription.getApplicationName() + "." + moduleDescription.getModuleName() + "." + moduleDescription.getDistinctName();
                }
                ROOT_LOGGER.debugf("Installing timer service for component %s", componentDescription.getComponentName());
                componentDescription.getConfigurators().add(new ComponentConfigurator() {

                    @Override
                    public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                        final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
                        final ServiceName invokerServiceName = ejbComponentDescription.getServiceName().append(TimedObjectInvokerImpl.SERVICE_NAME);
                        final TimedObjectInvokerImpl invoker = new TimedObjectInvokerImpl(deploymentName, module);
                        context.getServiceTarget().addService(invokerServiceName, invoker).addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, invoker.getEjbComponent()).install();
                        //install the timer create service
                        final ServiceName serviceName = componentDescription.getServiceName().append(TimerServiceImpl.SERVICE_NAME);
                        final TimerServiceImpl service = new TimerServiceImpl(ejbComponentDescription.getScheduleMethods(), serviceName, timerServiceRegistry);
                        final ServiceBuilder<javax.ejb.TimerService> createBuilder = context.getServiceTarget().addService(serviceName, service);
                        createBuilder.addDependency(TIMER_SERVICE_NAME, Timer.class, service.getTimerInjectedValue());
                        createBuilder.addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, service.getEjbComponentInjectedValue());
                        createBuilder.addDependency(timerServiceThreadPool, ExecutorService.class, service.getExecutorServiceInjectedValue());
                        if (timerPersistenceServices.containsKey(ejbComponentDescription.getEJBName())) {
                            createBuilder.addDependency(timerPersistenceServices.get(ejbComponentDescription.getEJBName()), TimerPersistence.class, service.getTimerPersistence());
                        } else {
                            createBuilder.addDependency(finalDefaultTimerPersistenceService, TimerPersistence.class, service.getTimerPersistence());
                        }
                        createBuilder.addDependency(invokerServiceName, TimedObjectInvoker.class, service.getTimedObjectInvoker());
                        createBuilder.install();
                        ejbComponentDescription.setTimerService(service);
                        //inject the timer service directly into the start service
                        configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                            @Override
                            public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                                serviceBuilder.addDependency(serviceName);
                            }
                        });
                    }
                });
            } else {
                //the EJB is of a type that could have a timer service, but has no timer methods.
                //just bind the non-functional timer service
                componentDescription.getConfigurators().add(new ComponentConfigurator() {

                    @Override
                    public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                        final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) description;
                        final ServiceName nonFunctionalTimerServiceName = NonFunctionalTimerService.serviceNameFor(ejbComponentDescription);
                        final NonFunctionalTimerService nonFunctionalTimerService;
                        if (ejbComponentDescription instanceof StatefulComponentDescription) {
                            // for stateful beans, use a different error message that gets thrown from the NonFunctionalTimerService
                            nonFunctionalTimerService = new NonFunctionalTimerService(EjbLogger.ROOT_LOGGER.timerServiceMethodNotAllowedForSFSB(ejbComponentDescription.getComponentName()), timerServiceRegistry);
                        } else {
                            nonFunctionalTimerService = new NonFunctionalTimerService(EjbLogger.ROOT_LOGGER.ejbHasNoTimerMethods(), timerServiceRegistry);
                        }
                        // add the non-functional timer service as a MSC service
                        context.getServiceTarget().addService(nonFunctionalTimerServiceName, nonFunctionalTimerService).install();
                        // set the timer service in the EJB component
                        ejbComponentDescription.setTimerService(nonFunctionalTimerService);
                        // now we want the EJB component to depend on this non-functional timer service to start
                        configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                            @Override
                            public void configureDependency(ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
                                serviceBuilder.addDependency(nonFunctionalTimerServiceName);
                            }
                        });
                    }
                });
            }
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) HashMap(java.util.HashMap) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) TimedObjectInvokerImpl(org.jboss.as.ejb3.timerservice.TimedObjectInvokerImpl) TimerServiceImpl(org.jboss.as.ejb3.timerservice.TimerServiceImpl) TimerPersistence(org.jboss.as.ejb3.timerservice.persistence.TimerPersistence) ComponentStartService(org.jboss.as.ee.component.ComponentStartService) TimerServiceMetaData(org.jboss.as.ejb3.timerservice.TimerServiceMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) TimedObjectInvoker(org.jboss.as.ejb3.timerservice.spi.TimedObjectInvoker) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) TimerServiceRegistry(org.jboss.as.ejb3.component.TimerServiceRegistry) Timer(java.util.Timer) ServiceName(org.jboss.msc.service.ServiceName) NonFunctionalTimerService(org.jboss.as.ejb3.timerservice.NonFunctionalTimerService) ExecutorService(java.util.concurrent.ExecutorService) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)25 AssemblyDescriptorMetaData (org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData)12 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)10 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)7 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)5 Module (org.jboss.modules.Module)5 HashMap (java.util.HashMap)4 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)4 Map (java.util.Map)3 EjbJarDescription (org.jboss.as.ejb3.deployment.EjbJarDescription)3 EJBBoundSecurityMetaData (org.jboss.as.ejb3.security.metadata.EJBBoundSecurityMetaData)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2