Search in sources :

Example 11 with PrettyPrintFilter

use of nl.nn.adapterframework.xml.PrettyPrintFilter 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;
}
Also used : XmlTee(nl.nn.adapterframework.stream.xml.XmlTee) Writer(java.io.Writer) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter)

Example 12 with PrettyPrintFilter

use of nl.nn.adapterframework.xml.PrettyPrintFilter 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;
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) ContentHandler(org.xml.sax.ContentHandler) SAXException(org.xml.sax.SAXException) INamedObject(nl.nn.adapterframework.core.INamedObject) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) TransformerException(javax.xml.transform.TransformerException) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter)

Aggregations

PrettyPrintFilter (nl.nn.adapterframework.xml.PrettyPrintFilter)12 XmlWriter (nl.nn.adapterframework.xml.XmlWriter)11 ContentHandler (org.xml.sax.ContentHandler)8 SAXException (org.xml.sax.SAXException)6 IOException (java.io.IOException)5 XmlTee (nl.nn.adapterframework.stream.xml.XmlTee)4 Writer (java.io.Writer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 StringWriter (java.io.StringWriter)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 SenderException (nl.nn.adapterframework.core.SenderException)2 Message (nl.nn.adapterframework.stream.Message)2 StreamingException (nl.nn.adapterframework.stream.StreamingException)2 JsonTee (nl.nn.adapterframework.stream.json.JsonTee)2 JsonWriter (nl.nn.adapterframework.stream.json.JsonWriter)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1