Search in sources :

Example 36 with EEModuleDescription

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

the class WSIntegrationProcessorJAXWS_POJO method processAnnotation.

// @Override
protected void processAnnotation(final DeploymentUnit unit, final EEModuleDescription moduleDescription) throws DeploymentUnitProcessingException {
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, unit)) {
        return;
    }
    final Map<String, EEModuleClassDescription> classDescriptionMap = new HashMap<String, org.jboss.as.ee.component.EEModuleClassDescription>();
    final CompositeIndex index = unit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    for (EEModuleClassDescription classDescritpion : moduleDescription.getClassDescriptions()) {
        if (isJaxwsEndpoint(classDescritpion, index) && !exclude(unit, classDescritpion)) {
            classDescriptionMap.put(classDescritpion.getClassName(), classDescritpion);
        }
    }
    final JBossWebMetaData jbossWebMD = getJBossWebMetaData(unit);
    final JAXWSDeployment jaxwsDeployment = getJaxwsDeployment(unit);
    if (jbossWebMD != null) {
        final Set<String> matchedEps = new HashSet<String>();
        for (final ServletMetaData servletMD : getServlets(jbossWebMD)) {
            final String endpointClassName = getEndpointClassName(servletMD);
            final String endpointName = getEndpointName(servletMD);
            if (classDescriptionMap.containsKey(endpointClassName) || matchedEps.contains(endpointClassName)) {
                // creating component description for POJO endpoint
                final ComponentDescription pojoComponent = createComponentDescription(unit, endpointName, endpointClassName, endpointName);
                final ServiceName pojoViewName = registerView(pojoComponent, endpointClassName);
                final String urlPattern = getUrlPattern(endpointName, unit);
                jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointName, endpointClassName, pojoViewName, urlPattern));
                classDescriptionMap.remove(endpointClassName);
                matchedEps.add(endpointClassName);
            } else {
                if (unit.getParent() != null && DeploymentTypeMarker.isType(DeploymentType.EAR, unit.getParent())) {
                    final EEModuleDescription eeModuleDescription = unit.getParent().getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
                    final CompositeIndex parentIndex = unit.getParent().getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
                    for (EEModuleClassDescription classDescription : eeModuleDescription.getClassDescriptions()) {
                        if (classDescription.getClassName().equals(endpointClassName) && isJaxwsEndpoint(classDescription, parentIndex)) {
                            final ComponentDescription pojoComponent = createComponentDescription(unit, endpointName, endpointClassName, endpointName);
                            final ServiceName pojoViewName = registerView(pojoComponent, endpointClassName);
                            final String urlPattern = getUrlPattern(endpointName, unit);
                            jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointName, endpointClassName, pojoViewName, urlPattern));
                        }
                    }
                }
            }
        }
    }
    for (EEModuleClassDescription classDescription : classDescriptionMap.values()) {
        ClassInfo classInfo = null;
        String serviceName = null;
        String urlPattern = null;
        // #1 Override serviceName with the explicit urlPattern from port-component/port-component-uri in jboss-webservices.xml
        EJBEndpoint ejbEndpoint = getWebserviceMetadataEJBEndpoint(jaxwsDeployment, classDescription.getClassName());
        if (ejbEndpoint != null) {
            urlPattern = UrlPatternUtils.getUrlPatternByPortComponentURI(getJBossWebserviceMetaDataPortComponent(unit, ejbEndpoint.getName()));
        }
        // #2 Override serviceName with @WebContext.urlPattern
        if (urlPattern == null) {
            final ClassAnnotationInformation<WebContext, WebContextAnnotationInfo> annotationWebContext = classDescription.getAnnotationInformation(WebContext.class);
            if (annotationWebContext != null) {
                WebContextAnnotationInfo wsInfo = annotationWebContext.getClassLevelAnnotations().get(0);
                if (wsInfo != null && wsInfo.getUrlPattern().length() > 0) {
                    urlPattern = wsInfo.getUrlPattern();
                }
            }
        }
        // #3 use serviceName declared in a class annotation
        if (urlPattern == null) {
            final ClassAnnotationInformation<WebService, WebServiceAnnotationInfo> annotationInfo = classDescription.getAnnotationInformation(WebService.class);
            if (annotationInfo != null) {
                WebServiceAnnotationInfo wsInfo = annotationInfo.getClassLevelAnnotations().get(0);
                serviceName = wsInfo.getServiceName();
                classInfo = (ClassInfo) wsInfo.getTarget();
                urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceName);
                if (jaxwsDeployment.contains(urlPattern)) {
                    urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceName, wsInfo.getName());
                }
            }
            final ClassAnnotationInformation<WebServiceProvider, WebServiceProviderAnnotationInfo> annotationProviderInfo = classDescription.getAnnotationInformation(WebServiceProvider.class);
            if (annotationProviderInfo != null) {
                WebServiceProviderAnnotationInfo wsInfo = annotationProviderInfo.getClassLevelAnnotations().get(0);
                serviceName = wsInfo.getServiceName();
                classInfo = (ClassInfo) wsInfo.getTarget();
            }
        }
        if (classInfo != null) {
            final String endpointClassName = classDescription.getClassName();
            final ComponentDescription pojoComponent = createComponentDescription(unit, endpointClassName, endpointClassName, endpointClassName);
            final ServiceName pojoViewName = registerView(pojoComponent, endpointClassName);
            if (urlPattern == null) {
                urlPattern = UrlPatternUtils.getUrlPattern(classInfo.name().local(), serviceName);
            }
            // register POJO endpoint
            jaxwsDeployment.addEndpoint(new POJOEndpoint(endpointClassName, pojoViewName, UrlPatternUtils.getUrlPattern(urlPattern)));
        }
    }
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) ASHelper.getJBossWebMetaData(org.jboss.as.webservices.util.ASHelper.getJBossWebMetaData) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WebContext(org.jboss.ws.api.annotation.WebContext) HashMap(java.util.HashMap) WebService(javax.jws.WebService) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EJBEndpoint(org.jboss.as.webservices.metadata.model.EJBEndpoint) ASHelper.getWebserviceMetadataEJBEndpoint(org.jboss.as.webservices.util.ASHelper.getWebserviceMetadataEJBEndpoint) ServletMetaData(org.jboss.metadata.web.spec.ServletMetaData) HashSet(java.util.HashSet) POJOEndpoint(org.jboss.as.webservices.metadata.model.POJOEndpoint) WebServiceProvider(javax.xml.ws.WebServiceProvider) ServiceName(org.jboss.msc.service.ServiceName) JAXWSDeployment(org.jboss.as.webservices.metadata.model.JAXWSDeployment) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) ClassInfo(org.jboss.jandex.ClassInfo)

