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