Search in sources :

Example 36 with WarMetaData

use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.

the class WebFragmentParsingDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    assert warMetaData != null;
    Map<String, WebFragmentMetaData> webFragments = warMetaData.getWebFragmentsMetaData();
    if (webFragments == null) {
        webFragments = new HashMap<String, WebFragmentMetaData>();
        warMetaData.setWebFragmentsMetaData(webFragments);
    }
    List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
    for (ResourceRoot resourceRoot : resourceRoots) {
        if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
            VirtualFile webFragment = resourceRoot.getRoot().getChild(WEB_FRAGMENT_XML);
            if (webFragment.exists() && webFragment.isFile()) {
                InputStream is = null;
                try {
                    is = webFragment.openStream();
                    final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
                    inputFactory.setXMLResolver(NoopXMLResolver.create());
                    XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
                    WebFragmentMetaData webFragmentMetaData = WebFragmentMetaDataParser.parse(xmlReader, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
                    webFragments.put(resourceRoot.getRootName(), webFragmentMetaData);
                    /*Log message to inform that distributable is not set in web-fragment.xml while it is set in web.xml*/
                    if (warMetaData.getWebMetaData() != null && warMetaData.getWebMetaData().getDistributable() != null && webFragmentMetaData.getDistributable() == null)
                        UndertowLogger.ROOT_LOGGER.distributableDisabledInFragmentXml(deploymentUnit.getName(), resourceRoot.getRootName());
                } catch (XMLStreamException e) {
                    throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webFragment.toString(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()));
                } catch (IOException e) {
                    throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webFragment.toString()), e);
                } finally {
                    try {
                        if (is != null) {
                            is.close();
                        }
                    } catch (IOException e) {
                    // Ignore
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) WarMetaData(org.jboss.as.web.common.WarMetaData) IOException(java.io.IOException) WebFragmentMetaData(org.jboss.metadata.web.spec.WebFragmentMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLStreamException(javax.xml.stream.XMLStreamException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 37 with WarMetaData

use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.

the class EarContextRootProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        // Nothing we can do without WarMetaData
        return;
    }
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
    if (deploymentRoot == null) {
        // We don't have a root to work with
        return;
    }
    final DeploymentUnit parent = deploymentUnit.getParent();
    if (parent == null || !DeploymentTypeMarker.isType(DeploymentType.EAR, parent)) {
        // Only care if this war is nested in an EAR
        return;
    }
    final EarMetaData earMetaData = parent.getAttachment(Attachments.EAR_METADATA);
    if (earMetaData == null) {
        // Nothing to see here
        return;
    }
    final ModulesMetaData modulesMetaData = earMetaData.getModules();
    if (modulesMetaData != null)
        for (ModuleMetaData moduleMetaData : modulesMetaData) {
            if (Web.equals(moduleMetaData.getType()) && moduleMetaData.getFileName().equals(deploymentRoot.getRootName())) {
                String contextRoot = WebModuleMetaData.class.cast(moduleMetaData.getValue()).getContextRoot();
                if (contextRoot == null && (warMetaData.getJBossWebMetaData() == null || warMetaData.getJBossWebMetaData().getContextRoot() == null)) {
                    contextRoot = "/" + parent.getName().substring(0, parent.getName().length() - 4) + "/" + deploymentUnit.getName().substring(0, deploymentUnit.getName().length() - 4);
                }
                if (contextRoot != null) {
                    JBossWebMetaData jBossWebMetaData = warMetaData.getJBossWebMetaData();
                    if (jBossWebMetaData == null) {
                        jBossWebMetaData = new JBossWebMetaData();
                        warMetaData.setJBossWebMetaData(jBossWebMetaData);
                    }
                    jBossWebMetaData.setContextRoot(contextRoot);
                }
                return;
            }
        }
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) ModulesMetaData(org.jboss.metadata.ear.spec.ModulesMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) WebModuleMetaData(org.jboss.metadata.ear.spec.WebModuleMetaData) ModuleMetaData(org.jboss.metadata.ear.spec.ModuleMetaData)

Example 38 with WarMetaData

use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.

the class ASHelper method getJBossWebMetaData.

/**
 * Gets the JBossWebMetaData from the WarMetaData attached to the provided deployment unit, if any.
 *
 * @param unit
 * @return the JBossWebMetaData or null if either that or the parent WarMetaData are not found.
 */
public static JBossWebMetaData getJBossWebMetaData(final DeploymentUnit unit) {
    final WarMetaData warMetaData = getOptionalAttachment(unit, WarMetaData.ATTACHMENT_KEY);
    JBossWebMetaData result = null;
    if (warMetaData != null) {
        result = warMetaData.getMergedJBossWebMetaData();
        if (result == null) {
            result = warMetaData.getJBossWebMetaData();
        }
    } else {
        result = getOptionalAttachment(unit, WSAttachmentKeys.JBOSSWEB_METADATA_KEY);
    }
    return result;
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData)

Aggregations

WarMetaData (org.jboss.as.web.common.WarMetaData)38 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)31 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)20 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)14 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)12 VirtualFile (org.jboss.vfs.VirtualFile)11 HashSet (java.util.HashSet)9 Module (org.jboss.modules.Module)9 ArrayList (java.util.ArrayList)8 ParamValueMetaData (org.jboss.metadata.javaee.spec.ParamValueMetaData)8 HashMap (java.util.HashMap)7 JBossServletMetaData (org.jboss.metadata.web.jboss.JBossServletMetaData)6 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)6 IOException (java.io.IOException)5 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)5 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)5 WebMetaData (org.jboss.metadata.web.spec.WebMetaData)5 ServiceName (org.jboss.msc.service.ServiceName)5 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)4 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)4