Search in sources :

Example 1 with SaxAbortException

use of nl.nn.adapterframework.stream.SaxAbortException in project iaf by ibissource.

the class ForEachChildElementPipe method createHandler.

protected void createHandler(HandlerRecord result, ThreadConnector threadConnector, PipeLineSession session, ItemCallback callback) throws TransformerConfigurationException {
    result.itemHandler = new ItemCallbackCallingHandler(callback);
    result.inputHandler = result.itemHandler;
    if (getXmlDebugger() != null && (StringUtils.isNotEmpty(getContainerElement()) || StringUtils.isNotEmpty(getTargetElement()) || getExtractElementsTp() != null)) {
        String containerElementString = StringUtils.isNotEmpty(getContainerElement()) ? "filter to containerElement '" + getContainerElement() + "'" : null;
        String targetElementString = StringUtils.isNotEmpty(getTargetElement()) ? "filter to targetElement '" + getTargetElement() + "'" : null;
        String xpathString = getExtractElementsTp() != null ? "filter XPath '" + getElementXPathExpression() + "'" : null;
        String label = "XML after preprocessing: " + Misc.concat(", ", containerElementString, targetElementString, xpathString);
        result.inputHandler = getXmlDebugger().inspectXml(session, label, result.inputHandler);
    }
    if (isRemoveNamespaces()) {
        result.inputHandler = new NamespaceRemovingFilter(result.inputHandler);
    }
    if (getExtractElementsTp() != null) {
        if (log.isDebugEnabled())
            log.debug("transforming input to obtain list of elements using xpath [" + getElementXPathExpression() + "]");
        TransformerFilter transformerFilter = getExtractElementsTp().getTransformerFilter(threadConnector, result.inputHandler);
        result.inputHandler = transformerFilter;
        result.transformerErrorListener = (TransformerErrorListener) transformerFilter.getErrorListener();
        result.errorMessage = "Could not process list of elements using xpath [" + getElementXPathExpression() + "]";
    }
    if (StringUtils.isNotEmpty(getTargetElement())) {
        result.inputHandler = new NodeSetFilter(XmlUtils.getNamespaceMap(getNamespaceDefs()), getTargetElement(), true, true, result.inputHandler);
    }
    if (StringUtils.isNotEmpty(getContainerElement())) {
        result.inputHandler = new NodeSetFilter(XmlUtils.getNamespaceMap(getNamespaceDefs()), getContainerElement(), false, true, result.inputHandler);
    }
    result.inputHandler = new StopSensor(result.itemHandler, result.inputHandler);
    result.inputHandler = new ExceptionCatchingFilter(result.inputHandler) {

        @Override
        protected void handleException(Exception e) throws SAXException {
            if (e instanceof SaxTimeoutException) {
                throw (SaxTimeoutException) e;
            }
            if (result.itemHandler.isStopRequested()) {
                if (e instanceof SaxAbortException) {
                    throw (SaxAbortException) e;
                }
                throw new SaxAbortException(e);
            }
            // For improved diagnosability of error situations, rethrow the original exception, where applicable.
            if (result.transformerErrorListener != null) {
                TransformerException tex = result.transformerErrorListener.getFatalTransformerException();
                if (tex != null) {
                    throw new SaxException(result.errorMessage, tex);
                }
                IOException iox = result.transformerErrorListener.getFatalIOException();
                if (iox != null) {
                    throw new SaxException(result.errorMessage, iox);
                }
            }
            throw new SaxException(result.errorMessage, e);
        }
    };
}
Also used : TransformerFilter(nl.nn.adapterframework.xml.TransformerFilter) SaxException(nl.nn.adapterframework.xml.SaxException) IOException(java.io.IOException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException) ExceptionCatchingFilter(nl.nn.adapterframework.xml.ExceptionCatchingFilter) TransformerException(javax.xml.transform.TransformerException) SaxException(nl.nn.adapterframework.xml.SaxException) SaxAbortException(nl.nn.adapterframework.stream.SaxAbortException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) StreamingException(nl.nn.adapterframework.stream.StreamingException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException) NamespaceRemovingFilter(nl.nn.adapterframework.xml.NamespaceRemovingFilter) SAXException(org.xml.sax.SAXException) NodeSetFilter(nl.nn.adapterframework.xml.NodeSetFilter) SaxAbortException(nl.nn.adapterframework.stream.SaxAbortException) TransformerException(javax.xml.transform.TransformerException)

