Search in sources :

Example 56 with XMLStreamException

use of javax.xml.stream.XMLStreamException 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 57 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project wildfly by wildfly.

the class WSDeploymentAspectParser method parseDeploymentAspect.

private static DeploymentAspect parseDeploymentAspect(XMLStreamReader reader, ClassLoader loader) throws XMLStreamException {
    String deploymentAspectClass = reader.getAttributeValue(null, CLASS);
    if (deploymentAspectClass == null) {
        throw WSLogger.ROOT_LOGGER.missingDeploymentAspectClassAttribute();
    }
    DeploymentAspect deploymentAspect = null;
    try {
        @SuppressWarnings("unchecked") Class<? extends DeploymentAspect> clazz = (Class<? extends DeploymentAspect>) Class.forName(deploymentAspectClass, true, loader);
        ClassLoader orig = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
        try {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(loader);
            deploymentAspect = clazz.newInstance();
        } finally {
            WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(orig);
        }
    } catch (Exception e) {
        throw WSLogger.ROOT_LOGGER.cannotInstantiateDeploymentAspect(e, deploymentAspectClass);
    }
    String priority = reader.getAttributeValue(null, PRIORITY);
    if (priority != null) {
        deploymentAspect.setRelativeOrder(Integer.parseInt(priority.trim()));
    }
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT:
                {
                    if (match(reader, NS, DEPLOYMENT_ASPECT)) {
                        return deploymentAspect;
                    } else {
                        throw WSLogger.ROOT_LOGGER.unexpectedEndTag(reader.getLocalName());
                    }
                }
            case XMLStreamConstants.START_ELEMENT:
                {
                    if (match(reader, NS, PROPERTY)) {
                        parseProperty(reader, deploymentAspect, loader);
                    } else {
                        throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName());
                    }
                }
        }
    }
    throw WSLogger.ROOT_LOGGER.unexpectedEndOfDocument();
}
Also used : DeploymentAspect(org.jboss.wsf.spi.deployment.DeploymentAspect) WebServiceException(javax.xml.ws.WebServiceException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 58 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project wildfly by wildfly.

the class WSDeploymentAspectParser method parseProperty.

@SuppressWarnings("rawtypes")
private static void parseProperty(XMLStreamReader reader, DeploymentAspect deploymentAspect, ClassLoader loader) throws XMLStreamException {
    Class<? extends DeploymentAspect> deploymentAspectClass = deploymentAspect.getClass();
    String propName = reader.getAttributeValue(null, NAME);
    if (propName == null) {
        throw WSLogger.ROOT_LOGGER.missingPropertyNameAttribute(deploymentAspect);
    }
    String propClass = reader.getAttributeValue(null, CLASS);
    if (propClass == null) {
        throw WSLogger.ROOT_LOGGER.missingPropertyClassAttribute(deploymentAspect);
    } else {
        try {
            if (isSupportedPropertyClass(propClass)) {
                Method m = selectMethod(deploymentAspectClass, propName, propClass);
                m.invoke(deploymentAspect, parseSimpleValue(reader, propClass));
                return;
            }
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    while (reader.hasNext()) {
        switch(reader.nextTag()) {
            case XMLStreamConstants.END_ELEMENT:
                {
                    if (match(reader, NS, PROPERTY)) {
                        return;
                    } else {
                        throw WSLogger.ROOT_LOGGER.unexpectedEndTag(reader.getLocalName());
                    }
                }
            case XMLStreamConstants.START_ELEMENT:
                {
                    if (match(reader, NS, MAP)) {
                        try {
                            Method m = selectMethod(deploymentAspectClass, propName, propClass);
                            Map map = parseMapProperty(reader, propClass, reader.getAttributeValue(null, KEY_CLASS), reader.getAttributeValue(null, VALUE_CLASS), loader);
                            m.invoke(deploymentAspect, map);
                        } catch (Exception e) {
                            throw new IllegalStateException(e);
                        }
                    } else if (match(reader, NS, LIST)) {
                        try {
                            Method m = selectMethod(deploymentAspectClass, propName, propClass);
                            List list = parseListProperty(reader, propClass, reader.getAttributeValue(null, ELEMENT_CLASS));
                            m.invoke(deploymentAspect, list);
                        } catch (Exception e) {
                            throw new IllegalStateException(e);
                        }
                    } else {
                        throw WSLogger.ROOT_LOGGER.unexpectedElement(reader.getLocalName());
                    }
                }
        }
    }
    throw WSLogger.ROOT_LOGGER.unexpectedEndOfDocument();
}
Also used : List(java.util.List) LinkedList(java.util.LinkedList) Method(java.lang.reflect.Method) Map(java.util.Map) WebServiceException(javax.xml.ws.WebServiceException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 59 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project wildfly by wildfly.

the class ApplicationClientParsingDeploymentProcessor method parseAppClient.

private ApplicationClientMetaData parseAppClient(DeploymentUnit deploymentUnit, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR);
    // Locate the descriptor
    final VirtualFile descriptor;
    if (alternateDescriptor != null) {
        descriptor = alternateDescriptor;
    } else {
        descriptor = deploymentRoot.getRoot().getChild(APP_XML);
    }
    if (descriptor.exists()) {
        InputStream is = null;
        try {
            is = descriptor.openStream();
            ApplicationClientMetaData data = new ApplicationClientMetaDataParser().parse(getXMLStreamReader(is), propertyReplacer);
            return data;
        } catch (XMLStreamException e) {
            throw AppClientLogger.ROOT_LOGGER.failedToParseXml(e, descriptor, e.getLocation().getLineNumber(), e.getLocation().getColumnNumber());
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException("Failed to parse " + descriptor, e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    } else {
        return null;
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) IOException(java.io.IOException) ApplicationClientMetaDataParser(org.jboss.metadata.appclient.parser.spec.ApplicationClientMetaDataParser)

Example 60 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project uPortal by Jasig.

the class XmlUtilitiesImpl method serializeXMLEvents.

@Override
public String serializeXMLEvents(List<XMLEvent> xmlEvents, boolean isHtml) {
    final XMLOutputFactory outputFactory;
    if (isHtml) {
        outputFactory = this.getHtmlOutputFactory();
    } else {
        outputFactory = this.getXmlOutputFactory();
    }
    final StringWriter writer = new StringWriter();
    final XMLEventWriter xmlEventWriter;
    try {
        xmlEventWriter = new IndentingXMLEventWriter(outputFactory.createXMLEventWriter(writer));
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to create XMLEventWriter", e);
    }
    try {
        for (final XMLEvent bufferedEvent : xmlEvents) {
            xmlEventWriter.add(bufferedEvent);
        }
        xmlEventWriter.flush();
        xmlEventWriter.close();
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to write XMLEvents to XMLEventWriter", e);
    }
    return writer.toString();
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventWriter(javax.xml.stream.XMLEventWriter) IndentingXMLEventWriter(org.apereo.portal.xml.stream.IndentingXMLEventWriter) IndentingXMLEventWriter(org.apereo.portal.xml.stream.IndentingXMLEventWriter) XMLEvent(javax.xml.stream.events.XMLEvent)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)442 XMLStreamReader (javax.xml.stream.XMLStreamReader)137 IOException (java.io.IOException)126 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)75 XMLInputFactory (javax.xml.stream.XMLInputFactory)69 InputStream (java.io.InputStream)66 Document (org.w3c.dom.Document)36 JAXBException (javax.xml.bind.JAXBException)35 Fault (org.apache.cxf.interceptor.Fault)34 Element (org.w3c.dom.Element)32 StringReader (java.io.StringReader)30 XMLEvent (javax.xml.stream.events.XMLEvent)28 DOMSource (javax.xml.transform.dom.DOMSource)27 ByteArrayInputStream (java.io.ByteArrayInputStream)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)23 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)23 Node (org.w3c.dom.Node)22 StringWriter (java.io.StringWriter)21 XMLEventReader (javax.xml.stream.XMLEventReader)20