use of nl.nn.adapterframework.xml.ExceptionCatchingFilter 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);
}
};
}
Aggregations