Search in sources :

Example 76 with DeploymentUnit

use of org.jboss.as.server.deployment.DeploymentUnit in project wildfly by wildfly.

the class WebComponentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        return;
    }
    final Map<String, ComponentDescription> componentByClass = new HashMap<String, ComponentDescription>();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (moduleDescription == null) {
        //not an EE deployment
        return;
    }
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        componentByClass.put(component.getComponentClassName(), component);
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    final TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
    final Set<String> classes = getAllComponentClasses(deploymentUnit, compositeIndex, warMetaData, tldsMetaData);
    for (String clazz : classes) {
        if (clazz == null || clazz.trim().isEmpty()) {
            continue;
        }
        ComponentDescription description = componentByClass.get(clazz);
        if (description != null) {
            //TODO: make sure the component is a managed bean
            if (!(description.getViews().size() == 1)) {
                throw UndertowLogger.ROOT_LOGGER.wrongComponentType(clazz);
            }
        } else {
            //we do not make the standard tags into components, as there is no need
            if (compositeIndex.getClassByName(DotName.createSimple(clazz)) == null) {
                boolean found = false;
                for (String pack : BUILTIN_TAGLIBS) {
                    if (clazz.startsWith(pack)) {
                        found = true;
                        break;
                    }
                }
                if (found) {
                    continue;
                }
            }
            description = new WebComponentDescription(clazz, clazz, moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
            moduleDescription.addComponent(description);
            deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, description.getStartServiceName());
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) WarMetaData(org.jboss.as.web.common.WarMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 77 with DeploymentUnit

use of org.jboss.as.server.deployment.DeploymentUnit in project wildfly by wildfly.

the class WebParsingDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    ClassLoader old = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(WebParsingDeploymentProcessor.class);
        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
        if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
            // Skip non web deployments
            return;
        }
        final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_WEB_DEPLOYMENT_DESCRIPTOR);
        // Locate the descriptor
        final VirtualFile webXml;
        if (alternateDescriptor != null) {
            webXml = alternateDescriptor;
        } else {
            webXml = deploymentRoot.getRoot().getChild(WEB_XML);
        }
        final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        assert warMetaData != null;
        if (webXml.exists()) {
            InputStream is = null;
            try {
                is = webXml.openStream();
                final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
                MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
                inputFactory.setXMLResolver(dtdInfo);
                final XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
                WebMetaData webMetaData = WebMetaDataParser.parse(xmlReader, dtdInfo, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
                if (schemaValidation && webMetaData.getSchemaLocation() != null) {
                    XMLSchemaValidator validator = new XMLSchemaValidator(new XMLResourceResolver());
                    InputStream xmlInput = webXml.openStream();
                    try {
                        if (webMetaData.is23())
                            validator.validate("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", xmlInput);
                        else if (webMetaData.is24())
                            validator.validate("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd", xmlInput);
                        else if (webMetaData.is25())
                            validator.validate("http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd", xmlInput);
                        else if (webMetaData.is30())
                            validator.validate("http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd", xmlInput);
                        else if (webMetaData.is31())
                            validator.validate("http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd", xmlInput);
                        else
                            validator.validate("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", xmlInput);
                    } catch (SAXException e) {
                        throw new DeploymentUnitProcessingException("Failed to validate " + webXml, e);
                    } finally {
                        xmlInput.close();
                    }
                }
                warMetaData.setWebMetaData(webMetaData);
            } catch (XMLStreamException e) {
                Integer lineNumber = null;
                Integer columnNumber = null;
                if (e.getLocation() != null) {
                    lineNumber = e.getLocation().getLineNumber();
                    columnNumber = e.getLocation().getColumnNumber();
                }
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webXml.toString(), lineNumber, columnNumber), e);
            } catch (IOException e) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webXml.toString()), e);
            } finally {
                try {
                    if (is != null) {
                        is.close();
                    }
                } catch (IOException e) {
                // Ignore
                }
            }
        }
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(old);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) XMLResourceResolver(org.jboss.metadata.parser.util.XMLResourceResolver) WarMetaData(org.jboss.as.web.common.WarMetaData) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLStreamException(javax.xml.stream.XMLStreamException) MetaDataElementParser(org.jboss.metadata.parser.util.MetaDataElementParser) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) WebMetaData(org.jboss.metadata.web.spec.WebMetaData) XMLInputFactory(javax.xml.stream.XMLInputFactory) XMLSchemaValidator(org.jboss.metadata.parser.util.XMLSchemaValidator)

Example 78 with DeploymentUnit

use of org.jboss.as.server.deployment.DeploymentUnit in project wildfly by wildfly.

the class UndertowHandlersDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        return;
    }
    handleInfoFile(deploymentUnit, module);
    handleJbossWebXml(deploymentUnit, module);
}
Also used : Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 79 with DeploymentUnit

use of org.jboss.as.server.deployment.DeploymentUnit in project wildfly by wildfly.

