Search in sources :

Example 11 with ViewConfiguration

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

the class WeldComponentIntegrationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        return;
    }
    final DeploymentUnit topLevelDeployment = getRootDeploymentUnit(deploymentUnit);
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final ServiceName weldBootstrapService = topLevelDeployment.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    final ServiceName weldStartService = topLevelDeployment.getServiceName().append(WeldStartService.SERVICE_NAME);
    final ServiceName beanManagerService = ServiceNames.beanManagerServiceName(deploymentUnit);
    final Iterable<ComponentIntegrator> componentIntegrators = ServiceLoader.load(ComponentIntegrator.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldComponentIntegrationProcessor.class));
    final ComponentInterceptorSupport componentInterceptorSupport = ServiceLoaders.loadSingle(ComponentInterceptorSupport.class, WeldComponentIntegrationProcessor.class).orElse(null);
    WeldClassIntrospector.install(deploymentUnit, phaseContext.getServiceTarget());
    eeModuleDescription.setDefaultClassIntrospectorServiceName(WeldClassIntrospector.serviceName(deploymentUnit));
    for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
        final String beanName;
        if (isBeanNameRequired(component, componentIntegrators)) {
            beanName = component.getComponentName();
        } else {
            beanName = null;
        }
        component.getConfigurators().add((context, description, configuration) -> {
            //add interceptor to activate the request scope if required
            final EjbRequestScopeActivationInterceptor.Factory requestFactory = new EjbRequestScopeActivationInterceptor.Factory(beanManagerService);
            for (ViewConfiguration view : configuration.getViews()) {
                view.addViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
            }
            configuration.addTimeoutViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
        });
        component.getConfigurators().addFirst(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final Class<?> componentClass = configuration.getComponentClass();
                final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
                final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
                final ModuleClassLoader classLoader = module.getClassLoader();
                //get the interceptors so they can be injected as well
                final Set<Class<?>> interceptorClasses = new HashSet<Class<?>>();
                for (InterceptorDescription interceptorDescription : description.getAllInterceptors()) {
                    try {
                        interceptorClasses.add(ClassLoadingUtils.loadClass(interceptorDescription.getInterceptorClassName(), module));
                    } catch (ClassNotFoundException e) {
                        throw WeldLogger.ROOT_LOGGER.couldNotLoadInterceptorClass(interceptorDescription.getInterceptorClassName(), e);
                    }
                }
                addWeldIntegration(componentIntegrators, componentInterceptorSupport, context.getServiceTarget(), configuration, description, componentClass, beanName, weldBootstrapService, weldStartService, beanManagerService, interceptorClasses, classLoader, description.getBeanDeploymentArchiveId());
            }
        });
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) Set(java.util.Set) HashSet(java.util.HashSet) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) WeldManagedReferenceFactory(org.jboss.as.weld.injection.WeldManagedReferenceFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ComponentIntegrator(org.jboss.as.weld.spi.ComponentIntegrator) ComponentInterceptorSupport(org.jboss.as.weld.spi.ComponentInterceptorSupport) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ServiceName(org.jboss.msc.service.ServiceName) EjbRequestScopeActivationInterceptor(org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit)

Example 12 with ViewConfiguration

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

the class MessageDrivenComponentDescription method setupViewInterceptors.

@Override
protected void setupViewInterceptors(EJBViewDescription view) {
    // let the super do its job
    super.setupViewInterceptors(view);
    view.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            //add the invocation type to the start of the chain
            //TODO: is there a cleaner way to do this?
            configuration.addViewInterceptor(new ImmediateInterceptorFactory(new Interceptor() {

                @Override
                public Object processInvocation(final InterceptorContext context) throws Exception {
                    context.putPrivateData(InvocationType.class, InvocationType.MESSAGE_DELIVERY);
                    return context.proceed();
                }
            }), InterceptorOrder.View.INVOCATION_TYPE);
            // add the instance associating interceptor at the start of the interceptor chain
            configuration.addViewInterceptor(MessageDrivenComponentInstanceAssociatingFactory.instance(), InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
            final MessageDrivenComponentDescription mdb = (MessageDrivenComponentDescription) componentConfiguration.getComponentDescription();
            if (mdb.getTransactionManagementType() == TransactionManagementType.CONTAINER) {
                configuration.addViewInterceptor(CMTTxInterceptor.FACTORY, InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) InvocationType(org.jboss.as.ee.component.interceptors.InvocationType) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) InterceptorContext(org.jboss.invocation.InterceptorContext) CurrentInvocationContextInterceptor(org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor) Interceptor(org.jboss.invocation.Interceptor) LifecycleCMTTxInterceptor(org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor) TimerCMTTxInterceptor(org.jboss.as.ejb3.tx.TimerCMTTxInterceptor) CMTTxInterceptor(org.jboss.as.ejb3.tx.CMTTxInterceptor) EjbBMTInterceptor(org.jboss.as.ejb3.tx.EjbBMTInterceptor)

Example 13 with ViewConfiguration

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

the class SessionBeanComponentDescription method addNoInterfaceView.

public void addNoInterfaceView() {
    noInterfaceViewPresent = true;
    final ViewDescription viewDescription = registerView(getEJBClassName(), MethodIntf.LOCAL);
    //set up interceptor for non-business methods
    viewDescription.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            DeploymentReflectionIndex index = context.getDeploymentUnit().getAttachment(Attachments.REFLECTION_INDEX);
            for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
                if (!Modifier.isPublic(method.getModifiers()) && isNotOverriden(method, componentConfiguration.getComponentClass(), index)) {
                    configuration.addClientInterceptor(method, new ImmediateInterceptorFactory(new NotBusinessMethodInterceptor(method)), InterceptorOrder.Client.NOT_BUSINESS_METHOD_EXCEPTION);
                }
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) Method(java.lang.reflect.Method) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 14 with ViewConfiguration

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

the class EJBComponentSuspendDeploymentUnitProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext context) {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final String topLevelName;
    //check if the controller is installed
    if (!RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
        return;
    }
    if (deploymentUnit.getParent() == null) {
        topLevelName = deploymentUnit.getName();
    } else {
        topLevelName = deploymentUnit.getParent().getName();
    }
    for (ComponentDescription component : deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION).getComponentDescriptions()) {
        if (component instanceof EJBComponentDescription) {
            final String entryPoint = ENTRY_POINT_NAME + deploymentUnit.getName() + "." + component.getComponentName();
            ControlPointService.install(context.getServiceTarget(), topLevelName, entryPoint);
            component.getConfigurators().add(new ComponentConfigurator() {

                @Override
                public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
                    EjbSuspendInterceptor interceptor = null;
                    ImmediateInterceptorFactory factory = null;
                    for (ViewConfiguration view : configuration.getViews()) {
                        EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
                        if (INTERFACES.contains(ejbView.getMethodIntf())) {
                            if (factory == null) {
                                interceptor = new EjbSuspendInterceptor();
                                factory = new ImmediateInterceptorFactory(interceptor);
                            }
                            view.addViewInterceptor(factory, InterceptorOrder.View.GRACEFUL_SHUTDOWN);
                        }
                    }
                    configuration.getCreateDependencies().add(new DependencyConfigurator<EJBComponentCreateService>() {

                        @Override
                        public void configureDependency(ServiceBuilder<?> serviceBuilder, EJBComponentCreateService service) {
                            serviceBuilder.addDependency(ControlPointService.serviceName(topLevelName, entryPoint), ControlPoint.class, service.getControlPointInjector());
                        }
                    });
                }
            });
        }
    }
}
Also used : EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EJBComponentCreateService(org.jboss.as.ejb3.component.EJBComponentCreateService) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 15 with ViewConfiguration

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

