use of javax.xml.stream.XMLStreamException in project OpenRefine by OpenRefine.
the class XmlImporter method createParserUIInitializationData.
@Override
public JSONObject createParserUIInitializationData(ImportingJob job, List<JSONObject> fileRecords, String format) {
JSONObject options = super.createParserUIInitializationData(job, fileRecords, format);
try {
if (fileRecords.size() > 0) {
JSONObject firstFileRecord = fileRecords.get(0);
File file = ImportingUtilities.getFile(job, firstFileRecord);
InputStream is = new FileInputStream(file);
try {
XMLStreamReader parser = createXMLStreamReader(is);
PreviewParsingState state = new PreviewParsingState();
while (parser.hasNext() && state.tokenCount < PREVIEW_PARSING_LIMIT) {
int tokenType = parser.next();
state.tokenCount++;
if (tokenType == XMLStreamConstants.START_ELEMENT) {
JSONObject rootElement = descendElement(parser, state);
if (rootElement != null) {
JSONUtilities.safePut(options, "dom", rootElement);
break;
}
} else {
// ignore everything else
}
}
} catch (XMLStreamException e) {
logger.warn("Error generating parser UI initialization data for XML file", e);
} finally {
is.close();
}
}
} catch (IOException e) {
logger.error("Error generating parser UI initialization data for XML file", e);
}
return options;
}
use of javax.xml.stream.XMLStreamException in project wildfly by wildfly.
the class EjbJarParsingDeploymentUnitProcessor method getXMLStreamReader.
/**
* Creates and returns a {@link XMLStreamReader} for the passed {@link VirtualFile ejb-jar.xml}
*
* @param stream The input stream
* @param ejbJarXml
* @return
* @throws DeploymentUnitProcessingException
*
*/
private static XMLStreamReader getXMLStreamReader(InputStream stream, VirtualFile ejbJarXml, XMLResolver resolver) throws DeploymentUnitProcessingException {
try {
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(resolver);
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(stream);
return xmlReader;
} catch (XMLStreamException xmlse) {
throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, "ejb-jar.xml: " + ejbJarXml.getPathName());
}
}
use of javax.xml.stream.XMLStreamException in project wildfly by wildfly.
the class EjbTimerXmlPersister method writeCalendarTimer.
private void writeCalendarTimer(XMLExtendedStreamWriter writer, CalendarTimer timer) throws XMLStreamException {
String info = null;
String primaryKey = null;
if (timer.getInfo() != null) {
try {
Marshaller marshaller = factory.createMarshaller(configuration);
ByteArrayOutputStream out = new ByteArrayOutputStream();
marshaller.start(new OutputStreamByteOutput(out));
marshaller.writeObject(timer.getInfo());
marshaller.finish();
marshaller.flush();
info = Base64.getEncoder().encodeToString(out.toByteArray());
} catch (Exception e) {
EjbLogger.EJB3_TIMER_LOGGER.failedToPersistTimer(timer, e);
return;
}
}
if (timer.getPrimaryKey() != null) {
try {
Marshaller marshaller = factory.createMarshaller(configuration);
ByteArrayOutputStream out = new ByteArrayOutputStream();
marshaller.start(new OutputStreamByteOutput(out));
marshaller.writeObject(timer.getPrimaryKey());
marshaller.finish();
marshaller.flush();
primaryKey = Base64.getEncoder().encodeToString(out.toByteArray());
} catch (Exception e) {
EjbLogger.EJB3_TIMER_LOGGER.failedToPersistTimer(timer, e);
return;
}
}
writer.writeStartElement(CALENDAR_TIMER);
writer.writeAttribute(TIMED_OBJECT_ID, timer.getTimedObjectId());
writer.writeAttribute(TIMER_ID, timer.getId());
if (timer.getInitialExpiration() != null) {
writer.writeAttribute(INITIAL_DATE, Long.toString(timer.getInitialExpiration().getTime()));
}
if (timer.getNextExpiration() != null) {
writer.writeAttribute(NEXT_DATE, Long.toString(timer.getNextExpiration().getTime()));
}
writer.writeAttribute(TIMER_STATE, timer.getState().name());
writer.writeAttribute(SCHEDULE_EXPR_SECOND, timer.getScheduleExpression().getSecond());
writer.writeAttribute(SCHEDULE_EXPR_MINUTE, timer.getScheduleExpression().getMinute());
writer.writeAttribute(SCHEDULE_EXPR_HOUR, timer.getScheduleExpression().getHour());
writer.writeAttribute(SCHEDULE_EXPR_DAY_OF_WEEK, timer.getScheduleExpression().getDayOfWeek());
writer.writeAttribute(SCHEDULE_EXPR_DAY_OF_MONTH, timer.getScheduleExpression().getDayOfMonth());
writer.writeAttribute(SCHEDULE_EXPR_MONTH, timer.getScheduleExpression().getMonth());
writer.writeAttribute(SCHEDULE_EXPR_YEAR, timer.getScheduleExpression().getYear());
if (timer.getScheduleExpression().getStart() != null) {
writer.writeAttribute(SCHEDULE_EXPR_START_DATE, Long.toString(timer.getScheduleExpression().getStart().getTime()));
}
if (timer.getScheduleExpression().getEnd() != null) {
writer.writeAttribute(SCHEDULE_EXPR_END_DATE, Long.toString(timer.getScheduleExpression().getEnd().getTime()));
}
if (timer.getScheduleExpression().getTimezone() != null) {
writer.writeAttribute(SCHEDULE_EXPR_TIMEZONE, timer.getScheduleExpression().getTimezone());
}
if (info != null) {
writer.writeStartElement(INFO);
writer.writeCharacters(info);
writer.writeEndElement();
}
if (primaryKey != null) {
writer.writeStartElement(PRIMARY_KEY);
writer.writeCharacters(primaryKey);
writer.writeEndElement();
}
if (timer.isAutoTimer()) {
writer.writeStartElement(TIMEOUT_METHOD);
writer.writeAttribute(DECLARING_CLASS, timer.getTimeoutMethod().getDeclaringClass().getName());
writer.writeAttribute(NAME, timer.getTimeoutMethod().getName());
for (Class<?> param : timer.getTimeoutMethod().getParameterTypes()) {
writer.writeStartElement(PARAMETER);
writer.writeAttribute(TYPE, param.getName());
writer.writeEndElement();
}
writer.writeEndElement();
}
writer.writeEndElement();
}
use of javax.xml.stream.XMLStreamException in project wildfly by wildfly.
the class SubsystemOperationsTestCase method testRemoveThreadPool.
@Test
public void testRemoveThreadPool() throws Exception {
final KernelServices kernelServices = boot(getSubsystemXml("/minimal-subsystem.xml"));
final ModelNode address = createAddress(BatchSubsystemDefinition.THREAD_POOL_PATH);
// Remove the thread pool
final ModelNode removeOp = SubsystemOperations.createRemoveOperation(address);
executeOperation(kernelServices, removeOp);
// Reboot with a default thread pool
String marshalledXml = kernelServices.getPersistedSubsystemXml();
try {
boot(marshalledXml);
Assert.fail("Should be missing <thread-pool/>");
} catch (XMLStreamException ignore) {
}
// Add back a thread-pool, must be named batch
final ModelNode addOp = SubsystemOperations.createAddOperation(address);
addOp.get("max-threads").set(10);
final ModelNode keepAlive = addOp.get("keepalive-time");
keepAlive.get("time").set(100L);
keepAlive.get("unit").set(TimeUnit.MILLISECONDS.toString());
executeOperation(kernelServices, addOp);
// Get the serialized output and boot
marshalledXml = kernelServices.getPersistedSubsystemXml();
try {
final KernelServices k = boot(marshalledXml);
Assert.assertTrue(k.isSuccessfulBoot());
} catch (XMLStreamException e) {
final StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
Assert.fail("Failed to parse XML; " + writer.toString());
}
// Remove and add in a composite operation
final Operation compositeOp = CompositeOperationBuilder.create().addStep(removeOp).addStep(addOp).build();
executeOperation(kernelServices, compositeOp);
// Get the serialized output and boot
marshalledXml = kernelServices.getPersistedSubsystemXml();
try {
final KernelServices k = boot(marshalledXml);
Assert.assertTrue(k.isSuccessfulBoot());
} catch (XMLStreamException e) {
final StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
Assert.fail("Failed to parse XML; " + writer.toString());
}
}
use of javax.xml.stream.XMLStreamException 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);
}
}
}
Aggregations