use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class SapSender method sendMessage.
@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
String tid = null;
try {
ParameterValueList pvl = null;
if (paramList != null) {
pvl = paramList.getValues(message, session);
}
SapSystem sapSystem = getSystem(pvl);
JCoFunction function = getFunction(sapSystem, pvl);
if (StringUtils.isEmpty(getSapSystemName())) {
pvl.remove(getSapSystemNameParam());
}
if (StringUtils.isEmpty(getFunctionName())) {
pvl.remove(getFunctionNameParam());
}
String correlationID = session == null ? null : session.getMessageId();
message2FunctionCall(function, message.asString(), correlationID, pvl);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + " function call [" + functionCall2message(function) + "]");
JCoDestination destination = getDestination(session, sapSystem);
tid = getTid(destination, sapSystem);
if (StringUtils.isEmpty(tid)) {
function.execute(destination);
} else {
function.execute(destination, tid);
}
if (isSynchronous()) {
return functionResult2message(function);
}
return new Message(tid);
} catch (Exception e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class IdocSender method sendMessage.
@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
String tid = null;
try {
ParameterValueList pvl = null;
if (paramList != null) {
pvl = paramList.getValues(message, session);
}
SapSystem sapSystem = getSystem(pvl);
IDocDocument idoc = parseIdoc(sapSystem, message);
try {
log.trace(getLogPrefix() + "checking syntax");
idoc.checkSyntax();
} catch (IDocException e) {
throw new SenderException("Syntax error in idoc", e);
}
if (log.isDebugEnabled()) {
log.debug(getLogPrefix() + "parsed idoc [" + JCoIDoc.getIDocFactory().getIDocXMLProcessor().render(idoc) + "]");
}
JCoDestination destination = getDestination(session, sapSystem);
tid = getTid(destination, sapSystem);
if (tid == null) {
throw new SenderException("could not obtain TID to send Idoc");
}
JCoIDoc.send(idoc, IDocFactory.IDOC_VERSION_DEFAULT, destination, tid);
return new Message(tid);
} catch (Exception e) {
throw new SenderException(e);
}
}
use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.
the class FileSystemSenderWithAttachments method sendMessage.
@Override
public PipeRunResult sendMessage(Message message, PipeLineSession session, IForwardTarget next) throws SenderException, TimeoutException {
if (getAction() != FileSystemAction.LISTATTACHMENTS) {
return super.sendMessage(message, session, next);
} else {
IBasicFileSystem<F> ifs = getFileSystem();
F file;
try {
file = ifs.toFile(message.asString());
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "unable to get file", e);
}
XmlBuilder attachments = new XmlBuilder("attachments");
IWithAttachments<F, A> withAttachments = getFileSystem();
try {
Iterator<A> it = withAttachments.listAttachments(file);
if (it != null) {
while (it.hasNext()) {
A attachment = it.next();
XmlBuilder attachmentXml = new XmlBuilder("attachment");
attachmentXml.addAttribute("name", withAttachments.getAttachmentName(attachment));
attachmentXml.addAttribute("contentType", withAttachments.getAttachmentContentType(attachment));
attachmentXml.addAttribute("size", withAttachments.getAttachmentSize(attachment));
attachmentXml.addAttribute("filename", withAttachments.getAttachmentFileName(attachment));
FileAttachment fileAttachment = (FileAttachment) attachment;
fileAttachment.load();
if (!attachmentsAsSessionKeys) {
InputStream binaryInputStream = new ByteArrayInputStream(fileAttachment.getContent());
InputStream base64 = new Base64InputStream(binaryInputStream, true);
attachmentXml.setCdataValue(Misc.streamToString(base64, StreamUtil.DEFAULT_INPUT_STREAM_ENCODING));
} else {
attachmentXml.setValue(fileAttachment.getName());
session.put(fileAttachment.getName(), fileAttachment.getContent());
}
attachments.addSubElement(attachmentXml);
}
}
} catch (Exception e) {
log.error("unable to list all attachments", e);
throw new SenderException(e);
}
return new PipeRunResult(null, attachments.toString());
}
}
use of nl.nn.adapterframework.core.TimeOutException 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.core.TimeOutException in project iaf by ibissource.
the class ResultSet2FileSender method executeStatementSet.
@Override
protected PipeRunResult executeStatementSet(QueryExecutionContext queryExecutionContext, Message message, PipeLineSession session, IForwardTarget next) throws SenderException, TimeoutException {
int counter = 0;
String fileName = null;
try {
fileName = session.getMessage(getFilenameSessionKey()).asString();
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "unable to get filename from session key [" + getFilenameSessionKey() + "]", e);
}
int maxRecords = -1;
if (StringUtils.isNotEmpty(getMaxRecordsSessionKey())) {
try {
maxRecords = Integer.parseInt(session.getMessage(getMaxRecordsSessionKey()).asString());
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "unable to parse " + getMaxRecordsSessionKey() + " to integer", e);
}
}
try (FileOutputStream fos = new FileOutputStream(fileName, isAppend())) {
PreparedStatement statement = queryExecutionContext.getStatement();
JdbcUtil.applyParameters(getDbmsSupport(), statement, queryExecutionContext.getParameterList(), message, session);
try (ResultSet resultset = statement.executeQuery()) {
boolean eor = false;
if (maxRecords == 0) {
eor = true;
}
while (resultset.next() && !eor) {
counter++;
processResultSet(resultset, fos, counter);
if (maxRecords >= 0 && counter >= maxRecords) {
ResultSetMetaData rsmd = resultset.getMetaData();
if (rsmd.getColumnCount() >= 3) {
String group = resultset.getString(3);
while (resultset.next() && !eor) {
String groupNext = resultset.getString(3);
if (groupNext.equals(group)) {
counter++;
processResultSet(resultset, fos, counter);
} else {
eor = true;
}
}
} else {
eor = true;
}
}
}
}
} catch (FileNotFoundException e) {
throw new SenderException(getLogPrefix() + "could not find file [" + fileName + "]", e);
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "got Exception resolving parameter", e);
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "got IOException", e);
} catch (SQLException sqle) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", sqle);
} catch (JdbcException e) {
throw new SenderException(getLogPrefix() + "got exception executing a SQL command", e);
}
return new PipeRunResult(null, new Message("<result><rowsprocessed>" + counter + "</rowsprocessed></result>"));
}
Aggregations