Search in sources :

Example 1 with ListenerException

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

the class JdbcListener method getRawMessage.

protected Object getRawMessage(Connection conn, Map threadContext) throws ListenerException {
    boolean inTransaction = false;
    try {
        inTransaction = JtaUtil.inTransaction();
    } catch (Exception e) {
        log.warn(getLogPrefix() + "could not determing XA transaction status, assuming not in XA transaction: " + e.getMessage());
        inTransaction = false;
    }
    try {
        if (!inTransaction) {
            execute(conn, getStartLocalTransactionQuery());
        }
        String query = preparedSelectQuery;
        try {
            Statement stmt = null;
            try {
                stmt = conn.createStatement();
                stmt.setFetchSize(1);
                ResultSet rs = null;
                try {
                    if (trace && log.isDebugEnabled())
                        log.debug("executing query for [" + query + "]");
                    rs = stmt.executeQuery(query);
                    if (!rs.next()) {
                        return null;
                    }
                    Object result;
                    String key = rs.getString(getKeyField());
                    if (StringUtils.isNotEmpty(getMessageField())) {
                        String message;
                        if ("clob".equalsIgnoreCase(getMessageFieldType())) {
                            message = JdbcUtil.getClobAsString(rs, getMessageField(), false);
                        } else {
                            if ("blob".equalsIgnoreCase(getMessageFieldType())) {
                                message = JdbcUtil.getBlobAsString(rs, getMessageField(), getBlobCharset(), false, isBlobsCompressed(), isBlobSmartGet(), false);
                            } else {
                                message = rs.getString(getMessageField());
                            }
                        }
                        // log.debug("building wrapper for key ["+key+"], message ["+message+"]");
                        MessageWrapper mw = new MessageWrapper();
                        mw.setId(key);
                        mw.setText(message);
                        result = mw;
                    } else {
                        result = key;
                    }
                    return result;
                } finally {
                    if (rs != null) {
                        rs.close();
                    }
                }
            } finally {
                if (stmt != null) {
                    stmt.close();
                }
            }
        } catch (Exception e) {
            throw new ListenerException(getLogPrefix() + "caught exception retrieving message using query [" + query + "]", e);
        }
    } finally {
        if (!inTransaction) {
            execute(conn, getCommitLocalTransactionQuery());
        }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) MessageWrapper(nl.nn.adapterframework.receivers.MessageWrapper) IMessageWrapper(nl.nn.adapterframework.core.IMessageWrapper) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SQLException(java.sql.SQLException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 2 with ListenerException

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

the class JdbcListener method afterMessageProcessed.

public void afterMessageProcessed(PipeLineResult processResult, Object rawMessage, Map context) throws ListenerException {
    String key = getIdFromRawMessage(rawMessage, context);
    if (isConnectionsArePooled()) {
        Connection c = null;
        try {
            // log.debug("getting connection");
            c = getConnection();
            afterMessageProcessed(c, processResult, key, context);
        } catch (JdbcException e) {
            throw new ListenerException(e);
        } finally {
            if (c != null) {
                try {
                    // log.debug("closing connection");
                    c.close();
                } catch (SQLException e) {
                    log.warn(new ListenerException(getLogPrefix() + "caught exception closing connection in afterMessageProcessed()", e));
                }
            }
        }
    } else {
        synchronized (connection) {
            afterMessageProcessed(connection, processResult, key, context);
        }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 3 with ListenerException

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

the class JdbcListener method execute.

protected void execute(Connection conn, String query, String parameter) throws ListenerException {
    if (StringUtils.isNotEmpty(query)) {
        if (trace && log.isDebugEnabled())
            log.debug("executing statement [" + query + "]");
        PreparedStatement stmt = null;
        try {
            stmt = conn.prepareStatement(query);
            stmt.clearParameters();
            if (StringUtils.isNotEmpty(parameter)) {
                log.debug("setting parameter 1 to [" + parameter + "]");
                stmt.setString(1, parameter);
            }
            stmt.execute();
        } catch (SQLException e) {
            throw new ListenerException(getLogPrefix() + "exception executing statement [" + query + "]", e);
        } finally {
            if (stmt != null) {
                try {
                    // log.debug("closing statement for ["+query+"]");
                    stmt.close();
                } catch (SQLException e) {
                    log.warn(getLogPrefix() + "exception closing statement [" + query + "]", e);
                }
            }
        }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 4 with ListenerException

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

the class JdbcTransactionalStorage method getContext.

public IMessageBrowsingIteratorItem getContext(String messageId) throws ListenerException {
    Connection conn;
    try {
        conn = getConnection();
    } catch (JdbcException e) {
        throw new ListenerException(e);
    }
    try {
        PreparedStatement stmt = conn.prepareStatement(selectContextQuery);
        applyStandardParameters(stmt, messageId, true);
        ResultSet rs = stmt.executeQuery();
        if (!rs.next()) {
            throw new ListenerException("could not retrieve context for messageid [" + messageId + "]");
        }
        return new JdbcTransactionalStorageIteratorItem(conn, rs, true);
    } catch (Exception e) {
        throw new ListenerException("cannot read context", e);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) ListenerException(nl.nn.adapterframework.core.ListenerException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 5 with ListenerException

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

the class JdbcTransactionalStorage method containsCorrelationId.

public boolean containsCorrelationId(String correlationId) throws ListenerException {
    Connection conn;
    try {
        conn = getConnection();
    } catch (JdbcException e) {
        throw new ListenerException(e);
    }
    try {
        PreparedStatement stmt = conn.prepareStatement(checkCorrelationIdQuery);
        applyStandardParameters(stmt, correlationId, false);
        ResultSet rs = stmt.executeQuery();
        if (!rs.next()) {
            return false;
        }
        return true;
    } catch (Exception e) {
        throw new ListenerException("cannot deserialize message", e);
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            log.error("error closing JdbcConnection", e);
        }
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) ListenerException(nl.nn.adapterframework.core.ListenerException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

ListenerException (nl.nn.adapterframework.core.ListenerException)84 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)19 HashMap (java.util.HashMap)18 Map (java.util.Map)18 JMSException (javax.jms.JMSException)16 SenderException (nl.nn.adapterframework.core.SenderException)14 SQLException (java.sql.SQLException)13 PreparedStatement (java.sql.PreparedStatement)11 Session (javax.jms.Session)10 LinkedHashMap (java.util.LinkedHashMap)9 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)9 TimeOutException (nl.nn.adapterframework.core.TimeOutException)9 IfsaException (nl.nn.adapterframework.extensions.ifsa.IfsaException)9 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 QueueSession (javax.jms.QueueSession)8 File (java.io.File)7 MessageConsumer (javax.jms.MessageConsumer)7 Message (javax.jms.Message)6