Search in sources :

Example 1 with EJBComponentDescription

use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.

the class EjbContextJndiBindingProcessor method processComponentConfig.

protected void processComponentConfig(final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext, final CompositeIndex index, final ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
    if (!(componentDescription instanceof EJBComponentDescription)) {
        // Only process EJBs
        return;
    }
    // if the EJB is packaged in a .war, then we need to bind the java:comp/EJBContext only once for the entire module
    if (componentDescription.getNamingMode() != ComponentNamingMode.CREATE) {
        // get the module description
        final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
        // the java:module/EJBContext binding configuration
        // Note that we bind to java:module/EJBContext since it's a .war. End users can still lookup java:comp/EJBContext
        // and that will internally get translated to  java:module/EJBContext for .war, since java:comp == java:module in
        // a web ENC. So binding to java:module/EJBContext is OK.
        final BindingConfiguration ejbContextBinding = new BindingConfiguration("java:module/EJBContext", directEjbContextReferenceSource);
        moduleDescription.getBindingConfigurations().add(ejbContextBinding);
    } else {
        // EJB packaged outside of a .war. So process normally.
        // add the binding configuration to the component description
        final BindingConfiguration ejbContextBinding = new BindingConfiguration("java:comp/EJBContext", directEjbContextReferenceSource);
        componentDescription.getBindingConfigurations().add(ejbContextBinding);
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 2 with EJBComponentDescription

use of org.jboss.as.ejb3.component.EJBComponentDescription 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 3 with EJBComponentDescription

use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.

the class TransactionAttributeMergingProcessor method handleAnnotations.

@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    processTransactionAttributeAnnotation(applicationClasses, deploymentReflectionIndex, componentClass, null, componentConfiguration);
    processTransactionTimeoutAnnotation(applicationClasses, deploymentReflectionIndex, componentClass, null, componentConfiguration);
    for (ViewDescription view : componentConfiguration.getViews()) {
        try {
            final Class<?> viewClass = module.getClassLoader().loadClass(view.getViewClassName());
            EJBViewDescription ejbView = (EJBViewDescription) view;
            processTransactionAttributeAnnotation(applicationClasses, deploymentReflectionIndex, viewClass, ejbView.getMethodIntf(), componentConfiguration);
            processTransactionTimeoutAnnotation(applicationClasses, deploymentReflectionIndex, viewClass, ejbView.getMethodIntf(), componentConfiguration);
        } catch (ClassNotFoundException e) {
            throw EjbLogger.ROOT_LOGGER.failToLoadEjbViewClass(e);
        }
    }
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) Module(org.jboss.modules.Module)

Example 4 with EJBComponentDescription

use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.

the class EjbContextJndiBindingProcessor method processComponentConfig.

protected void processComponentConfig(final ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
    if (!(componentDescription instanceof EJBComponentDescription)) {
        // Only process Jakarta Enterprise Beans
        return;
    }
    // if the Jakarta Enterprise Beans are packaged in a .war, then we need to bind the java:comp/EJBContext only once for the entire module
    if (componentDescription.getNamingMode() != ComponentNamingMode.CREATE) {
        // get the module description
        final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
        // the java:module/EJBContext binding configuration
        // Note that we bind to java:module/EJBContext since it's a .war. End users can still lookup java:comp/EJBContext
        // and that will internally get translated to  java:module/EJBContext for .war, since java:comp == java:module in
        // a web ENC. So binding to java:module/EJBContext is OK.
        final BindingConfiguration ejbContextBinding = new BindingConfiguration("java:module/EJBContext", directEjbContextReferenceSource);
        moduleDescription.getBindingConfigurations().add(ejbContextBinding);
    } else {
        // Jakarta Enterprise Beans packaged outside of a .war. So process normally.
        // add the binding configuration to the component description
        final BindingConfiguration ejbContextBinding = new BindingConfiguration("java:comp/EJBContext", directEjbContextReferenceSource);
        componentDescription.getBindingConfigurations().add(ejbContextBinding);
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 5 with EJBComponentDescription

use of org.jboss.as.ejb3.component.EJBComponentDescription in project wildfly by wildfly.

the class EjbIIOPDeploymentUnitProcessor method processEjb.

private void processEjb(final EJBComponentDescription componentDescription, final DeploymentReflectionIndex deploymentReflectionIndex, final Module module, final ServiceTarget serviceTarget, final IIOPMetaData iiopMetaData) {
    componentDescription.setExposedViaIiop(true);
    // Create bean method mappings for container invoker
    final EJBViewDescription remoteView = componentDescription.getEjbRemoteView();
    final Class<?> remoteClass;
    try {
        remoteClass = ClassLoadingUtils.loadClass(remoteView.getViewClassName(), module);
    } catch (ClassNotFoundException e) {
        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
    }
    final EJBViewDescription homeView = componentDescription.getEjbHomeView();
    final Class<?> homeClass;
    try {
        homeClass = ClassLoadingUtils.loadClass(homeView.getViewClassName(), module);
    } catch (ClassNotFoundException e) {
        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
    }
    componentDescription.getEjbHomeView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
    componentDescription.getEjbRemoteView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
    final InterfaceAnalysis remoteInterfaceAnalysis;
    try {
        // TODO: change all this to use the deployment reflection index
        remoteInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(remoteClass);
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
    }
    final Map<String, SkeletonStrategy> beanMethodMap = new HashMap<String, SkeletonStrategy>();
    final AttributeAnalysis[] remoteAttrs = remoteInterfaceAnalysis.getAttributes();
    for (int i = 0; i < remoteAttrs.length; i++) {
        final OperationAnalysis op = remoteAttrs[i].getAccessorAnalysis();
        if (op != null) {
            EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", op.getJavaName(), op.getIDLName());
            // translate to the deployment reflection index method
            // TODO: this needs to be fixed so it just returns the correct method
            final Method method = translateMethod(deploymentReflectionIndex, op);
            beanMethodMap.put(op.getIDLName(), new SkeletonStrategy(method));
            final OperationAnalysis setop = remoteAttrs[i].getMutatorAnalysis();
            if (setop != null) {
                EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", setop.getJavaName(), setop.getIDLName());
                // translate to the deployment reflection index method
                // TODO: this needs to be fixed so it just returns the correct method
                final Method realSetmethod = translateMethod(deploymentReflectionIndex, setop);
                beanMethodMap.put(setop.getIDLName(), new SkeletonStrategy(realSetmethod));
            }
        }
    }
    final OperationAnalysis[] ops = remoteInterfaceAnalysis.getOperations();
    for (int i = 0; i < ops.length; i++) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", ops[i].getJavaName(), ops[i].getIDLName());
        beanMethodMap.put(ops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, ops[i])));
    }
    // Initialize repository ids of remote interface
    final String[] beanRepositoryIds = remoteInterfaceAnalysis.getAllTypeIds();
    // Create home method mappings for container invoker
    final InterfaceAnalysis homeInterfaceAnalysis;
    try {
        // TODO: change all this to use the deployment reflection index
        homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeClass);
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
    }
    final Map<String, SkeletonStrategy> homeMethodMap = new HashMap<String, SkeletonStrategy>();
    final AttributeAnalysis[] attrs = homeInterfaceAnalysis.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
        final OperationAnalysis op = attrs[i].getAccessorAnalysis();
        if (op != null) {
            EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", op.getJavaName(), op.getIDLName());
            homeMethodMap.put(op.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, op)));
            final OperationAnalysis setop = attrs[i].getMutatorAnalysis();
            if (setop != null) {
                EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", setop.getJavaName(), setop.getIDLName());
                homeMethodMap.put(setop.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, setop)));
            }
        }
    }
    final OperationAnalysis[] homeops = homeInterfaceAnalysis.getOperations();
    for (int i = 0; i < homeops.length; i++) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", homeops[i].getJavaName(), homeops[i].getIDLName());
        homeMethodMap.put(homeops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, homeops[i])));
    }
    // Initialize repository ids of home interface
    final String[] homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();
    final EjbIIOPService service = new EjbIIOPService(beanMethodMap, beanRepositoryIds, homeMethodMap, homeRepositoryIds, settingsService.isUseQualifiedName(), iiopMetaData, module);
    final ServiceBuilder<EjbIIOPService> builder = serviceTarget.addService(componentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), service);
    builder.addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, service.getEjbComponentInjectedValue());
    builder.addDependency(homeView.getServiceName(), ComponentView.class, service.getHomeView());
    builder.addDependency(remoteView.getServiceName(), ComponentView.class, service.getRemoteView());
    builder.addDependency(CorbaORBService.SERVICE_NAME, ORB.class, service.getOrb());
    builder.addDependency(POARegistry.SERVICE_NAME, POARegistry.class, service.getPoaRegistry());
    builder.addDependency(CorbaPOAService.INTERFACE_REPOSITORY_SERVICE_NAME, POA.class, service.getIrPoa());
    builder.addDependency(CorbaNamingService.SERVICE_NAME, NamingContextExt.class, service.getCorbaNamingContext());
    builder.addDependency(IORSecConfigMetaDataService.SERVICE_NAME, IORSecurityConfigMetaData.class, service.getIORSecConfigMetaDataInjectedValue());
    builder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.getServiceModuleLoaderInjectedValue());
    builder.addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER, TransactionManagerService.class, service.getTransactionManagerInjectedValue());
    builder.install();
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) HashMap(java.util.HashMap) SkeletonStrategy(org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy) Method(java.lang.reflect.Method) OperationAnalysis(org.wildfly.iiop.openjdk.rmi.OperationAnalysis) InterfaceAnalysis(org.wildfly.iiop.openjdk.rmi.InterfaceAnalysis) AttributeAnalysis(org.wildfly.iiop.openjdk.rmi.AttributeAnalysis) RMIIIOPViolationException(org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException) EjbIIOPService(org.jboss.as.ejb3.iiop.EjbIIOPService)

Aggregations

EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)26 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)18 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)16 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)16 Method (java.lang.reflect.Method)11 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)11 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)9 EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)9 HashMap (java.util.HashMap)8 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)8 ViewDescription (org.jboss.as.ee.component.ViewDescription)8 Module (org.jboss.modules.Module)8 ServiceName (org.jboss.msc.service.ServiceName)8 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)7 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)7 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)7 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 Map (java.util.Map)5 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)5