use of org.jboss.staxmapper.XMLMapper 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);
}
}
use of org.jboss.staxmapper.XMLMapper in project wildfly by wildfly.
the class EJBClientDescriptorParsingProcessor method createMapper.
private XMLMapper createMapper(final DeploymentUnit deploymentUnit) {
final XMLMapper mapper = XMLMapper.Factory.create();
final PropertyReplacer propertyReplacer = EjbClientDescriptorPropertyReplacement.propertyReplacer(deploymentUnit);
final EJBClientDescriptor10Parser ejbClientDescriptor10Parser = new EJBClientDescriptor10Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_0, ejbClientDescriptor10Parser);
final EJBClientDescriptor11Parser ejbClientDescriptor11Parser = new EJBClientDescriptor11Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_1, ejbClientDescriptor11Parser);
final EJBClientDescriptor11Parser ejbClientDescriptor12Parser = new EJBClientDescriptor12Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_2, ejbClientDescriptor12Parser);
final EJBClientDescriptor13Parser ejbClientDescriptor13Parser = new EJBClientDescriptor13Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_3, ejbClientDescriptor13Parser);
mapper.registerRootElement(ROOT_NO_NAMESPACE, ejbClientDescriptor13Parser);
return mapper;
}
use of org.jboss.staxmapper.XMLMapper in project wildfly by wildfly.
the class EJBClientDescriptorParsingProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final XMLMapper mapper = createMapper(deploymentUnit);
final ResourceRoot resourceRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final ServiceModuleLoader moduleLoader = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.SERVICE_MODULE_LOADER);
VirtualFile descriptorFile = null;
for (final String loc : EJB_CLIENT_DESCRIPTOR_LOCATIONS) {
final VirtualFile file = resourceRoot.getRoot().getChild(loc);
if (file.exists()) {
descriptorFile = file;
break;
}
}
if (descriptorFile == null) {
return;
}
if (deploymentUnit.getParent() != null) {
EeLogger.ROOT_LOGGER.subdeploymentIgnored(descriptorFile.getPathName());
return;
}
final File ejbClientDeploymentDescriptorFile;
try {
ejbClientDeploymentDescriptorFile = descriptorFile.getPhysicalFile();
} catch (IOException e) {
throw EeLogger.ROOT_LOGGER.failedToProcessEJBClientDescriptor(e);
}
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = parse(ejbClientDeploymentDescriptorFile, mapper);
EeLogger.ROOT_LOGGER.debugf("Successfully parsed jboss-ejb-client.xml for deployment unit %s", deploymentUnit);
// attach the metadata
deploymentUnit.putAttachment(Attachments.EJB_CLIENT_METADATA, ejbClientDescriptorMetaData);
}
use of org.jboss.staxmapper.XMLMapper in project wildfly by wildfly.
the class FileTimerPersistence method loadTimersFromFile.
private Map<String, TimerImpl> loadTimersFromFile(String timedObjectId, TimerServiceImpl timerService) {
Map<String, TimerImpl> timers = new HashMap<>();
String directory = getDirectory(timedObjectId);
timers.putAll(LegacyFileStore.loadTimersFromFile(timedObjectId, timerService, directory, factory, configuration));
for (Map.Entry<String, TimerImpl> entry : timers.entrySet()) {
//write legacy timers into the new format
writeFile(entry.getValue());
//the legacy code handling code will write a marker file, to make sure that the old timers will not be loaded on next restart.
}
final File file = new File(directory);
if (!file.exists()) {
//no timers exist yet
return timers;
} else if (!file.isDirectory()) {
EJB3_TIMER_LOGGER.failToRestoreTimers(file);
return timers;
}
final XMLMapper mapper = createMapper(timerService);
for (File timerFile : file.listFiles()) {
if (!timerFile.getName().endsWith(".xml")) {
continue;
}
FileInputStream in = null;
try {
in = new FileInputStream(timerFile);
final XMLInputFactory inputFactory = INPUT_FACTORY;
setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(in);
try {
List<TimerImpl> timerList = new ArrayList<>();
mapper.parseDocument(timerList, streamReader);
for (TimerImpl timer : timerList) {
if (timer.getId().equals("deleted-timer")) {
timerFile.delete();
break;
}
timers.put(timer.getId(), timer);
}
} finally {
safeClose(in);
}
} catch (Exception e) {
EJB3_TIMER_LOGGER.failToRestoreTimersFromFile(timerFile, e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
EJB3_TIMER_LOGGER.failToCloseFile(e);
}
}
}
}
return timers;
}
use of org.jboss.staxmapper.XMLMapper in project wildfly by wildfly.
the class FileTimerPersistence method writeFile.
private void writeFile(TimerImpl timer) {
final File file = fileName(timer.getTimedObjectId(), timer.getId());
//if the timer is expired or cancelled delete the file
if (timer.getState() == TimerState.CANCELED || timer.getState() == TimerState.EXPIRED) {
if (file.exists()) {
file.delete();
}
return;
}
try {
FileOutputStream out = new FileOutputStream(file);
try {
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
XMLMapper mapper = createMapper(timer.getTimerService());
mapper.deparseDocument(new EjbTimerXmlPersister(factory, configuration), Collections.singletonList(timer), writer);
writer.flush();
writer.close();
} finally {
safeClose(out);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations