use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class ProcessUtil method executeCommand.
/**
* Execute a command as a process in the operating system.
*
* @param timeout timeout in seconds, or 0 to wait indefinetely until the process ends
* @param command
* @throws TimeOutException
* @throws SenderException
*/
public static String executeCommand(List command, int timeout) throws TimeOutException, SenderException {
String output;
String errors;
Process process;
try {
process = Runtime.getRuntime().exec((String[]) command.toArray(new String[0]));
} catch (Throwable t) {
throw new SenderException("Could not execute command [" + getCommandLine(command) + "]", t);
}
TimeoutGuard tg = new TimeoutGuard("ProcessUtil ");
tg.activateGuard(timeout);
try {
// Wait until the process is completely finished, or timeout is expired
process.waitFor();
} catch (InterruptedException e) {
if (tg.threadKilled()) {
throw new TimeOutException("command [" + getCommandLine(command) + "] timed out", e);
} else {
throw new SenderException("command [" + getCommandLine(command) + "] interrupted while waiting for process", e);
}
} finally {
tg.cancel();
}
// Read the output of the process
try {
output = readStream(process.getInputStream());
} catch (IOException e) {
throw new SenderException("Could not read output of command [" + getCommandLine(command) + "]", e);
}
// Read the errors of the process
try {
errors = readStream(process.getErrorStream());
} catch (IOException e) {
throw new SenderException("Could not read errors of command [" + getCommandLine(command) + "]", e);
}
// Throw an exception if the command returns an error exit value
int exitValue = process.exitValue();
if (exitValue != 0) {
throw new SenderException("Nonzero exit value [" + exitValue + "] for command [" + getCommandLine(command) + "], process output was [" + output + "], error output was [" + errors + "]");
}
if (StringUtils.isNotEmpty(errors)) {
log.warn("command [" + getCommandLine(command) + "] had error output [" + errors + "]");
}
return output;
}
use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class ReloadSender method sendMessage.
@Override
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws TimeOutException, SenderException {
String configName = null;
String activeVersion = null;
ParameterValueList pvl = null;
try {
if (prc != null && paramList != null) {
pvl = prc.getValues(paramList);
if (pvl.getParameterValue("name") != null)
configName = (String) pvl.getParameterValue("name").getValue();
if (pvl.getParameterValue("forceReload") != null)
setForceReload((Boolean) pvl.getParameterValue("forceReload").getValue());
}
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
}
try {
if (configName == null)
configName = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='NAME']");
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "error evaluating Xpath expression configName", e);
}
try {
if (!getForceReload())
activeVersion = XmlUtils.evaluateXPathNodeSetFirstElement(message, "row/field[@name='VERSION']");
} catch (Exception e) {
throw new SenderException(getLogPrefix() + "error evaluating Xpath expression activeVersion", e);
}
Configuration configuration = getPipe().getAdapter().getConfiguration().getIbisManager().getConfiguration(configName);
if (configuration != null) {
String latestVersion = configuration.getVersion();
if (getForceReload() || (latestVersion != null && !activeVersion.equals(latestVersion))) {
IbisContext ibisContext = configuration.getIbisManager().getIbisContext();
ibisContext.reload(configName);
return "Reload " + configName + " succeeded";
} else {
return "Reload " + configName + " skipped";
}
} else {
log.warn("Configuration [" + configName + "] not loaded yet");
return "Reload " + configName + " skipped";
}
}
use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class TestTool method executeFixedQuerySenderRead.
private static int executeFixedQuerySenderRead(String step, String stepDisplayName, Properties properties, Map queues, Map writers, String queueName, String fileName, String fileContent) {
int result = RESULT_ERROR;
Map querySendersInfo = (Map) queues.get(queueName);
Integer waitBeforeRead = (Integer) querySendersInfo.get("readQueryWaitBeforeRead");
if (waitBeforeRead != null) {
try {
Thread.sleep(waitBeforeRead.intValue());
} catch (InterruptedException e) {
}
}
boolean newRecordFound = true;
FixedQuerySender prePostFixedQuerySender = (FixedQuerySender) querySendersInfo.get("prePostQueryFixedQuerySender");
if (prePostFixedQuerySender != null) {
try {
String preResult = (String) querySendersInfo.get("prePostQueryResult");
debugPipelineMessage(stepDisplayName, "Pre result '" + queueName + "':", preResult, writers);
String postResult = prePostFixedQuerySender.sendMessage(TESTTOOL_CORRELATIONID, TESTTOOL_DUMMY_MESSAGE);
debugPipelineMessage(stepDisplayName, "Post result '" + queueName + "':", postResult, writers);
if (preResult.equals(postResult)) {
newRecordFound = false;
}
/* Fill the preResult with postResult, so closeQueues is able to determine if there
* are remaining messages left.
*/
querySendersInfo.put("prePostQueryResult", postResult);
} catch (TimeOutException e) {
errorMessage("Time out on execute query for '" + queueName + "': " + e.getMessage(), e, writers);
} catch (SenderException e) {
errorMessage("Could not execute query for '" + queueName + "': " + e.getMessage(), e, writers);
}
}
String message = null;
if (newRecordFound) {
FixedQuerySender readQueryFixedQuerySender = (FixedQuerySender) querySendersInfo.get("readQueryQueryFixedQuerySender");
try {
message = readQueryFixedQuerySender.sendMessage(TESTTOOL_CORRELATIONID, TESTTOOL_DUMMY_MESSAGE);
} catch (TimeOutException e) {
errorMessage("Time out on execute query for '" + queueName + "': " + e.getMessage(), e, writers);
} catch (SenderException e) {
errorMessage("Could not execute query for '" + queueName + "': " + e.getMessage(), e, writers);
}
}
if (message == null) {
if ("".equals(fileName)) {
result = RESULT_OK;
} else {
errorMessage("Could not read jdbc message (null returned) or no new message found (pre result equals post result)", writers);
}
} else {
if ("".equals(fileName)) {
debugPipelineMessage(stepDisplayName, "Unexpected message read from '" + queueName + "':", message, writers);
} else {
result = compareResult(step, stepDisplayName, fileName, fileContent, message, properties, writers, queueName);
}
}
return result;
}
use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class TestTool method executeJmsSenderWrite.
private static int executeJmsSenderWrite(String stepDisplayName, Map queues, Map writers, String queueName, String fileContent) {
int result = RESULT_ERROR;
Map jmsSenderInfo = (Map) queues.get(queueName);
JmsSender jmsSender = (JmsSender) jmsSenderInfo.get("jmsSender");
try {
String correlationId = null;
String useCorrelationIdFrom = (String) jmsSenderInfo.get("useCorrelationIdFrom");
if (useCorrelationIdFrom != null) {
Map listenerInfo = (Map) queues.get(useCorrelationIdFrom);
if (listenerInfo == null) {
errorMessage("Could not find listener '" + useCorrelationIdFrom + "' to use correlation id from", writers);
} else {
correlationId = (String) listenerInfo.get("correlationId");
if (correlationId == null) {
errorMessage("Could not find correlation id from listener '" + useCorrelationIdFrom + "'", writers);
}
}
}
if (correlationId == null) {
correlationId = (String) jmsSenderInfo.get("jmsCorrelationId");
}
if (correlationId == null) {
correlationId = TESTTOOL_CORRELATIONID;
}
jmsSender.sendMessage(correlationId, fileContent);
debugPipelineMessage(stepDisplayName, "Successfully written to '" + queueName + "':", fileContent, writers);
result = RESULT_OK;
} catch (TimeOutException e) {
errorMessage("Time out sending jms message to '" + queueName + "': " + e.getMessage(), e, writers);
} catch (SenderException e) {
errorMessage("Could not send jms message to '" + queueName + "': " + e.getMessage(), e, writers);
}
return result;
}
use of nl.nn.adapterframework.core.TimeoutException in project iaf by ibissource.
the class SapSender method sendMessage.
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
String tid = null;
try {
ParameterValueList pvl = null;
if (prc != null) {
pvl = prc.getValues(paramList);
}
SapSystem sapSystem = getSystem(pvl);
JCO.Function function = getFunction(sapSystem, pvl);
if (StringUtils.isEmpty(getSapSystemName())) {
pvl.removeParameterValue(getSapSystemNameParam());
}
if (StringUtils.isEmpty(getFunctionName())) {
pvl.removeParameterValue(getFunctionNameParam());
}
message2FunctionCall(function, message, correlationID, pvl);
if (log.isDebugEnabled())
log.debug(getLogPrefix() + " function call [" + functionCall2message(function) + "]");
JCO.Client client = getClient(prc.getSession(), sapSystem);
try {
tid = getTid(client, sapSystem);
if (StringUtils.isEmpty(tid)) {
client.execute(function);
} else {
client.execute(function, tid);
}
} finally {
releaseClient(client, sapSystem);
}
if (isSynchronous()) {
return functionResult2message(function);
} else {
return tid;
}
} catch (Exception e) {
throw new SenderException(e);
}
}
Aggregations