Search in sources :

Example 11 with TimeOutException

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;
}
Also used : TimeOutException(nl.nn.adapterframework.core.TimeOutException) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutGuard(nl.nn.adapterframework.task.TimeoutGuard)

Example 12 with TimeOutException

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";
    }
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Configuration(nl.nn.adapterframework.configuration.Configuration) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Example 13 with TimeOutException

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;
}
Also used : TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender)

Example 14 with TimeOutException

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;
}
Also used : TimeOutException(nl.nn.adapterframework.core.TimeOutException) JmsSender(nl.nn.adapterframework.jms.JmsSender) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with TimeOutException

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);
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) JCO(com.sap.mw.jco.JCO) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException)

Aggregations

TimeOutException (nl.nn.adapterframework.core.TimeOutException)31 SenderException (nl.nn.adapterframework.core.SenderException)30 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)15 IOException (java.io.IOException)12 HashMap (java.util.HashMap)11 Map (java.util.Map)9 ParameterException (nl.nn.adapterframework.core.ParameterException)9 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)8 LinkedHashMap (java.util.LinkedHashMap)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 InputStream (java.io.InputStream)3 Iterator (java.util.Iterator)3 JMSException (javax.jms.JMSException)3 ListenerException (nl.nn.adapterframework.core.ListenerException)3 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)3 JavaListener (nl.nn.adapterframework.receivers.JavaListener)3 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)3 JCoDestination (com.sap.conn.jco.JCoDestination)2