Example 37 with EEModuleDescription

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

the class AbstractIntegrationProcessorJAXWS method createComponentDescription.

static ComponentDescription createComponentDescription(final DeploymentUnit unit, final String componentName, final String componentClassName, final String dependsOnEndpointClassName) {
    final EEModuleDescription moduleDescription = getRequiredAttachment(unit, EE_MODULE_DESCRIPTION);
    // JBoss WEB processors may install fake components for WS endpoints - removing them forcibly
    moduleDescription.removeComponent(componentName, componentClassName);
    // register WS component
    ComponentDescription componentDescription = new WSComponentDescription(componentName, componentClassName, moduleDescription, unit.getServiceName());
    moduleDescription.addComponent(componentDescription);
    // register WS dependency
    final ServiceName endpointServiceName = EndpointService.getServiceName(unit, dependsOnEndpointClassName);
    componentDescription.addDependency(endpointServiceName, ServiceBuilder.DependencyType.REQUIRED);
    return componentDescription;
}
Also used : WSComponentDescription(org.jboss.as.webservices.injection.WSComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) WSComponentDescription(org.jboss.as.webservices.injection.WSComponentDescription)

Example 38 with EEModuleDescription

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

the class WSRefAnnotationProcessor method processRef.

private static void processRef(final DeploymentUnit unit, final String type, final WSRefAnnotationWrapper annotation, final ClassInfo classInfo, final InjectionTarget injectionTarget, final String bindingName) throws DeploymentUnitProcessingException {
    final EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final AnnotatedElement target = createAnnotatedElement(unit, classInfo, injectionTarget);
    final String componentClassName = classInfo.name().toString();
    final Map<String, String> bindingMap = new HashMap<String, String>();
    boolean isEJB = false;
    for (final ComponentDescription componentDescription : moduleDescription.getComponentsByClassName(componentClassName)) {
        if (componentDescription instanceof SessionBeanComponentDescription) {
            isEJB = true;
            bindingMap.put(componentDescription.getComponentName() + "/" + bindingName, bindingName);
        }
    }
    if (!isEJB) {
        bindingMap.put(bindingName, bindingName);
    }
    for (String refKey : bindingMap.keySet()) {
        String refName = bindingMap.get(refKey);
        ManagedReferenceFactory factory = WebServiceReferences.createWebServiceFactory(unit, type, annotation, target, refName, refKey);
        final EEModuleClassDescription classDescription = moduleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
        // Create the binding from whence our injection comes.
        final InjectionSource serviceRefSource = new FixedInjectionSource(factory, factory);
        final BindingConfiguration bindingConfiguration = new BindingConfiguration(refName, serviceRefSource);
        classDescription.getBindingConfigurations().add(bindingConfiguration);
        // our injection comes from the local lookup, no matter what.
        final ResourceInjectionConfiguration injectionConfiguration = injectionTarget != null ? new ResourceInjectionConfiguration(injectionTarget, new LookupInjectionSource(refName)) : null;
        if (injectionConfiguration != null) {
            classDescription.addResourceInjection(injectionConfiguration);
        }
    }
}
Also used : SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) HashMap(java.util.HashMap) AnnotatedElement(java.lang.reflect.AnnotatedElement) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) FixedInjectionSource(org.jboss.as.ee.component.FixedInjectionSource) FixedInjectionSource(org.jboss.as.ee.component.FixedInjectionSource) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Example 39 with EEModuleDescription

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

