use of nl.nn.adapterframework.stream.ThreadConnector in project iaf by ibissource.
the class XsltSender method sendMessage.
/*
* alternative implementation of send message, that should do the same as the original, but reuses the streaming content handler
*/
@Override
public PipeRunResult sendMessage(Message message, PipeLineSession session, IForwardTarget next) throws SenderException {
if (message == null) {
throw new SenderException(getLogPrefix() + "got null input");
}
try {
try (ThreadConnector threadConnector = streamingXslt ? new ThreadConnector(this, threadLifeCycleEventListener, txManager, session) : null) {
try (MessageOutputStream target = MessageOutputStream.getTargetStream(this, session, next)) {
ContentHandler handler = createHandler(message, threadConnector, session, target);
if (isDebugInput() && log.isDebugEnabled()) {
handler = new XmlTap(handler) {
@Override
public void endDocument() throws SAXException {
super.endDocument();
log.debug(getLogPrefix() + " xml input [" + getWriter() + "]");
}
};
}
XMLReader reader = getXmlReader(session, handler);
InputSource source = message.asInputSource();
reader.parse(source);
return target.getPipeRunResult();
}
}
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "Exception on transforming input", e);
}
}
use of nl.nn.adapterframework.stream.ThreadConnector in project iaf by ibissource.
the class XsltExceptionTest method testXsltException.
public void testXsltException(boolean expectChildThreads, int tailCount) throws Exception {
String xpathExpression = "*/*";
int xsltVersion = 1;
TransformerPool tp = TransformerPool.configureTransformer0(null, null, null, xpathExpression, null, OutputType.XML, false, null, xsltVersion);
XmlWriter writer = new XmlWriter();
FullXmlFilter filter = new FullXmlFilter(writer) {
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
if (localName.equals("error")) {
throw new SaxException("Found error");
}
super.startElement(uri, localName, qName, atts);
}
};
try (ThreadConnector threadConnector = expectChildThreads ? new ThreadConnector(null, null, null, (PipeLineSession) null) : null) {
TransformerFilter transformer = tp.getTransformerFilter(threadConnector, filter);
try {
try (SaxDocumentBuilder seb = new SaxDocumentBuilder("root", transformer)) {
seb.addElement("elem");
seb.addElement("error");
for (int i = 0; i < tailCount; i++) {
seb.addElement("elem");
}
}
fail("Expected exception to be caught while processing");
} catch (Exception e) {
System.out.println("Expected exception: " + e.getMessage());
}
System.out.println(writer);
}
}
use of nl.nn.adapterframework.stream.ThreadConnector in project iaf by ibissource.
the class XsltSender method provideOutputStream.
@Override
public MessageOutputStream provideOutputStream(PipeLineSession session, IForwardTarget next) throws StreamingException {
if (!canProvideOutputStream()) {
log.debug("sender [{}] cannot provide outputstream", () -> getName());
return null;
}
ThreadConnector threadConnector = streamingXslt ? new ThreadConnector(this, threadLifeCycleEventListener, txManager, session) : null;
MessageOutputStream target = MessageOutputStream.getTargetStream(this, session, next);
ContentHandler handler = createHandler(null, threadConnector, session, target);
return new MessageOutputStream(this, handler, target, threadLifeCycleEventListener, txManager, session, threadConnector);
}
use of nl.nn.adapterframework.stream.ThreadConnector 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);
}
use of nl.nn.adapterframework.stream.ThreadConnector in project iaf by ibissource.
the class ForEachChildElementPipe method provideOutputStream.
@Override
protected MessageOutputStream provideOutputStream(PipeLineSession session) throws StreamingException {
HandlerRecord handlerRecord = new HandlerRecord();
try {
ThreadConnector threadConnector = streamingXslt ? new ThreadConnector(this, threadLifeCycleEventListener, txManager, session) : null;
MessageOutputStream target = getTargetStream(session);
Writer resultWriter = target.asWriter();
ItemCallback callback = createItemCallBack(session, getSender(), resultWriter);
createHandler(handlerRecord, threadConnector, session, callback);
return new MessageOutputStream(this, handlerRecord.inputHandler, target, threadLifeCycleEventListener, txManager, session, threadConnector);
} catch (TransformerException e) {
throw new StreamingException(handlerRecord.errorMessage, e);
}
}
Aggregations