Search in sources :

Example 56 with ComponentDescription

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

the class JSFManagedBeanProcessor method installManagedBeanComponent.

private void installManagedBeanComponent(String className, final EEModuleDescription moduleDescription, final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClassesDescription) {
    final ComponentDescription componentDescription = new WebComponentDescription(MANAGED_BEAN.toString() + "." + className, className, moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
    moduleDescription.addComponent(componentDescription);
    deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, componentDescription.getStartServiceName());
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription)

Example 57 with ComponentDescription

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

the class JaxrsComponentDeployer method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (module == null) {
        return;
    }
    final ResteasyDeploymentData resteasy = deploymentUnit.getAttachment(JaxrsAttachments.RESTEASY_DEPLOYMENT_DATA);
    if (resteasy == null) {
        return;
    }
    // right now I only support resources
    if (!resteasy.isScanResources())
        return;
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    final ClassLoader loader = module.getClassLoader();
    for (final ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        Class<?> componentClass = null;
        try {
            componentClass = loader.loadClass(component.getComponentClassName());
        } catch (ClassNotFoundException e) {
            throw new DeploymentUnitProcessingException(e);
        }
        if (!GetRestful.isRootResource(componentClass))
            continue;
        if (isInstanceOf(component, SESSION_BEAN_DESCRIPTION_CLASS_NAME)) {
            if (isInstanceOf(component, STATEFUL_SESSION_BEAN_DESCRIPTION_CLASS_NAME)) {
                //using SFSB's as JAX-RS endpoints is not recommended, but if people really want to do it they can
                JAXRS_LOGGER.debugf("Stateful session bean %s is being used as a JAX-RS endpoint, this is not recommended", component.getComponentName());
                if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
                    //if possible just let CDI handle the integration
                    continue;
                }
            }
            Class<?>[] jaxrsType = GetRestful.getSubResourceClasses(componentClass);
            final String jndiName;
            if (component.getViews().size() == 1) {
                //only 1 view, just use the simple JNDI name
                jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();
            } else {
                boolean found = false;
                String foundType = null;
                for (final ViewDescription view : component.getViews()) {
                    for (Class<?> subResource : jaxrsType) {
                        if (view.getViewClassName().equals(subResource.getName())) {
                            foundType = subResource.getName();
                            found = true;
                            break;
                        }
                    }
                    if (found) {
                        break;
                    }
                }
                if (!found) {
                    throw JAXRS_LOGGER.typeNameNotAnEjbView(Arrays.asList(jaxrsType), component.getComponentName());
                }
                jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName() + "!" + foundType;
            }
            JAXRS_LOGGER.debugf("Found JAX-RS Managed Bean: %s local jndi jaxRsTypeName: %s", component.getComponentClassName(), jndiName);
            StringBuilder buf = new StringBuilder();
            buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");
            resteasy.getScannedJndiComponentResources().add(buf.toString());
            // make sure its removed from list
            resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
        } else if (component instanceof ManagedBeanComponentDescription) {
            String jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();
            JAXRS_LOGGER.debugf("Found JAX-RS Managed Bean: %s local jndi name: %s", component.getComponentClassName(), jndiName);
            StringBuilder buf = new StringBuilder();
            buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");
            resteasy.getScannedJndiComponentResources().add(buf.toString());
            // make sure its removed from list
            resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ManagedBeanComponentDescription(org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) ManagedBeanComponentDescription(org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 58 with ComponentDescription

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

the class SessionBeanXmlDescriptorProcessor method processBeanMetaData.

/**
     * Processes the passed {@link org.jboss.metadata.ejb.spec.SessionBeanMetaData} and creates appropriate {@link org.jboss.as.ejb3.component.session.SessionBeanComponentDescription} out of it.
     * The {@link org.jboss.as.ejb3.component.session.SessionBeanComponentDescription} is then added to the {@link org.jboss.as.ee.component.EEModuleDescription module description} available
     * in the deployment unit of the passed {@link DeploymentPhaseContext phaseContext}
     *
     * @param sessionBean  The session bean metadata
     * @param phaseContext
     * @throws DeploymentUnitProcessingException
     *
     */
@Override
protected void processBeanMetaData(final SessionBeanMetaData sessionBean, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // get the module description
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final String beanName = sessionBean.getName();
    ComponentDescription bean = moduleDescription.getComponentByName(beanName);
    if (appclient) {
        if (bean == null) {
            for (final ComponentDescription component : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
                if (component.getComponentName().equals(beanName)) {
                    bean = component;
                    break;
                }
            }
        }
    }
    if (!(bean instanceof SessionBeanComponentDescription)) {
        //if this is a GenericBeanMetadata it may actually represent an MDB
        return;
    }
    SessionBeanComponentDescription sessionBeanDescription = (SessionBeanComponentDescription) bean;
    sessionBeanDescription.setDeploymentDescriptorEnvironment(new DeploymentDescriptorEnvironment("java:comp/env/", sessionBean));
    // mapped-name
    sessionBeanDescription.setMappedName(sessionBean.getMappedName());
    // local business interface views
    final BusinessLocalsMetaData businessLocals = sessionBean.getBusinessLocals();
    if (businessLocals != null && !businessLocals.isEmpty()) {
        sessionBeanDescription.addLocalBusinessInterfaceViews(businessLocals);
    }
    final String local = sessionBean.getLocal();
    if (local != null) {
        sessionBeanDescription.addEjbLocalObjectView(local);
    }
    final String remote = sessionBean.getRemote();
    if (remote != null) {
        sessionBeanDescription.addEjbObjectView(remote);
    }
    // remote business interface views
    final BusinessRemotesMetaData businessRemotes = sessionBean.getBusinessRemotes();
    if (businessRemotes != null && !businessRemotes.isEmpty()) {
        sessionBeanDescription.addRemoteBusinessInterfaceViews(businessRemotes);
    }
    // process EJB3.1 specific session bean description
    if (sessionBean instanceof SessionBean31MetaData) {
        this.processSessionBean31((SessionBean31MetaData) sessionBean, sessionBeanDescription);
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) SessionBean31MetaData(org.jboss.metadata.ejb.spec.SessionBean31MetaData) BusinessLocalsMetaData(org.jboss.metadata.ejb.spec.BusinessLocalsMetaData) BusinessRemotesMetaData(org.jboss.metadata.ejb.spec.BusinessRemotesMetaData)

Example 59 with ComponentDescription

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

the class AsynchronousMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final SessionBeanComponentDescription description) throws DeploymentUnitProcessingException {
    final SessionBeanMetaData data = description.getDescriptorData();
    final boolean isSecurityDomainKnown = description.isSecurityDomainKnown();
    if (data != null) {
        if (data instanceof SessionBean31MetaData) {
            final SessionBean31MetaData sessionBeanData = (SessionBean31MetaData) data;
            final AsyncMethodsMetaData async = sessionBeanData.getAsyncMethods();
            if (async != null) {
                for (AsyncMethodMetaData method : async) {
                    final Collection<Method> methods = MethodResolutionUtils.resolveMethods(method.getMethodName(), method.getMethodParams(), componentClass, deploymentReflectionIndex);
                    for (final Method m : methods) {
                        description.addAsynchronousMethod(MethodIdentifier.getIdentifierForMethod(m));
                    }
                }
            }
        }
    }
    if (!description.getAsynchronousClasses().isEmpty() || !description.getAsynchronousMethods().isEmpty()) {
        //setup a dependency on the executor service
        description.getConfigurators().add(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                configuration.getCreateDependencies().add(new DependencyConfigurator<SessionBeanComponentCreateService>() {

                    @Override
                    public void configureDependency(final ServiceBuilder<?> serviceBuilder, final SessionBeanComponentCreateService service) throws DeploymentUnitProcessingException {
                        serviceBuilder.addDependency(asynchronousThreadPoolService, ExecutorService.class, service.getAsyncExecutorService());
                    }
                });
            }
        });
        for (final ViewDescription view : description.getViews()) {
            final EJBViewDescription ejbView = (EJBViewDescription) view;
            ejbView.getConfigurators().add(new ViewConfigurator() {

                @Override
                public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                    final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
                    for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
                        //we need the component method to get the correct declaring class
                        final Method componentMethod = ClassReflectionIndexUtil.findMethod(deploymentReflectionIndex, componentClass, method);
                        if (componentMethod != null) {
                            if (componentDescription.getAsynchronousClasses().contains(componentMethod.getDeclaringClass().getName())) {
                                addAsyncInterceptor(configuration, method, isSecurityDomainKnown);
                                configuration.addAsyncMethod(method);
                            } else {
                                MethodIdentifier id = MethodIdentifier.getIdentifierForMethod(method);
                                if (componentDescription.getAsynchronousMethods().contains(id)) {
                                    addAsyncInterceptor(configuration, method, isSecurityDomainKnown);
                                    configuration.addAsyncMethod(method);
                                }
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) 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) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) SessionBean31MetaData(org.jboss.metadata.ejb.spec.SessionBean31MetaData) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AsyncMethodsMetaData(org.jboss.metadata.ejb.spec.AsyncMethodsMetaData) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) AsyncMethodMetaData(org.jboss.metadata.ejb.spec.AsyncMethodMetaData) SessionBeanComponentCreateService(org.jboss.as.ejb3.component.session.SessionBeanComponentCreateService) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Example 60 with ComponentDescription

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

the class StartupAwaitDeploymentUnitProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        if (component instanceof EJBComponentDescription) {
            component.getConfigurators().add(new ComponentConfigurator() {

                @Override
                public void configure(DeploymentPhaseContext context, ComponentDescription description, ComponentConfiguration configuration) {
                    StartupCountdown countdown = context.getDeploymentUnit().getAttachment(Attachments.STARTUP_COUNTDOWN);
                    for (ViewConfiguration view : configuration.getViews()) {
                        EJBViewConfiguration ejbView = (EJBViewConfiguration) view;
                        if (INTFS.contains(ejbView.getMethodIntf())) {
                            ejbView.addViewInterceptor(new ImmediateInterceptorFactory(new StartupAwaitInterceptor(countdown)), InterceptorOrder.View.STARTUP_AWAIT_INTERCEPTOR);
                        }
                    }
                }
            });
        }
    }
}
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) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown)

Aggregations

ComponentDescription (org.jboss.as.ee.component.ComponentDescription)65 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)45 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)44 ServiceName (org.jboss.msc.service.ServiceName)20 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)19 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)18 Module (org.jboss.modules.Module)18 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)17 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)16 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)16 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)15 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)11 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)9 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)9 ServiceTarget (org.jboss.msc.service.ServiceTarget)9 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)8 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)5 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)5 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)5