the class StatelessComponentDescription method setupViewInterceptors.

@Override
protected void setupViewInterceptors(EJBViewDescription view) {
    // let super do its job first
    super.setupViewInterceptors(view);
    addViewSerializationInterceptor(view);
    // add the instance associating interceptor at the start of the interceptor chain
    view.getConfigurators().addFirst(new ViewConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            //add equals/hashCode interceptor
            for (Method method : configuration.getProxyFactory().getCachedMethods()) {
                if ((method.getName().equals("hashCode") && method.getParameterTypes().length == 0) || method.getName().equals("equals") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) {
                    configuration.addClientInterceptor(method, ComponentTypeIdentityInterceptorFactory.INSTANCE, InterceptorOrder.Client.EJB_EQUALS_HASHCODE);
                }
            }
            // add the stateless component instance associating interceptor
            configuration.addViewInterceptor(StatelessComponentInstanceAssociatingFactory.instance(), InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
        }
    });
    if (view instanceof EJBViewDescription) {
        EJBViewDescription ejbViewDescription = (EJBViewDescription) view;
        if (ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE) {
            view.getConfigurators().add(new ViewConfigurator() {

                @Override
                public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                    final String earApplicationName = componentConfiguration.getComponentDescription().getModuleDescription().getEarApplicationName();
                    configuration.setViewInstanceFactory(new StatelessRemoteViewInstanceFactory(earApplicationName, componentConfiguration.getModuleName(), componentConfiguration.getComponentDescription().getModuleDescription().getDistinctName(), componentConfiguration.getComponentName()));
                }
            });
        }
    }
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) StatelessRemoteViewInstanceFactory(org.jboss.as.ejb3.component.session.StatelessRemoteViewInstanceFactory) Method(java.lang.reflect.Method) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext)

Aggregations

ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)19 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)17 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)17 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)16 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)14 ViewDescription (org.jboss.as.ee.component.ViewDescription)14 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)10 Method (java.lang.reflect.Method)9 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)9 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)4 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)4 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)4 WriteReplaceInterface (org.jboss.as.ee.component.serialization.WriteReplaceInterface)4 HashSet (java.util.HashSet)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)3 EJBViewConfiguration (org.jboss.as.ejb3.component.EJBViewConfiguration)3 ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)3