use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.
the class XmlParserTest method testParseXmlNoExternalEntityInjection.
@Test
public void testParseXmlNoExternalEntityInjection() throws IOException, SAXException {
String input = getInputAsString("/XmlUtils/EntityResolution/in-file-entity.xml");
String expected = TestFileUtils.getTestFile("/XmlUtils/EntityResolution/out-not-resolved.xml");
XmlWriter writer = new XmlWriter();
XmlUtils.parseXml(input, writer);
MatchUtils.assertXmlEquals(expected, writer.toString());
}
use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.
the class IbisDebuggerAdvice method inspectXml.
@Override
public ContentHandler inspectXml(PipeLineSession session, String label, ContentHandler contentHandler) {
if (!isEnabled()) {
return contentHandler;
}
String correlationId = session == null ? null : session.getMessageId();
WriterPlaceHolder writerPlaceHolder = ibisDebugger.showValue(correlationId, label, new WriterPlaceHolder());
if (writerPlaceHolder != null && writerPlaceHolder.getWriter() != null) {
Writer writer = writerPlaceHolder.getWriter();
session.scheduleCloseOnSessionExit(writer, "debugger for inspectXml labeled [" + label + "]");
XmlWriter xmlWriter = new XmlWriter(StreamUtil.limitSize(writer, writerPlaceHolder.getSizeLimit()), true);
contentHandler = new XmlTee(contentHandler, new PrettyPrintFilter(xmlWriter));
}
return contentHandler;
}
use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.
the class PipeDescriptionProvider method getPipeDescription.
/**
* Get a PipeDescription object for the specified pipe. The returned object
* is cached.
*/
public PipeDescription getPipeDescription(PipeLine pipeLine, IPipe pipe) {
PipeDescription pipeDescription;
INamedObject pipeLineOwner = pipeLine.getOwner();
String adapterName = pipeLineOwner == null ? "?" : pipeLineOwner.getName();
String pipeName = pipe.getName();
String checkpointName = null;
String xpathExpression = null;
if (pipeLine.getPipe(pipeName) == null) {
if (PipeLine.INPUT_VALIDATOR_NAME.equals(pipeName)) {
checkpointName = INPUT_VALIDATOR_CHECKPOINT_NAME;
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/inputValidator";
} else if (PipeLine.OUTPUT_VALIDATOR_NAME.equals(pipeName)) {
checkpointName = OUTPUT_VALIDATOR_CHECKPOINT_NAME;
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/outputValidator";
} else if (PipeLine.INPUT_WRAPPER_NAME.equals(pipeName)) {
checkpointName = INPUT_WRAPPER_CHECKPOINT_NAME;
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/inputWrapper";
} else if (PipeLine.OUTPUT_WRAPPER_NAME.equals(pipeName)) {
checkpointName = OUTPUT_WRAPPER_CHECKPOINT_NAME;
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/outputWrapper";
} else if (pipeName.startsWith(MessageSendingPipe.INPUT_VALIDATOR_NAME_PREFIX) && pipeName.endsWith(MessageSendingPipe.INPUT_VALIDATOR_NAME_SUFFIX)) {
checkpointName = INPUT_VALIDATOR_CHECKPOINT_NAME;
String parentPipeName = getParentPipeName(pipeName, MessageSendingPipe.INPUT_VALIDATOR_NAME_PREFIX, MessageSendingPipe.INPUT_VALIDATOR_NAME_SUFFIX);
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/pipe[@name=\"" + parentPipeName + "\"]/inputValidator";
} else if (pipeName.startsWith(MessageSendingPipe.OUTPUT_VALIDATOR_NAME_PREFIX) && pipeName.endsWith(MessageSendingPipe.OUTPUT_VALIDATOR_NAME_SUFFIX)) {
checkpointName = OUTPUT_VALIDATOR_CHECKPOINT_NAME;
String parentPipeName = getParentPipeName(pipeName, MessageSendingPipe.OUTPUT_VALIDATOR_NAME_PREFIX, MessageSendingPipe.OUTPUT_VALIDATOR_NAME_SUFFIX);
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/pipe[@name=\"" + parentPipeName + "\"]/outputValidator";
} else if (pipeName.startsWith(MessageSendingPipe.INPUT_WRAPPER_NAME_PREFIX) && pipeName.endsWith(MessageSendingPipe.INPUT_WRAPPER_NAME_SUFFIX)) {
checkpointName = INPUT_WRAPPER_CHECKPOINT_NAME;
String parentPipeName = getParentPipeName(pipeName, MessageSendingPipe.INPUT_WRAPPER_NAME_PREFIX, MessageSendingPipe.INPUT_WRAPPER_NAME_SUFFIX);
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/pipe[@name=\"" + parentPipeName + "\"]/inputWrapper";
} else if (pipeName.startsWith(MessageSendingPipe.OUTPUT_WRAPPER_NAME_PREFIX) && pipeName.endsWith(MessageSendingPipe.OUTPUT_WRAPPER_NAME_SUFFIX)) {
checkpointName = OUTPUT_WRAPPER_CHECKPOINT_NAME;
String parentPipeName = getParentPipeName(pipeName, MessageSendingPipe.OUTPUT_WRAPPER_NAME_PREFIX, MessageSendingPipe.OUTPUT_WRAPPER_NAME_SUFFIX);
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/pipe[@name=\"" + parentPipeName + "\"]/outputWrapper";
}
} else {
xpathExpression = "//*/adapter[@name=\"" + adapterName + "\"]/pipeline/pipe[@name=\"" + pipeName + "\"]";
}
synchronized (pipeDescriptionCaches) {
// this is a WeakHashMap.
if (!(pipeLine.getApplicationContext() instanceof Configuration)) {
pipeDescription = new PipeDescription();
pipeDescription.setCheckpointName(getCheckpointName(pipe, checkpointName));
pipeDescription.setDescription("Unable to find pipe information, configuration not found.");
return pipeDescription;
}
Configuration configuration = (Configuration) pipeLine.getApplicationContext();
Map<String, PipeDescription> pipeDescriptionCache = pipeDescriptionCaches.get(configuration);
if (pipeDescriptionCache == null) {
pipeDescriptionCache = new HashMap<>();
pipeDescriptionCaches.put(configuration, pipeDescriptionCache);
}
pipeDescription = pipeDescriptionCache.get(xpathExpression);
if (pipeDescription == null) {
pipeDescription = new PipeDescription();
pipeDescription.setCheckpointName(getCheckpointName(pipe, checkpointName));
if (xpathExpression == null) {
pipeDescription.setDescription("Could not create xpath to extract pipe from configuration");
pipeDescriptionCache.put(xpathExpression, pipeDescription);
} else {
Document document = documents.get(configuration);
if (document == null) {
try {
String config = configuration.getLoadedConfiguration();
document = XmlUtils.buildDomDocument(config);
documents.put(configuration, document);
} catch (DomBuilderException e) {
pipeDescription = new PipeDescription();
pipeDescription.setCheckpointName(getCheckpointName(pipe, checkpointName));
pipeDescription.setDescription("Could not parse configuration: " + e.getMessage());
pipeDescriptionCache.put(xpathExpression, pipeDescription);
}
}
if (document != null) {
Node node = doXPath(document, xpathExpression);
if (node != null) {
XmlWriter xmlWriter = new XmlWriter();
ContentHandler handler = new PrettyPrintFilter(xmlWriter);
try {
String input = XmlUtils.nodeToString(node);
XmlUtils.parseXml(input, handler);
pipeDescription.setDescription(xmlWriter.toString());
} catch (IOException | TransformerException | SAXException e) {
pipeDescription.setDescription("Exception: " + e.getMessage());
}
addResourceNamesToPipeDescription(node, pipeDescription);
} else {
pipeDescription.setDescription("Pipe not found in configuration.");
}
}
}
pipeDescriptionCache.put(xpathExpression, pipeDescription);
}
}
return pipeDescription;
}
Aggregations