Search in sources :

Example 1 with ViewConfigurator

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

the class SessionBeanHomeProcessor method configureHome.

private void configureHome(final DeploymentPhaseContext phaseContext, final ComponentDescription componentDescription, final SessionBeanComponentDescription ejbComponentDescription, final EJBViewDescription homeView, final EJBViewDescription ejbObjectView) {
    homeView.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            configuration.addClientPostConstructInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
            configuration.addClientPreDestroyInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
            //loop over methods looking for create methods:
            for (Method method : configuration.getProxyFactory().getCachedMethods()) {
                if (method.getName().startsWith("create")) {
                    //we have a create method
                    if (ejbObjectView == null) {
                        throw EjbLogger.ROOT_LOGGER.invalidEjbLocalInterface(componentDescription.getComponentName());
                    }
                    Method initMethod = resolveInitMethod(ejbComponentDescription, method);
                    final SessionBeanHomeInterceptorFactory factory = new SessionBeanHomeInterceptorFactory(initMethod);
                    //add a dependency on the view to create
                    configuration.getDependencies().add(new DependencyConfigurator<ViewService>() {

                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ViewService service) throws DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(ejbObjectView.getServiceName(), ComponentView.class, factory.getViewToCreate());
                        }
                    });
                    //add the interceptor
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                } else if (method.getName().equals("getEJBMetaData") && method.getParameterTypes().length == 0 && ((EJBViewDescription) description).getMethodIntf() == MethodIntf.HOME) {
                    final Class<?> ejbObjectClass;
                    try {
                        ejbObjectClass = ClassLoadingUtils.loadClass(ejbObjectView.getViewClassName(), context.getDeploymentUnit());
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getComponentName());
                    }
                    final EjbMetadataInterceptor factory = new EjbMetadataInterceptor(ejbObjectClass, configuration.getViewClass().asSubclass(EJBHome.class), null, true, componentDescription instanceof StatelessComponentDescription);
                    //add a dependency on the view to create
                    componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
                        }
                    });
                    //add the interceptor
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(factory), InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                } else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) {
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, InvalidRemoveExceptionMethodInterceptor.FACTORY, InterceptorOrder.View.INVALID_METHOD_EXCEPTION);
                } else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Handle.class) {
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, HomeRemoveInterceptor.FACTORY, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                }
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBHome(javax.ejb.EJBHome) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Method(java.lang.reflect.Method) ViewService(org.jboss.as.ee.component.ViewService) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) Handle(javax.ejb.Handle) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) SessionBeanHomeInterceptorFactory(org.jboss.as.ejb3.component.interceptors.SessionBeanHomeInterceptorFactory) ComponentView(org.jboss.as.ee.component.ComponentView) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EjbMetadataInterceptor(org.jboss.as.ejb3.component.interceptors.EjbMetadataInterceptor) ComponentStartService(org.jboss.as.ee.component.ComponentStartService)

Example 2 with ViewConfigurator

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

the class EJBComponentDescription method setupRemoteViewInterceptors.

private void setupRemoteViewInterceptors(final EJBViewDescription view) {
    if (view.getMethodIntf() == MethodIntf.REMOTE || view.getMethodIntf() == MethodIntf.HOME) {
        view.getConfigurators().add(new ViewConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                if (Remote.class.isAssignableFrom(configuration.getViewClass())) {
                    configuration.addViewInterceptor(EjbExceptionTransformingInterceptorFactories.REMOTE_INSTANCE, InterceptorOrder.View.REMOTE_EXCEPTION_TRANSFORMER);
                }
            }
        });
        if (view.getMethodIntf() == MethodIntf.HOME) {
            view.getConfigurators().add(new ViewConfigurator() {

                @Override
                public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                    if (Remote.class.isAssignableFrom(configuration.getViewClass())) {
                        final String earApplicationName = componentConfiguration.getComponentDescription().getModuleDescription().getEarApplicationName();
                        configuration.setViewInstanceFactory(new RemoteHomeViewInstanceFactory(earApplicationName, componentConfiguration.getModuleName(), componentConfiguration.getComponentDescription().getModuleDescription().getDistinctName(), componentConfiguration.getComponentName()));
                    }
                }
            });
        }
        // add the remote tx propagating interceptor
        view.getConfigurators().add(new EJBRemoteTransactionsViewConfigurator());
    }
}
Also used : NamespaceViewConfigurator(org.jboss.as.ee.component.NamespaceViewConfigurator) EJBRemoteTransactionsViewConfigurator(org.jboss.as.ejb3.remote.EJBRemoteTransactionsViewConfigurator) EJBSecurityViewConfigurator(org.jboss.as.ejb3.security.EJBSecurityViewConfigurator) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBRemoteTransactionsViewConfigurator(org.jboss.as.ejb3.remote.EJBRemoteTransactionsViewConfigurator) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) ViewDescription(org.jboss.as.ee.component.ViewDescription) Remote(java.rmi.Remote) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext)