Example 2 with SaxAbortException

use of nl.nn.adapterframework.stream.SaxAbortException in project iaf by ibissource.

the class ForEachChildElementPipe method iterateOverInput.

@Override
protected StopReason iterateOverInput(Message input, PipeLineSession session, Map<String, Object> threadContext, ItemCallback callback) throws SenderException, TimeoutException {
    InputSource src;
    if (isProcessFile()) {
        try {
            String filename;
            try {
                filename = input.asString();
            } catch (IOException e) {
                throw new SenderException(getLogPrefix(session) + "cannot find filename", e);
            }
            src = new InputSource(new FileInputStream(filename));
        } catch (FileNotFoundException e) {
            throw new SenderException("could not find file [" + input + "]", e);
        }
    } else {
        try {
            src = input.asInputSource();
        } catch (IOException e) {
            throw new SenderException("could not get InputSource", e);
        }
    }
    HandlerRecord handlerRecord = new HandlerRecord();
    try (ThreadConnector threadConnector = streamingXslt ? new ThreadConnector(this, threadLifeCycleEventListener, txManager, session) : null) {
        try {
            createHandler(handlerRecord, threadConnector, session, callback);
        } catch (TransformerException e) {
            throw new SenderException(handlerRecord.errorMessage, e);
        }
        try {
            XmlUtils.parseXml(src, handlerRecord.inputHandler);
        } catch (Exception e) {
            try {
                if (e instanceof SaxTimeoutException) {
                    if (e.getCause() != null && e.getCause() instanceof TimeoutException) {
                        throw (TimeoutException) e.getCause();
                    }
                    throw new TimeoutException(e);
                }
                if (!(e instanceof SaxAbortException)) {
                    throw new SenderException(e);
                }
            } finally {
                try {
                    handlerRecord.inputHandler.endDocument();
                } catch (Exception e2) {
                    log.warn("Exception in endDocument()", e2);
                }
            }
        }
    } catch (IOException e) {
        throw new SenderException(e);
    }
    return handlerRecord.itemHandler.stopReason;
// 2020-06-12 removing below 'rethrowTransformerException()', as it does not break the tests, and cannot be implemented when providing an OutputStream.
// However, if cases popup of errors not being signaled, this modification could be the cause.
// rethrowTransformerException(handlerRecord.transformerErrorListener, handlerRecord.errorMessage);
}
Also used : InputSource(org.xml.sax.InputSource) FileNotFoundException(java.io.FileNotFoundException) ThreadConnector(nl.nn.adapterframework.stream.ThreadConnector) IOException(java.io.IOException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException) FileInputStream(java.io.FileInputStream) TransformerException(javax.xml.transform.TransformerException) SaxException(nl.nn.adapterframework.xml.SaxException) SaxAbortException(nl.nn.adapterframework.stream.SaxAbortException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) StreamingException(nl.nn.adapterframework.stream.StreamingException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) SenderException(nl.nn.adapterframework.core.SenderException) SaxAbortException(nl.nn.adapterframework.stream.SaxAbortException) SenderException(nl.nn.adapterframework.core.SenderException) TransformerException(javax.xml.transform.TransformerException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) SaxTimeoutException(nl.nn.adapterframework.stream.SaxTimeoutException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 PipeStartException (nl.nn.adapterframework.core.PipeStartException)2 SenderException (nl.nn.adapterframework.core.SenderException)2 TimeoutException (nl.nn.adapterframework.core.TimeoutException)2 SaxAbortException (nl.nn.adapterframework.stream.SaxAbortException)2 SaxTimeoutException (nl.nn.adapterframework.stream.SaxTimeoutException)2 StreamingException (nl.nn.adapterframework.stream.StreamingException)2 SaxException (nl.nn.adapterframework.xml.SaxException)2 SAXException (org.xml.sax.SAXException)2 FileInputStream (java.io.FileInputStream)1 ThreadConnector (nl.nn.adapterframework.stream.ThreadConnector)1 ExceptionCatchingFilter (nl.nn.adapterframework.xml.ExceptionCatchingFilter)1 NamespaceRemovingFilter (nl.nn.adapterframework.xml.NamespaceRemovingFilter)1 NodeSetFilter (nl.nn.adapterframework.xml.NodeSetFilter)1 TransformerFilter (nl.nn.adapterframework.xml.TransformerFilter)1 InputSource (org.xml.sax.InputSource)1