use of nl.nn.adapterframework.stream.StreamingException in project iaf by ibissource.
the class ChecksumPipe method provideOutputStream.
@Override
protected MessageOutputStream provideOutputStream(PipeLineSession session) throws StreamingException {
ChecksumGenerator cg;
try {
cg = createChecksumGenerator();
} catch (NoSuchAlgorithmException e) {
throw new StreamingException("Cannot create ChecksumGenerator", e);
}
OutputStream targetStream = new OutputStream() {
@Override
public void write(int b) throws IOException {
cg.update(b);
}
@Override
public void write(byte[] buf, int offset, int length) throws IOException {
cg.update(buf, offset, length);
}
};
return new MessageOutputStream(this, targetStream, getNextPipe(), getCharset()) {
@Override
public Message getResponse() {
return new Message(cg.getResult());
}
};
}
use of nl.nn.adapterframework.stream.StreamingException in project iaf by ibissource.
the class XsltSender method createHandler.
protected ContentHandler createHandler(Message input, ThreadConnector threadConnector, PipeLineSession session, MessageOutputStream target) throws StreamingException {
ContentHandler handler = null;
try {
ParameterValueList pvl = null;
if (paramList != null) {
pvl = paramList.getValues(input, session);
}
TransformerPool poolToUse = transformerPool;
if (StringUtils.isNotEmpty(styleSheetNameSessionKey)) {
Message styleSheetNameToUse = session.getMessage(styleSheetNameSessionKey);
if (!Message.isEmpty(styleSheetNameToUse)) {
String styleSheetNameFromSessionKey = styleSheetNameToUse.asString();
if (!dynamicTransformerPoolMap.containsKey(styleSheetNameFromSessionKey)) {
dynamicTransformerPoolMap.put(styleSheetNameFromSessionKey, poolToUse = TransformerPool.configureTransformer(getLogPrefix(), this, null, null, styleSheetNameFromSessionKey, null, true, getParameterList()));
poolToUse.open();
} else {
poolToUse = dynamicTransformerPoolMap.get(styleSheetNameFromSessionKey);
}
}
if (poolToUse == null) {
throw new SenderException("no XSLT stylesheet found from styleSheetNameSessionKey [" + styleSheetNameSessionKey + "], and neither one statically configured");
}
}
OutputType outputType = getOutputType();
if (log.isTraceEnabled())
log.trace("Configured outputmethod [" + outputType + "]");
if (outputType == null) {
String parsedOutputType = poolToUse.getOutputMethod();
if (StringUtils.isNotEmpty(parsedOutputType)) {
outputType = EnumUtils.parse(OutputType.class, parsedOutputType);
}
if (log.isTraceEnabled())
log.trace("Detected outputmethod [" + parsedOutputType + "]");
}
if (outputType == null) {
outputType = DEFAULT_OUTPUT_METHOD;
if (log.isTraceEnabled())
log.trace("Default outputmethod [" + outputType + "]");
}
Object targetStream = target.asNative();
Boolean indentXml = getIndentXml();
if (log.isTraceEnabled())
log.trace("Configured indentXml [" + indentXml + "]");
if (indentXml == null) {
indentXml = poolToUse.getIndent();
if (log.isTraceEnabled())
log.trace("Detected indentXml [" + indentXml + "]");
}
if (indentXml == null) {
indentXml = DEFAULT_INDENT;
if (log.isTraceEnabled())
log.trace("Default indentXml [" + indentXml + "]");
}
Boolean omitXmlDeclaration = getOmitXmlDeclaration();
if (targetStream instanceof ContentHandler) {
handler = (ContentHandler) targetStream;
} else {
XmlWriter xmlWriter = new XmlWriter(target.asWriter());
if (log.isTraceEnabled())
log.trace("Configured omitXmlDeclaration [" + omitXmlDeclaration + "]");
if (outputType == OutputType.XML) {
if (omitXmlDeclaration == null) {
omitXmlDeclaration = poolToUse.getOmitXmlDeclaration();
if (log.isTraceEnabled())
log.trace("Detected omitXmlDeclaration [" + omitXmlDeclaration + "]");
if (omitXmlDeclaration == null) {
omitXmlDeclaration = DEFAULT_OMIT_XML_DECLARATION;
if (log.isTraceEnabled())
log.trace("Default omitXmlDeclaration [" + omitXmlDeclaration + "]");
}
}
xmlWriter.setIncludeXmlDeclaration(!omitXmlDeclaration);
if (indentXml) {
xmlWriter.setNewlineAfterXmlDeclaration(true);
}
} else {
xmlWriter.setTextMode(true);
}
handler = xmlWriter;
}
if (indentXml) {
handler = new PrettyPrintFilter(handler);
}
if (isSkipEmptyTags()) {
handler = new SkipEmptyTagsFilter(handler);
}
TransformerFilter mainFilter = poolToUse.getTransformerFilter(threadConnector, handler);
if (pvl != null) {
XmlUtils.setTransformerParameters(mainFilter.getTransformer(), pvl.getValueMap());
}
handler = filterInput(mainFilter, session);
return handler;
} catch (Exception e) {
// log.warn(getLogPrefix()+"intermediate exception logging",e);
throw new StreamingException(getLogPrefix() + "Exception on creating transformerHandler chain", e);
}
}
use of nl.nn.adapterframework.stream.StreamingException in project iaf by ibissource.
the class FileSystemActor method provideOutputStream.
@SuppressWarnings("resource")
@Override
public MessageOutputStream provideOutputStream(PipeLineSession session, IForwardTarget next) throws StreamingException {
if (!canProvideOutputStream()) {
return null;
}
ParameterValueList pvl = null;
try {
if (parameterList != null) {
pvl = parameterList.getValues(null, session);
}
} catch (ParameterException e) {
throw new StreamingException("caught exception evaluating parameters", e);
}
try {
F file = getFile(null, pvl);
OutputStream out;
if (getAction() == FileSystemAction.APPEND) {
out = ((IWritableFileSystem<F>) fileSystem).appendFile(file);
} else {
out = ((IWritableFileSystem<F>) fileSystem).createFile(file);
}
MessageOutputStream stream = new MessageOutputStream(owner, out, next);
stream.setResponse(new Message(FileSystemUtils.getFileInfo(fileSystem, file).toXML()));
return stream;
} catch (FileSystemException | IOException e) {
throw new StreamingException("cannot obtain OutputStream", e);
}
}
use of nl.nn.adapterframework.stream.StreamingException in project iaf by ibissource.
the class JdbcQuerySenderBase method provideOutputStream.
@Override
public MessageOutputStream provideOutputStream(PipeLineSession session, IForwardTarget next) throws StreamingException {
if (!canProvideOutputStream()) {
return null;
}
return TransactionConnectorCoordinator.doInUnsuspendedTransationContext(() -> {
final Connection connection;
QueryExecutionContext queryExecutionContext;
try {
connection = getConnectionWithTimeout(getTimeout());
queryExecutionContext = getQueryExecutionContext(connection, null, session);
} catch (JdbcException | ParameterException | SQLException | SenderException | TimeoutException e) {
throw new StreamingException(getLogPrefix() + "cannot getQueryExecutionContext", e);
}
try {
PreparedStatement statement = queryExecutionContext.getStatement();
if (queryExecutionContext.getParameterList() != null) {
JdbcUtil.applyParameters(getDbmsSupport(), statement, queryExecutionContext.getParameterList().getValues(new Message(""), session));
}
if (queryExecutionContext.getQueryType() == QueryType.UPDATEBLOB) {
BlobOutputStream blobOutputStream = getBlobOutputStream(statement, blobColumn, isBlobsCompressed());
TransactionConnectorCoordinator.onEndChildThread(() -> {
blobOutputStream.close();
connection.close();
log.warn(getLogPrefix() + "warnings: " + blobOutputStream.getWarnings().toXML());
});
return new MessageOutputStream(this, blobOutputStream, next) {
// perform close() on MessageOutputStream.close(), necessary when no TransactionConnector available for onEndThread()
@Override
public void afterClose() throws SQLException {
if (!connection.isClosed()) {
connection.close();
}
log.warn(getLogPrefix() + "warnings: " + blobOutputStream.getWarnings().toXML());
}
};
}
if (queryExecutionContext.getQueryType() == QueryType.UPDATECLOB) {
ClobWriter clobWriter = getClobWriter(statement, getClobColumn());
TransactionConnectorCoordinator.onEndChildThread(() -> {
clobWriter.close();
connection.close();
log.warn(getLogPrefix() + "warnings: " + clobWriter.getWarnings().toXML());
});
return new MessageOutputStream(this, clobWriter, next) {
// perform close() on MessageOutputStream.close(), necessary when no TransactionConnector available for onEndThread()
@Override
public void afterClose() throws SQLException {
if (!connection.isClosed()) {
connection.close();
}
log.warn(getLogPrefix() + "warnings: " + clobWriter.getWarnings().toXML());
}
};
}
throw new IllegalArgumentException(getLogPrefix() + "illegal queryType [" + queryExecutionContext.getQueryType() + "], must be 'updateBlob' or 'updateClob'");
} catch (JdbcException | SQLException | IOException | ParameterException e) {
throw new StreamingException(getLogPrefix() + "cannot update CLOB or BLOB", e);
}
});
}
use of nl.nn.adapterframework.stream.StreamingException in project iaf by ibissource.
the class MongoDbSender method renderResult.
protected void renderResult(FindIterable<Document> findResults, MessageOutputStream target) throws StreamingException {
try {
if (isCountOnly()) {
try (Writer writer = target.asWriter()) {
int count = 0;
for (Document doc : findResults) {
count++;
}
writer.write(Integer.toString(count));
}
return;
}
try (ArrayBuilder builder = DocumentBuilderFactory.startArrayDocument(getOutputFormat(), "FindManyResult", "item", target)) {
JsonWriterSettings writerSettings = JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build();
Encoder<Document> encoder = new DocumentCodec();
for (Document doc : findResults) {
try (INodeBuilder element = builder.addElement()) {
JsonDocumentWriter jsonWriter = new JsonDocumentWriter(element, writerSettings);
encoder.encode(jsonWriter, doc, EncoderContext.builder().build());
}
}
}
} catch (Exception e) {
throw new StreamingException("Could not render collection", e);
}
}
Aggregations