the class WebIntegrationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription module = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        WeldLogger.DEPLOYMENT_LOGGER.debug("Not installing Weld web tier integration as no war metadata found");
        return;
    }
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        WeldLogger.DEPLOYMENT_LOGGER.debug("Not installing Weld web tier integration as no merged web metadata found");
        return;
    }
    if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        if (WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
            createDependency(deploymentUnit, warMetaData);
        }
        return;
    }
    createDependency(deploymentUnit, warMetaData);
    List<ListenerMetaData> listeners = webMetaData.getListeners();
    if (listeners == null) {
        listeners = new ArrayList<ListenerMetaData>();
        webMetaData.setListeners(listeners);
    } else {
        //if the weld servlet listener is present remove it
        //this should allow wars to be portable between AS7 and servlet containers
        final ListIterator<ListenerMetaData> iterator = listeners.listIterator();
        while (iterator.hasNext()) {
            final ListenerMetaData listener = iterator.next();
            if (listener.getListenerClass().trim().equals(WELD_SERVLET_LISTENER)) {
                WeldLogger.DEPLOYMENT_LOGGER.debugf("Removing weld servlet listener %s from web config, as it is not needed in EE6 environments", WELD_SERVLET_LISTENER);
                iterator.remove();
                break;
            }
        }
    }
    listeners.add(0, INITIAL_LISTENER_METADATA);
    listeners.add(TERMINAL_LISTENER_MEDATADA);
    //These listeners use resource injection, so they need to be components
    registerAsComponent(WELD_INITIAL_LISTENER, deploymentUnit);
    registerAsComponent(WELD_TERMINAL_LISTENER, deploymentUnit);
    deploymentUnit.addToAttachmentList(ExpressionFactoryWrapper.ATTACHMENT_KEY, WeldJspExpressionFactoryWrapper.INSTANCE);
    if (webMetaData.getContextParams() == null) {
        webMetaData.setContextParams(new ArrayList<ParamValueMetaData>());
    }
    final List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
    setupWeldContextIgnores(contextParams, InitParameters.CONTEXT_IGNORE_FORWARD);
    setupWeldContextIgnores(contextParams, InitParameters.CONTEXT_IGNORE_INCLUDE);
    if (webMetaData.getFilterMappings() != null) {
        // register ConversationFilter
        boolean filterMappingFound = false;
        for (FilterMappingMetaData mapping : webMetaData.getFilterMappings()) {
            if (CONVERSATION_FILTER_NAME.equals(mapping.getFilterName())) {
                filterMappingFound = true;
                break;
            }
        }
        if (filterMappingFound) {
            // otherwise WeldListener will take care of conversation context activation
            boolean filterFound = false;
            // register ConversationFilter
            if (webMetaData.getFilters() == null) {
                webMetaData.setFilters(new FiltersMetaData());
            }
            for (FilterMetaData filter : webMetaData.getFilters()) {
                if (CONVERSATION_FILTER_CLASS.equals(filter.getFilterClass())) {
                    filterFound = true;
                    break;
                }
            }
            if (!filterFound) {
                webMetaData.getFilters().add(conversationFilterMetadata);
                registerAsComponent(CONVERSATION_FILTER_CLASS, deploymentUnit);
                webMetaData.getContextParams().add(CONVERSATION_FILTER_INITIALIZED);
            }
        }
    }
}
Also used : ParamValueMetaData(org.jboss.metadata.javaee.spec.ParamValueMetaData) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) FilterMetaData(org.jboss.metadata.web.spec.FilterMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) FiltersMetaData(org.jboss.metadata.web.spec.FiltersMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) FilterMappingMetaData(org.jboss.metadata.web.spec.FilterMappingMetaData)