the class UndertowJSRWebSocketDeploymentProcessor method installWebsockets.

private void installWebsockets(final DeploymentPhaseContext phaseContext, final WebSocketDeploymentInfo webSocketDeploymentInfo) {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    deploymentUnit.putAttachment(UndertowAttachments.WEB_SOCKET_DEPLOYMENT_INFO, webSocketDeploymentInfo);
}
Also used : DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 80 with DeploymentUnit

use of org.jboss.as.server.deployment.DeploymentUnit in project wildfly by wildfly.

the class UndertowJSRWebSocketDeploymentProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        return;
    }
    ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(module.getClassLoader());
        WarMetaData metaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
        if (metaData == null || metaData.getMergedJBossWebMetaData() == null) {
            return;
        }
        if (!metaData.getMergedJBossWebMetaData().isEnableWebSockets()) {
            return;
        }
        final Set<Class<?>> annotatedEndpoints = new HashSet<>();
        final Set<Class<? extends Endpoint>> endpoints = new HashSet<>();
        final Set<Class<? extends ServerApplicationConfig>> config = new HashSet<>();
        final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
        final List<AnnotationInstance> serverEndpoints = index.getAnnotations(SERVER_ENDPOINT);
        if (serverEndpoints != null) {
            for (AnnotationInstance endpoint : serverEndpoints) {
                if (endpoint.target() instanceof ClassInfo) {
                    ClassInfo clazz = (ClassInfo) endpoint.target();
                    try {
                        Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module);
                        if (!Modifier.isAbstract(moduleClass.getModifiers())) {
                            annotatedEndpoints.add(moduleClass);
                        }
                    } catch (ClassNotFoundException e) {
                        UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketEndpoint(clazz.name().toString(), e);
                    }
                }
            }
        }
        final List<AnnotationInstance> clientEndpoints = index.getAnnotations(CLIENT_ENDPOINT);
        if (clientEndpoints != null) {
            for (AnnotationInstance endpoint : clientEndpoints) {
                if (endpoint.target() instanceof ClassInfo) {
                    ClassInfo clazz = (ClassInfo) endpoint.target();
                    try {
                        Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module);
                        if (!Modifier.isAbstract(moduleClass.getModifiers())) {
                            annotatedEndpoints.add(moduleClass);
                        }
                    } catch (ClassNotFoundException e) {
                        UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketEndpoint(clazz.name().toString(), e);
                    }
                }
            }
        }
        final Set<ClassInfo> subclasses = index.getAllKnownImplementors(SERVER_APPLICATION_CONFIG);
        if (subclasses != null) {
            for (final ClassInfo clazz : subclasses) {
                try {
                    Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module);
                    if (!Modifier.isAbstract(moduleClass.getModifiers())) {
                        config.add((Class) moduleClass);
                    }
                } catch (ClassNotFoundException e) {
                    UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketConfig(clazz.name().toString(), e);
                }
            }
        }
        final Set<ClassInfo> epClasses = index.getAllKnownSubclasses(ENDPOINT);
        if (epClasses != null) {
            for (final ClassInfo clazz : epClasses) {
                try {
                    Class<?> moduleClass = ClassLoadingUtils.loadClass(clazz.name().toString(), module);
                    if (!Modifier.isAbstract(moduleClass.getModifiers())) {
                        endpoints.add((Class) moduleClass);
                    }
                } catch (ClassNotFoundException e) {
                    UndertowLogger.ROOT_LOGGER.couldNotLoadWebSocketConfig(clazz.name().toString(), e);
                }
            }
        }
        WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
        doDeployment(deploymentUnit, webSocketDeploymentInfo, annotatedEndpoints, config, endpoints);
        installWebsockets(phaseContext, webSocketDeploymentInfo);
    } finally {
        Thread.currentThread().setContextClassLoader(oldCl);
    }
}
Also used : WarMetaData(org.jboss.as.web.common.WarMetaData) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) ServerApplicationConfig(javax.websocket.server.ServerApplicationConfig) WebSocketDeploymentInfo(io.undertow.websockets.jsr.WebSocketDeploymentInfo) Endpoint(javax.websocket.Endpoint) ServerEndpoint(javax.websocket.server.ServerEndpoint) ClientEndpoint(javax.websocket.ClientEndpoint) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Aggregations

DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)271 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)77 Module (org.jboss.modules.Module)58 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)49 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)44 ServiceName (org.jboss.msc.service.ServiceName)44 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)43 ArrayList (java.util.ArrayList)33 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)32 VirtualFile (org.jboss.vfs.VirtualFile)30 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)29 WarMetaData (org.jboss.as.web.common.WarMetaData)25 ServiceTarget (org.jboss.msc.service.ServiceTarget)25 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ModuleDependency (org.jboss.as.server.deployment.module.ModuleDependency)24 ModuleLoader (org.jboss.modules.ModuleLoader)24 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)20 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)19 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)17