Search in sources :

Example 56 with TimeOutException

use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.

the class ReloadSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
    String configName = null;
    String activeVersion = null;
    boolean forceReload = getForceReload();
    ParameterValueList pvl = null;
    try {
        if (paramList != null) {
            pvl = paramList.getValues(message, session);
            if (pvl.getParameterValue("name") != null)
                configName = pvl.getParameterValue("name").asStringValue();
            if (pvl.getParameterValue("forceReload") != null)
                forceReload = pvl.getParameterValue("forceReload").asBooleanValue(false);
        }
    } catch (ParameterException e) {
        throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
    }
    try {
        if (configName == null)
            configName = XmlUtils.evaluateXPathNodeSetFirstElement(message.asString(), "row/field[@name='NAME']");
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "error evaluating Xpath expression configName", e);
    }
    try {
        if (!forceReload) {
            activeVersion = XmlUtils.evaluateXPathNodeSetFirstElement(message.asString(), "row/field[@name='VERSION']");
        }
    } catch (Exception e) {
        throw new SenderException(getLogPrefix() + "error evaluating Xpath expression activeVersion", e);
    }
    Configuration configuration = ibisManager.getConfiguration(configName);
    if (configuration != null) {
        String latestVersion = configuration.getVersion();
        if (forceReload || (latestVersion != null && !activeVersion.equals(latestVersion))) {
            IbisContext ibisContext = ibisManager.getIbisContext();
            ibisContext.reload(configName);
            return new Message("Reload " + configName + " succeeded");
        }
        return new Message("Reload " + configName + " skipped");
    }
    log.warn("Configuration [" + configName + "] not loaded yet");
    return new Message("Reload " + configName + " skipped");
}
Also used : IbisContext(nl.nn.adapterframework.configuration.IbisContext) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Configuration(nl.nn.adapterframework.configuration.Configuration) Message(nl.nn.adapterframework.stream.Message) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 57 with TimeOutException

use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.

the class ForEachChildElementPipeTest method testTimeout.

@Test
public void testTimeout() throws Exception {
    Exception targetException = new TimeoutException("FakeTimeout");
    pipe.setSender(getElementRenderer(targetException));
    configurePipe();
    pipe.start();
    try {
        doPipe(pipe, messageError, session);
        fail("Expected exception to be thrown");
    } catch (Exception e) {
        assertThat(e.getMessage(), StringContains.containsString("FakeTimeout"));
        assertCauseChainEndsAtOriginalException(targetException, e);
    }
}
Also used : TimeoutException(nl.nn.adapterframework.core.TimeoutException) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) Test(org.junit.Test)

Example 58 with TimeOutException

use of nl.nn.adapterframework.core.TimeOutException in project iaf by ibissource.

the class ForEachChildElementPipeTest method testTimeoutXpath.

@Test
public void testTimeoutXpath() throws Exception {
    Exception targetException = new TimeoutException("FakeTimeout");
    pipe.setSender(getElementRenderer(targetException));
    pipe.setElementXPathExpression("/root/sub");
    configurePipe();
    pipe.start();
    try {
        doPipe(pipe, messageError, session);
        fail("Expected exception to be thrown");
    } catch (Exception e) {
        assertThat(e.getMessage(), StringContains.containsString("FakeTimeout"));
        assertCauseChainEndsAtOriginalException(targetException, e);
    }
}
Also used : TimeoutException(nl.nn.adapterframework.core.TimeoutException) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) Test(org.junit.Test)

Example 59 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<String, Map<String, Object>> queues, Map<String, Object> 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);
            PipeLineSession session = new PipeLineSession();
            session.put(PipeLineSession.businessCorrelationIdKey, TestTool.TESTTOOL_CORRELATIONID);
            String postResult = prePostFixedQuerySender.sendMessage(TESTTOOL_DUMMY_MESSAGE, session).asString();
            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 (IOException | 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 {
            PipeLineSession session = new PipeLineSession();
            session.put(PipeLineSession.businessCorrelationIdKey, TestTool.TESTTOOL_CORRELATIONID);
            message = readQueryFixedQuerySender.sendMessage(TESTTOOL_DUMMY_MESSAGE, session).asString();
        } catch (TimeoutException e) {
            errorMessage("Time out on execute query for '" + queueName + "': " + e.getMessage(), e, writers);
        } catch (IOException | 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 : PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FixedQuerySender(nl.nn.adapterframework.jdbc.FixedQuerySender) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Example 60 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<String, Map<String, Object>> queues, Map<String, Object> 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(new nl.nn.adapterframework.stream.Message(fileContent), null);
        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 : Message(nl.nn.adapterframework.stream.Message) JmsSender(nl.nn.adapterframework.jms.JmsSender) SenderException(nl.nn.adapterframework.core.SenderException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)68 TimeoutException (nl.nn.adapterframework.core.TimeoutException)45 IOException (java.io.IOException)40 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)34 TimeOutException (nl.nn.adapterframework.core.TimeOutException)28 Message (nl.nn.adapterframework.stream.Message)26 ParameterException (nl.nn.adapterframework.core.ParameterException)24 HashMap (java.util.HashMap)20 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)18 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)12 ListenerException (nl.nn.adapterframework.core.ListenerException)10 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)9 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)9 JMSException (javax.jms.JMSException)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)8 FileNotFoundException (java.io.FileNotFoundException)7 InputStream (java.io.InputStream)7 SAXException (org.xml.sax.SAXException)7 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)6