Example 40 with EEModuleDescription

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

the class WeldImplicitDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        return;
    }
    if (Utils.getRootDeploymentUnit(deploymentUnit).getAttachment(WeldConfiguration.ATTACHMENT_KEY).isRequireBeanDescriptor()) {
        // if running in the require-bean-descriptor mode then bean archives are found by BeansXmlProcessor
        return;
    }
    /*
         * look for classes with bean defining annotations
         */
    final Set<AnnotationType> beanDefiningAnnotations = new HashSet<>(getRootDeploymentUnit(deploymentUnit).getAttachment(WeldAttachments.BEAN_DEFINING_ANNOTATIONS));
    final Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
    final ExplicitBeanArchiveMetadataContainer explicitBeanArchiveMetadata = deploymentUnit.getAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY);
    final ResourceRoot classesRoot = deploymentUnit.getAttachment(WeldAttachments.CLASSES_RESOURCE_ROOT);
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    for (Entry<ResourceRoot, Index> entry : indexes.entrySet()) {
        ResourceRoot resourceRoot = entry.getKey();
        if (resourceRoot == classesRoot) {
            // BDA for WEB-INF/classes is keyed under deploymentRoot in explicitBeanArchiveMetadata
            resourceRoot = deploymentRoot;
        }
        /*
             * Make sure bean defining annotations used in archives with bean-discovery-mode="none" are not considered here
             * WFLY-4388
             */
        if (explicitBeanArchiveMetadata != null && explicitBeanArchiveMetadata.getBeanArchiveMetadata().containsKey(resourceRoot)) {
            continue;
        }
        for (final AnnotationType annotation : beanDefiningAnnotations) {
            if (!entry.getValue().getAnnotations(annotation.getName()).isEmpty()) {
                WeldDeploymentMarker.mark(deploymentUnit);
                return;
            }
        }
    }
    /*
         * look for session beans and managed beans
         */
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final Iterable<ImplicitBeanArchiveDetector> detectors = ServiceLoader.load(ImplicitBeanArchiveDetector.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldImplicitDeploymentProcessor.class));
    for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
        for (ImplicitBeanArchiveDetector detector : detectors) {
            if (detector.isImplicitBeanArchiveRequired(component)) {
                WeldDeploymentMarker.mark(deploymentUnit);
                return;
            }
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) Index(org.jboss.jandex.Index) AnnotationType(org.jboss.as.weld.discovery.AnnotationType) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ImplicitBeanArchiveDetector(org.jboss.as.weld.spi.ImplicitBeanArchiveDetector) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit) ExplicitBeanArchiveMetadataContainer(org.jboss.as.weld.deployment.ExplicitBeanArchiveMetadataContainer) HashSet(java.util.HashSet)

Aggregations

EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)90 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)77 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)44 Module (org.jboss.modules.Module)27 ServiceName (org.jboss.msc.service.ServiceName)21 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)18 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)17 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)16 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)16 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)11 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)11 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)10 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 AnnotationInstance (org.jboss.jandex.AnnotationInstance)9 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)8 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)8 EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)7 Map (java.util.Map)6