Search in sources :

Example 6 with ViewDescription

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

the class EjbJndiBindingsDeploymentUnitProcessor method setupJNDIBindings.

/**
     * Sets up jndi bindings for each of the views exposed by the passed <code>sessionBean</code>
     *
     * @param sessionBean    The session bean
     * @param deploymentUnit The deployment unit containing the session bean
     */
private void setupJNDIBindings(EJBComponentDescription sessionBean, DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final Collection<ViewDescription> views = sessionBean.getViews();
    if (views == null || views.isEmpty()) {
        EjbLogger.DEPLOYMENT_LOGGER.noJNDIBindingsForSessionBean(sessionBean.getEJBName());
        return;
    }
    // In case of EJB bindings, appname == .ear file name/application-name set in the application.xml (if it's an .ear deployment)
    // NOTE: Do NOT use the app name from the EEModuleDescription.getApplicationName() because the Java EE spec has a different and conflicting meaning for app name
    // (where app name == module name in the absence of a .ear). Use EEModuleDescription.getEarApplicationName() instead
    final String applicationName = sessionBean.getModuleDescription().getEarApplicationName();
    final String globalJNDIBaseName = "java:global/" + (applicationName != null ? applicationName + "/" : "") + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
    final String appJNDIBaseName = "java:app/" + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
    final String moduleJNDIBaseName = "java:module/" + sessionBean.getEJBName();
    final String remoteExportedJNDIBaseName = "java:jboss/exported/" + (applicationName != null ? applicationName + "/" : "") + sessionBean.getModuleName() + "/" + sessionBean.getEJBName();
    // the base ServiceName which will be used to create the ServiceName(s) for each of the view bindings
    final StringBuilder jndiBindingsLogMessage = new StringBuilder();
    jndiBindingsLogMessage.append(System.lineSeparator()).append(System.lineSeparator());
    // now create the bindings for each view under the java:global, java:app and java:module namespaces
    EJBViewDescription ejbViewDescription = null;
    for (ViewDescription viewDescription : views) {
        ejbViewDescription = (EJBViewDescription) viewDescription;
        if (appclient && ejbViewDescription.getMethodIntf() != MethodIntf.REMOTE && ejbViewDescription.getMethodIntf() != MethodIntf.HOME) {
            continue;
        }
        if (!ejbViewDescription.hasJNDIBindings())
            continue;
        final String viewClassName = ejbViewDescription.getViewClassName();
        // java:global bindings
        final String globalJNDIName = globalJNDIBaseName + "!" + viewClassName;
        registerBinding(sessionBean, viewDescription, globalJNDIName);
        logBinding(jndiBindingsLogMessage, globalJNDIName);
        // java:app bindings
        final String appJNDIName = appJNDIBaseName + "!" + viewClassName;
        registerBinding(sessionBean, viewDescription, appJNDIName);
        logBinding(jndiBindingsLogMessage, appJNDIName);
        // java:module bindings
        final String moduleJNDIName = moduleJNDIBaseName + "!" + viewClassName;
        registerBinding(sessionBean, viewDescription, moduleJNDIName);
        logBinding(jndiBindingsLogMessage, moduleJNDIName);
        // If it a remote or (remote) home view then bind the java:jboss/exported jndi names for the view
        if (ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE || ejbViewDescription.getMethodIntf() == MethodIntf.HOME) {
            final String remoteJNDIName = remoteExportedJNDIBaseName + "!" + viewClassName;
            if (RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
                registerControlPointBinding(sessionBean, viewDescription, remoteJNDIName, deploymentUnit);
            } else {
                registerBinding(sessionBean, viewDescription, remoteJNDIName);
            }
            logBinding(jndiBindingsLogMessage, remoteJNDIName);
        }
    }
    // as can be seen by the examples in 4.4.2.1
    if (views.size() == 1) {
        final EJBViewDescription viewDescription = (EJBViewDescription) views.iterator().next();
        if (ejbViewDescription.hasJNDIBindings()) {
            // java:global binding
            registerBinding(sessionBean, viewDescription, globalJNDIBaseName);
            logBinding(jndiBindingsLogMessage, globalJNDIBaseName);
            // java:app binding
            registerBinding(sessionBean, viewDescription, appJNDIBaseName);
            logBinding(jndiBindingsLogMessage, appJNDIBaseName);
            // java:module binding
            registerBinding(sessionBean, viewDescription, moduleJNDIBaseName);
            logBinding(jndiBindingsLogMessage, moduleJNDIBaseName);
        }
    }
    // log the jndi bindings
    EjbLogger.DEPLOYMENT_LOGGER.jndiBindings(sessionBean.getEJBName(), deploymentUnit, jndiBindingsLogMessage);
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription)

Example 7 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription 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) 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) 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) ArrayList(java.util.ArrayList) List(java.util.List) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext)

Example 8 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription 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 9 with ViewDescription

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

the class EJBValidationConfigurator method configure.

@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
    final DeploymentReflectionIndex deploymentReflectionIndex = context.getDeploymentUnit().getAttachment(Attachments.REFLECTION_INDEX);
    final ClassReflectionIndex classIndex = deploymentReflectionIndex.getClassIndex(configuration.getComponentClass());
    final Constructor<?> ctor = classIndex.getConstructor(new String[0]);
    boolean noInterface = false;
    for (ViewDescription view : description.getViews()) {
        if (view.getViewClassName().equals(description.getComponentClassName())) {
            noInterface = true;
        }
    }
    if (ctor == null && noInterface) {
        //we only validate this for no interface views
        throw EjbLogger.ROOT_LOGGER.ejbMustHavePublicDefaultConstructor(description.getComponentName(), description.getComponentClassName());
    }
    if (configuration.getComponentClass().getEnclosingClass() != null) {
        throw EjbLogger.ROOT_LOGGER.ejbMustNotBeInnerClass(description.getComponentName(), description.getComponentClassName());
    }
    if (!Modifier.isPublic(configuration.getComponentClass().getModifiers())) {
        throw EjbLogger.ROOT_LOGGER.ejbMustBePublicClass(description.getComponentName(), description.getComponentClassName());
    }
    if (Modifier.isFinal(configuration.getComponentClass().getModifiers())) {
        throw EjbLogger.ROOT_LOGGER.ejbMustNotBeFinalClass(description.getComponentName(), description.getComponentClassName());
    }
}
Also used : ViewDescription(org.jboss.as.ee.component.ViewDescription) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 10 with ViewDescription

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

the class SingletonComponentDescription method setupViewInterceptors.

@Override
protected void setupViewInterceptors(EJBViewDescription view) {
    // let super do its job first
    super.setupViewInterceptors(view);
    addViewSerializationInterceptor(view);
    // add container managed concurrency interceptor to the component
    this.addConcurrencyManagementInterceptor(view);
    // add 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 singleton component instance associating interceptor
            configuration.addViewInterceptor(SingletonComponentInstanceAssociationInterceptor.FACTORY, InterceptorOrder.View.ASSOCIATING_INTERCEPTOR);
        }
    });
    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 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) 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

ViewDescription (org.jboss.as.ee.component.ViewDescription)21 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)15 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)15 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)14 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)14 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)14 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)14 Method (java.lang.reflect.Method)8 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)6 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)4 ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)4 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)3 WriteReplaceInterface (org.jboss.as.ee.component.serialization.WriteReplaceInterface)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Module (org.jboss.modules.Module)3 HashSet (java.util.HashSet)2 ComponentView (org.jboss.as.ee.component.ComponentView)2 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)2 NamespaceViewConfigurator (org.jboss.as.ee.component.NamespaceViewConfigurator)2