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);
}
}
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();
}
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();
}
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;
}
}
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();
}
Aggregations