Search in sources :

Example 51 with SenderException

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

the class StatisticsKeeperStore method openGroup.

public Object openGroup(Object parentData, String name, String type) throws SenderException {
    SessionInfo sessionInfo = (SessionInfo) parentData;
    int parentKey = sessionInfo.groupKey;
    int groupKey;
    try {
        groupKey = groups.findOrInsert(sessionInfo.connection, parentKey, instanceKey, name, type);
        SessionInfo groupData = new SessionInfo();
        groupData.connection = sessionInfo.connection;
        groupData.eventKey = sessionInfo.eventKey;
        groupData.groupKey = groupKey;
        return groupData;
    } catch (JdbcException e) {
        throw new SenderException(e);
    }
}
Also used : SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException)

Example 52 with SenderException

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

the class StatisticsKeeperStore method start.

public Object start(Date now, Date mainMark, Date detailMark) throws SenderException {
    List nameList = new LinkedList();
    List valueList = new LinkedList();
    now = new Date();
    SessionInfo sessionInfo = new SessionInfo();
    PreparedStatement stmt = null;
    long freeMem = Runtime.getRuntime().freeMemory();
    long totalMem = Runtime.getRuntime().totalMemory();
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_HOUR, PERIOD_FORMAT_DATEHOUR }, PERIOD_ALLOWED_LENGTH_HOUR, "s", mainMark);
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_DAY, PERIOD_FORMAT_DATE, PERIOD_FORMAT_WEEKDAY }, PERIOD_ALLOWED_LENGTH_DAY, "s", mainMark);
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_WEEK, PERIOD_FORMAT_YEARWEEK }, PERIOD_ALLOWED_LENGTH_WEEK, "s", mainMark);
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_MONTH, PERIOD_FORMAT_YEARMONTH }, PERIOD_ALLOWED_LENGTH_MONTH, "s", mainMark);
    addPeriodIndicator(nameList, valueList, now, new String[][] { PERIOD_FORMAT_YEAR }, PERIOD_ALLOWED_LENGTH_YEAR, "s", mainMark);
    try {
        Connection connection = getConnection();
        sessionInfo.connection = connection;
        String hostname = Misc.getHostname();
        int hostKey = hosts.findOrInsert(connection, hostname);
        sessionInfo.eventKey = JdbcUtil.executeIntQuery(connection, selectNextValueQuery);
        String insertEventQuery = null;
        try {
            String insertClause = insertEventQueryInsertClause;
            String valuesClause = insertEventQueryValuesClause;
            for (Iterator it = nameList.iterator(); it.hasNext(); ) {
                String name = (String) it.next();
                insertClause += "," + name;
                valuesClause += ",?";
            }
            insertEventQuery = insertClause + valuesClause + ")";
            if (trace && log.isDebugEnabled())
                log.debug("prepare and execute query [" + insertEventQuery + "]");
            stmt = connection.prepareStatement(insertEventQuery);
            int pos = 1;
            stmt.setInt(pos++, sessionInfo.eventKey);
            stmt.setInt(pos++, instanceKey);
            stmt.setInt(pos++, hostKey);
            stmt.setLong(pos++, totalMem - freeMem);
            stmt.setLong(pos++, totalMem);
            stmt.setTimestamp(pos++, new Timestamp(now.getTime()));
            stmt.setTimestamp(pos++, new Timestamp(mainMark.getTime()));
            for (Iterator it = valueList.iterator(); it.hasNext(); ) {
                String value = (String) it.next();
                stmt.setString(pos++, value);
            }
            stmt.execute();
        } catch (Exception e) {
            throw new JdbcException("could not execute query [" + insertEventQuery + "]", e);
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                    throw new JdbcException("could not close statement for query [" + insertEventQuery + "]", e);
                }
            }
        }
        return sessionInfo;
    } catch (Exception e) {
        throw new SenderException(e);
    }
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) LinkedList(java.util.LinkedList) Date(java.util.Date) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SQLException(java.sql.SQLException) SenderException(nl.nn.adapterframework.core.SenderException) Iterator(java.util.Iterator) List(java.util.List) LinkedList(java.util.LinkedList) SenderException(nl.nn.adapterframework.core.SenderException)

Example 53 with SenderException

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

the class StatisticsKeeperStore method handleScalar.

public void handleScalar(Object data, String scalarName, long value) throws SenderException {
    SessionInfo sessionInfo = (SessionInfo) data;
    PreparedStatement stmt = null;
    int statnamekey = -1;
    try {
        statnamekey = statnames.findOrInsert(sessionInfo.connection, scalarName);
        if (trace && log.isDebugEnabled())
            log.debug("prepare and execute query [" + insertNumQuery + "] params [" + sessionInfo.eventKey + "," + sessionInfo.groupKey + "," + statnamekey + "," + value + "]");
        stmt = sessionInfo.connection.prepareStatement(insertNumQuery);
        stmt.setLong(1, sessionInfo.eventKey);
        stmt.setLong(2, sessionInfo.groupKey);
        stmt.setLong(3, statnamekey);
        stmt.setLong(4, value);
        stmt.execute();
    } catch (Exception e) {
        throw new SenderException("could not execute query [" + insertNumQuery + "] params [" + sessionInfo.eventKey + "," + sessionInfo.groupKey + "," + statnamekey + "," + value + "]", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception e) {
                throw new SenderException("could not close statement for query [" + insertNumQuery + "] params [" + sessionInfo.eventKey + "," + sessionInfo.groupKey + "," + statnamekey + "," + value + "]", e);
            }
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SQLException(java.sql.SQLException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 54 with SenderException

use of nl.nn.adapterframework.core.SenderException 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 55 with SenderException

use of nl.nn.adapterframework.core.SenderException 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)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)130 TimeOutException (nl.nn.adapterframework.core.TimeOutException)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)36 SQLException (java.sql.SQLException)25 HashMap (java.util.HashMap)21 ParameterException (nl.nn.adapterframework.core.ParameterException)21 PreparedStatement (java.sql.PreparedStatement)20 Map (java.util.Map)20 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 Iterator (java.util.Iterator)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 InputStream (java.io.InputStream)15 ResultSet (java.sql.ResultSet)13 Element (org.w3c.dom.Element)13 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)12 Date (java.util.Date)10 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9