Example 3 with ViewConfigurator

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

the class ManagedBeanAnnotationProcessor method deploy.

/**
 * Check the deployment annotation index for all classes with the @ManagedBean annotation.  For each class with the
 * annotation, collect all the required information to create a managed bean instance, and attach it to the context.
 *
 * @param phaseContext the deployment unit context
 * @throws DeploymentUnitProcessingException
 */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    if (compositeIndex == null) {
        return;
    }
    final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME);
    if (instances == null || instances.isEmpty()) {
        return;
    }
    for (AnnotationInstance instance : instances) {
        AnnotationTarget target = instance.target();
        if (!(target instanceof ClassInfo)) {
            throw EeLogger.ROOT_LOGGER.classOnlyAnnotation("@ManagedBean", target);
        }
        final ClassInfo classInfo = (ClassInfo) target;
        // skip if it's not a valid managed bean class
        if (!assertManagedBeanClassValidity(classInfo)) {
            continue;
        }
        final String beanClassName = classInfo.name().toString();
        // Get the managed bean name from the annotation
        final AnnotationValue nameValue = instance.value();
        final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? beanClassName : replacer.replaceProperties(nameValue.asString());
        final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());
        // Add the view
        ViewDescription viewDescription = new ViewDescription(componentDescription, beanClassName);
        viewDescription.getConfigurators().addFirst(new ViewConfigurator() {

            public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                // Add MB association interceptors
                configuration.addClientPostConstructInterceptor(ManagedBeanCreateInterceptor.FACTORY, InterceptorOrder.ClientPostConstruct.INSTANCE_CREATE);
                final ClassLoader classLoader = componentConfiguration.getModuleClassLoader();
                configuration.addViewInterceptor(AccessCheckingInterceptor.getFactory(), InterceptorOrder.View.CHECKING_INTERCEPTOR);
                configuration.addViewInterceptor(new ImmediateInterceptorFactory(new ContextClassLoaderInterceptor(classLoader)), InterceptorOrder.View.TCCL_INTERCEPTOR);
            }
        });
        viewDescription.getBindingNames().addAll(Arrays.asList("java:module/" + beanName, "java:app/" + moduleDescription.getModuleName() + "/" + beanName));
        componentDescription.getViews().add(viewDescription);
        moduleDescription.addComponent(componentDescription);
        // register an EEResourceReferenceProcessor which can process @Resource references to this managed bean.
        registry.registerResourceReferenceProcessor(new ManagedBeanResourceReferenceProcessor(beanClassName));
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ManagedBeanComponentDescription(org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) ContextClassLoaderInterceptor(org.jboss.invocation.ContextClassLoaderInterceptor) ManagedBeanResourceReferenceProcessor(org.jboss.as.ee.managedbean.component.ManagedBeanResourceReferenceProcessor) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) EEResourceReferenceProcessorRegistry(org.jboss.as.ee.component.deployers.EEResourceReferenceProcessorRegistry) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 4 with ViewConfigurator

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

the class StatefulComponentDescription method setupViewInterceptors.

