use of nl.nn.adapterframework.stream.MessageOutputStream in project iaf by ibissource.
the class MongoDbSender method sendMessage.
@Override
public PipeRunResult sendMessage(Message message, PipeLineSession session, IForwardTarget next) throws SenderException, TimeoutException {
message.closeOnCloseOf(session, this);
MongoAction mngaction = getAction();
try (MessageOutputStream target = mngaction == MongoAction.FINDONE || mngaction == MongoAction.FINDMANY ? MessageOutputStream.getTargetStream(this, session, next) : new MessageOutputStreamCap(this, next)) {
ParameterValueList pvl = ParameterValueList.get(getParameterList(), message, session);
MongoDatabase mongoDatabase = getDatabase(pvl);
MongoCollection<Document> mongoCollection = getCollection(mongoDatabase, pvl);
switch(mngaction) {
case INSERTONE:
renderResult(mongoCollection.insertOne(getDocument(message)), target);
break;
case INSERTMANY:
renderResult(mongoCollection.insertMany(getDocuments(message)), target);
break;
case FINDONE:
renderResult(mongoCollection.find(getFilter(pvl, message)).first(), target);
break;
case FINDMANY:
renderResult(mongoCollection.find(getFilter(pvl, message)).limit(getLimit(pvl)), target);
break;
case UPDATEONE:
renderResult(mongoCollection.updateOne(getFilter(pvl, null), getDocument(message)), target);
break;
case UPDATEMANY:
renderResult(mongoCollection.updateMany(getFilter(pvl, null), getDocument(message)), target);
break;
case DELETEONE:
renderResult(mongoCollection.deleteOne(getFilter(pvl, message)), target);
break;
case DELETEMANY:
renderResult(mongoCollection.deleteMany(getFilter(pvl, message)), target);
break;
default:
throw new SenderException("Unknown action [" + getAction() + "]");
}
return target.getPipeRunResult();
} catch (Exception e) {
throw new SenderException("Cannot execute action [" + getAction() + "]", e);
}
}
use of nl.nn.adapterframework.stream.MessageOutputStream 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.MessageOutputStream in project iaf by ibissource.
the class CompressPipe method doPipe.
@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
try {
Object result;
InputStream in = null;
boolean zipMultipleFiles = false;
String filename = null;
if (messageIsContent) {
in = message.asInputStream();
} else {
filename = message.asString();
if (compress) {
zipMultipleFiles = StringUtils.contains(filename, ";");
} else {
in = new FileInputStream(filename);
}
}
if (resultIsContent) {
try (MessageOutputStream target = getTargetStream(session)) {
try (OutputStream stream = convert2String ? new WriterOutputStream(target.asWriter(), StreamUtil.DEFAULT_CHARSET) : target.asStream()) {
processStream(stream, in, zipMultipleFiles, filename, session);
}
return target.getPipeRunResult();
}
}
String outFilename = null;
if (messageIsContent) {
outFilename = FileUtils.getFilename(getParameterList(), session, (File) null, filenamePattern);
} else {
outFilename = FileUtils.getFilename(getParameterList(), session, new File(filename), filenamePattern);
}
File outFile = new File(outputDirectory, outFilename);
result = outFile.getAbsolutePath();
try (OutputStream stream = new FileOutputStream(outFile)) {
processStream(stream, in, zipMultipleFiles, filename, session);
}
return new PipeRunResult(getSuccessForward(), result);
} catch (Exception e) {
PipeForward exceptionForward = findForward(PipeForward.EXCEPTION_FORWARD_NAME);
if (exceptionForward != null) {
log.warn(getLogPrefix(session) + "exception occured, forwarded to [" + exceptionForward.getPath() + "]", e);
return new PipeRunResult(exceptionForward, new ErrorMessageFormatter().format(getLogPrefix(session), e, this, message, session.getMessageId(), 0));
}
throw new PipeRunException(this, getLogPrefix(session) + "Unexpected exception during compression", e);
}
}
use of nl.nn.adapterframework.stream.MessageOutputStream in project iaf by ibissource.
the class JsonXsltSender method createHandler.
@Override
protected ContentHandler createHandler(Message input, ThreadConnector threadConnector, PipeLineSession session, MessageOutputStream target) throws StreamingException {
if (!isJsonResult()) {
return super.createHandler(input, threadConnector, session, target);
}
XmlJsonWriter xjw = new XmlJsonWriter(target.asWriter());
MessageOutputStream prev = new MessageOutputStream(this, xjw, target, threadLifeCycleEventListener, txManager, session, null);
ContentHandler handler = super.createHandler(input, threadConnector, session, prev);
if (getXmlDebugger() != null) {
handler = getXmlDebugger().inspectXml(session, "XML to be converted to JSON", handler);
}
return handler;
}
use of nl.nn.adapterframework.stream.MessageOutputStream 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);
}
}
Aggregations