Search in sources :

Example 6 with DeploymentUnitProcessingException

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

the class ServiceDeploymentParsingProcessor method deploy.

/**
     * Process a deployment for jboss-service.xml files. Will parse the xml file and attach a configuration discovered
     * during processing.
     *
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    if (deploymentRoot == null || !deploymentRoot.exists())
        return;
    VirtualFile serviceXmlFile = null;
    if (deploymentRoot.isDirectory()) {
        serviceXmlFile = deploymentRoot.getChild(SERVICE_DESCRIPTOR_PATH);
    } else if (deploymentRoot.getName().toLowerCase(Locale.ENGLISH).endsWith(SERVICE_DESCRIPTOR_SUFFIX)) {
        serviceXmlFile = deploymentRoot;
    }
    if (serviceXmlFile == null || !serviceXmlFile.exists())
        return;
    final XMLMapper xmlMapper = XMLMapper.Factory.create();
    final JBossServiceXmlDescriptorParser jBossServiceXmlDescriptorParser = new JBossServiceXmlDescriptorParser(JBossDescriptorPropertyReplacement.propertyReplacer(phaseContext.getDeploymentUnit()));
    xmlMapper.registerRootElement(new QName("urn:jboss:service:7.0", "server"), jBossServiceXmlDescriptorParser);
    xmlMapper.registerRootElement(new QName(null, "server"), jBossServiceXmlDescriptorParser);
    InputStream xmlStream = null;
    try {
        xmlStream = serviceXmlFile.openStream();
        final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream);
        final ParseResult<JBossServiceXmlDescriptor> result = new ParseResult<JBossServiceXmlDescriptor>();
        xmlMapper.parseDocument(result, reader);
        final JBossServiceXmlDescriptor xmlDescriptor = result.getResult();
        if (xmlDescriptor != null)
            phaseContext.getDeploymentUnit().putAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
        else
            throw SarLogger.ROOT_LOGGER.failedXmlParsing(serviceXmlFile);
    } catch (Exception e) {
        throw SarLogger.ROOT_LOGGER.failedXmlParsing(e, serviceXmlFile);
    } finally {
        VFSUtils.safeClose(xmlStream);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLMapper(org.jboss.staxmapper.XMLMapper) JBossServiceXmlDescriptor(org.jboss.as.service.descriptor.JBossServiceXmlDescriptor) XMLStreamReader(javax.xml.stream.XMLStreamReader) ParseResult(org.jboss.as.service.descriptor.ParseResult) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) JBossServiceXmlDescriptorParser(org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 7 with DeploymentUnitProcessingException

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

the class ServletContainerInitializerDeploymentProcessor method loadSci.

private List<ServletContainerInitializer> loadSci(ClassLoader classLoader, VirtualFile sci, String jar, boolean error, Set<Class<? extends ServletContainerInitializer>> sciClasses) throws DeploymentUnitProcessingException {
    final List<ServletContainerInitializer> scis = new ArrayList<ServletContainerInitializer>();
    InputStream is = null;
    try {
        // Get the ServletContainerInitializer class name
        is = sci.openStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        String servletContainerInitializerClassName = reader.readLine();
        while (servletContainerInitializerClassName != null) {
            try {
                int pos = servletContainerInitializerClassName.indexOf('#');
                if (pos >= 0) {
                    servletContainerInitializerClassName = servletContainerInitializerClassName.substring(0, pos);
                }
                servletContainerInitializerClassName = servletContainerInitializerClassName.trim();
                if (!servletContainerInitializerClassName.isEmpty()) {
                    // Instantiate the ServletContainerInitializer
                    ServletContainerInitializer service = (ServletContainerInitializer) classLoader.loadClass(servletContainerInitializerClassName).newInstance();
                    if (service != null) {
                        if (sciClasses.add(service.getClass())) {
                            scis.add(service);
                        }
                    }
                }
                servletContainerInitializerClassName = reader.readLine();
            } catch (Exception e) {
                if (error) {
                    throw UndertowLogger.ROOT_LOGGER.errorProcessingSCI(jar, e);
                } else {
                    UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
                }
            }
        }
    } catch (Exception e) {
        if (error) {
            throw UndertowLogger.ROOT_LOGGER.errorProcessingSCI(jar, e);
        } else {
            UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
        }
    } finally {
        try {
            if (is != null)
                is.close();
        } catch (IOException e) {
        // Ignore
        }
    }
    return scis;
}
Also used : ServletContainerInitializer(javax.servlet.ServletContainerInitializer) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException)

Example 8 with DeploymentUnitProcessingException

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

the class TldParsingDeploymentProcessor method processTlds.

private void processTlds(VirtualFile root, List<VirtualFile> files, Map<String, TldMetaData> tlds, final List<TldMetaData> uniqueTlds) throws DeploymentUnitProcessingException {
    for (VirtualFile file : files) {
        if (file.isFile() && file.getName().toLowerCase(Locale.ENGLISH).endsWith(TLD)) {
            String pathNameRelativeToRoot;
            try {
                pathNameRelativeToRoot = file.getPathNameRelativeTo(root);
            } catch (IllegalArgumentException e) {
                throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(file.getPathName(), root.getPathName()), e);
            }
            final TldMetaData value = parseTLD(file);
            String key = "/" + pathNameRelativeToRoot;
            uniqueTlds.add(value);
            if (!tlds.containsKey(key)) {
                tlds.put(key, value);
            }
        } else if (file.isDirectory()) {
            processTlds(root, file.getChildren(), tlds, uniqueTlds);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) TldMetaData(org.jboss.metadata.web.spec.TldMetaData)

Example 9 with DeploymentUnitProcessingException

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

the class TldParsingDeploymentProcessor 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;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null || warMetaData.getMergedJBossWebMetaData() == null) {
        return;
    }
    TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
    if (tldsMetaData == null) {
        tldsMetaData = new TldsMetaData();
        deploymentUnit.putAttachment(TldsMetaData.ATTACHMENT_KEY, tldsMetaData);
    }
    Map<String, TldMetaData> tlds = new HashMap<String, TldMetaData>();
    tldsMetaData.setTlds(tlds);
    final List<TldMetaData> uniqueTlds = new ArrayList<>();
    final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    final List<VirtualFile> testRoots = new ArrayList<VirtualFile>();
    testRoots.add(deploymentRoot);
    testRoots.add(deploymentRoot.getChild(WEB_INF));
    testRoots.add(deploymentRoot.getChild(META_INF));
    for (ResourceRoot root : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
        testRoots.add(root.getRoot());
        testRoots.add(root.getRoot().getChild(META_INF));
    }
    JspConfigMetaData merged = warMetaData.getMergedJBossWebMetaData().getJspConfig();
    if (merged != null && merged.getTaglibs() != null) {
        for (final TaglibMetaData tld : merged.getTaglibs()) {
            boolean found = false;
            for (final VirtualFile root : testRoots) {
                VirtualFile child = root.getChild(tld.getTaglibLocation());
                if (child.exists()) {
                    String pathNameRelativeToRoot;
                    try {
                        pathNameRelativeToRoot = child.getPathNameRelativeTo(deploymentRoot);
                    } catch (IllegalArgumentException e) {
                        throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(child.getPathName(), deploymentRoot.getPathName()), e);
                    }
                    final TldMetaData value = parseTLD(child);
                    value.setUri(tld.getTaglibUri());
                    uniqueTlds.add(value);
                    String key = "/" + pathNameRelativeToRoot;
                    if (!tlds.containsKey(key)) {
                        tlds.put(key, value);
                    }
                    if (!tlds.containsKey(tld.getTaglibUri())) {
                        tlds.put(tld.getTaglibUri(), value);
                    }
                    found = true;
                    break;
                }
            }
            if (!found) {
                UndertowLogger.ROOT_LOGGER.tldNotFound(tld.getTaglibLocation());
            }
        }
    }
    // TLDs are located in WEB-INF or any subdir (except the top level "classes" and "lib")
    // and in JARs from WEB-INF/lib, in META-INF or any subdir
    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(META_INF);
            if (webFragment.exists() && webFragment.isDirectory()) {
                processTlds(deploymentRoot, webFragment.getChildren(), tlds, uniqueTlds);
            }
        }
    }
    VirtualFile webInf = deploymentRoot.getChild(WEB_INF);
    if (webInf.exists() && webInf.isDirectory()) {
        for (VirtualFile file : webInf.getChildren()) {
            if (file.isFile() && file.getName().toLowerCase(Locale.ENGLISH).endsWith(TLD)) {
                String pathNameRelativeToRoot;
                try {
                    pathNameRelativeToRoot = file.getPathNameRelativeTo(deploymentRoot);
                } catch (IllegalArgumentException e) {
                    throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.tldFileNotContainedInRoot(file.getPathName(), deploymentRoot.getPathName()), e);
                }
                final TldMetaData value = parseTLD(file);
                uniqueTlds.add(value);
                String key = "/" + pathNameRelativeToRoot;
                if (!tlds.containsKey(key)) {
                    tlds.put(key, value);
                }
            } else if (file.isDirectory() && !CLASSES.equals(file.getName()) && !LIB.equals(file.getName())) {
                processTlds(deploymentRoot, file.getChildren(), tlds, uniqueTlds);
            }
        }
    }
    JBossWebMetaData mergedMd = warMetaData.getMergedJBossWebMetaData();
    if (mergedMd.getListeners() == null) {
        mergedMd.setListeners(new ArrayList<ListenerMetaData>());
    }
    final ArrayList<TldMetaData> allTlds = new ArrayList<>(uniqueTlds);
    allTlds.addAll(tldsMetaData.getSharedTlds(deploymentUnit));
    for (final TldMetaData tld : allTlds) {
        if (tld.getListeners() != null) {
            for (ListenerMetaData l : tld.getListeners()) {
                mergedMd.getListeners().add(l);
            }
        }
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) HashMap(java.util.HashMap) WarMetaData(org.jboss.as.web.common.WarMetaData) ArrayList(java.util.ArrayList) JspConfigMetaData(org.jboss.metadata.web.spec.JspConfigMetaData) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) TaglibMetaData(org.jboss.metadata.web.spec.TaglibMetaData) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 10 with DeploymentUnitProcessingException

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

the class JBossWebParsingDeploymentProcessor 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;
    }
    final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    final VirtualFile jbossWebXml = deploymentRoot.getChild(JBOSS_WEB_XML);
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    assert warMetaData != null;
    if (jbossWebXml.exists()) {
        InputStream is = null;
        try {
            is = jbossWebXml.openStream();
            final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            inputFactory.setXMLResolver(NoopXMLResolver.create());
            XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
            final JBossWebMetaData jBossWebMetaData = JBossWebMetaDataParser.parse(xmlReader, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
            warMetaData.setJBossWebMetaData(jBossWebMetaData);
            // deployment unit
            if (jBossWebMetaData.getValves() != null) {
                for (ValveMetaData valve : jBossWebMetaData.getValves()) {
                    UndertowLogger.ROOT_LOGGER.unsupportedValveFeature(valve.getValveClass());
                }
            }
            if (jBossWebMetaData.getDistinctName() != null) {
                deploymentUnit.putAttachment(org.jboss.as.ee.structure.Attachments.DISTINCT_NAME, jBossWebMetaData.getDistinctName());
            }
        } catch (XMLStreamException e) {
            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(jbossWebXml.toString(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()), e);
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(jbossWebXml.toString()), e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    } else {
        //jboss web embedded inside jboss-all.xml
        final JBossWebMetaData jbMeta = deploymentUnit.getAttachment(WebJBossAllParser.ATTACHMENT_KEY);
        if (jbMeta != null) {
            warMetaData.setJBossWebMetaData(jbMeta);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) WarMetaData(org.jboss.as.web.common.WarMetaData) IOException(java.io.IOException) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ValveMetaData(org.jboss.metadata.web.jboss.ValveMetaData) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)95 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)45 Module (org.jboss.modules.Module)28 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)26 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)26 VirtualFile (org.jboss.vfs.VirtualFile)22 InputStream (java.io.InputStream)20 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)18 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)18 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)18 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)17 ViewDescription (org.jboss.as.ee.component.ViewDescription)16 Method (java.lang.reflect.Method)15 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)15 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)15 ServiceName (org.jboss.msc.service.ServiceName)15 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)14 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)12 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)12