@Override
protected void setupViewInterceptors(EJBViewDescription view) {
    // let super do its job
    super.setupViewInterceptors(view);
    // add the @Remove method interceptor
    this.addRemoveMethodInterceptor(view);
    // setup the instance associating interceptors
    this.addStatefulInstanceAssociatingInterceptor(view);
    this.addViewSerializationInterceptor(view);
    if (view.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 StatefulRemoteViewInstanceFactory(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) ViewDescription(org.jboss.as.ee.component.ViewDescription) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext)

Example 5 with ViewConfigurator

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

the class EJBComponentDescription method setupViewInterceptors.

protected void setupViewInterceptors(final EJBViewDescription view) {
    // add a logging interceptor (to take care of EJB3 spec, section 14.3 logging requirements)
    view.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(DeploymentPhaseContext context, ComponentConfiguration componentConfiguration, ViewDescription description, ViewConfiguration viewConfiguration) throws DeploymentUnitProcessingException {
            viewConfiguration.addViewInterceptor(LoggingInterceptor.FACTORY, InterceptorOrder.View.EJB_EXCEPTION_LOGGING_INTERCEPTOR);
            final ClassLoader classLoader = componentConfiguration.getModuleClassLoader();
            viewConfiguration.addViewInterceptor(AccessCheckingInterceptor.getFactory(), InterceptorOrder.View.CHECKING_INTERCEPTOR);
            viewConfiguration.addViewInterceptor(new ImmediateInterceptorFactory(new ContextClassLoaderInterceptor(classLoader)), InterceptorOrder.View.TCCL_INTERCEPTOR);
            // If this is the EJB 2.x local or home view add the exception transformer interceptor
            if (view.getMethodIntf() == MethodIntf.LOCAL && EJBLocalObject.class.isAssignableFrom(viewConfiguration.getViewClass())) {
                viewConfiguration.addViewInterceptor(EjbExceptionTransformingInterceptorFactories.LOCAL_INSTANCE, InterceptorOrder.View.REMOTE_EXCEPTION_TRANSFORMER);
            } else if (view.getMethodIntf() == MethodIntf.LOCAL_HOME) {
                viewConfiguration.addViewInterceptor(EjbExceptionTransformingInterceptorFactories.LOCAL_INSTANCE, InterceptorOrder.View.REMOTE_EXCEPTION_TRANSFORMER);
            }
            final List<SetupAction> ejbSetupActions = context.getDeploymentUnit().getAttachmentList(Attachments.OTHER_EE_SETUP_ACTIONS);
            if (!ejbSetupActions.isEmpty()) {
                viewConfiguration.addViewInterceptor(AdditionalSetupInterceptor.factory(ejbSetupActions), InterceptorOrder.View.EE_SETUP);
            }
            viewConfiguration.addViewInterceptor(WaitTimeInterceptor.FACTORY, InterceptorOrder.View.EJB_WAIT_TIME_INTERCEPTOR);
            viewConfiguration.addViewInterceptor(shutDownInterceptorFactory, InterceptorOrder.View.SHUTDOWN_INTERCEPTOR);
        }
    });
    this.addCurrentInvocationContextFactory(view);
    this.setupSecurityInterceptors(view);
    this.setupRemoteViewInterceptors(view);
    view.getConfigurators().addFirst(new NamespaceViewConfigurator());
}
Also used : NamespaceViewConfigurator(org.jboss.as.ee.component.NamespaceViewConfigurator) EJBSecurityViewConfigurator(org.jboss.as.ejb3.security.EJBSecurityViewConfigurator) 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) ViewDescription(org.jboss.as.ee.component.ViewDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ContextClassLoaderInterceptor(org.jboss.invocation.ContextClassLoaderInterceptor) NamespaceViewConfigurator(org.jboss.as.ee.component.NamespaceViewConfigurator) List(java.util.List) ArrayList(java.util.ArrayList) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext)

Aggregations

ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)16 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)16 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)16 ViewDescription (org.jboss.as.ee.component.ViewDescription)16 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)16 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)16 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)11 Method (java.lang.reflect.Method)9 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)7 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)4 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)4 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)4 NamespaceViewConfigurator (org.jboss.as.ee.component.NamespaceViewConfigurator)3 ViewService (org.jboss.as.ee.component.ViewService)3 WriteReplaceInterface (org.jboss.as.ee.component.serialization.WriteReplaceInterface)3 EJBSecurityViewConfigurator (org.jboss.as.ejb3.security.EJBSecurityViewConfigurator)3 ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)3 EJBHome (javax.ejb.EJBHome)2 Handle (javax.ejb.Handle)2 ComponentStartService (org.jboss.as.ee.component.ComponentStartService)2