Search in sources :

Example 6 with ListenerException

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

the class JdbcTransactionalStorage method getMessageCount.

public int getMessageCount() throws ListenerException {
    Connection conn;
    try {
        conn = getConnection();
    } catch (JdbcException e) {
        throw new ListenerException(e);
    }
    try {
        PreparedStatement stmt = conn.prepareStatement(getMessageCountQuery);
        applyStandardParameters(stmt, false, false);
        ResultSet rs = stmt.executeQuery();
        if (!rs.next()) {
            log.warn(getLogPrefix() + "no message count found");
            return 0;
        }
        return rs.getInt(1);
    } catch (Exception e) {
        throw new ListenerException("cannot determine message count", 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)

Example 7 with ListenerException

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

the class JdbcTransactionalStorage method browseMessage.

public Object browseMessage(String messageId) throws ListenerException {
    Connection conn;
    try {
        conn = getConnection();
    } catch (JdbcException e) {
        throw new ListenerException(e);
    }
    try {
        PreparedStatement stmt = conn.prepareStatement(selectDataQuery);
        applyStandardParameters(stmt, messageId, true);
        ResultSet rs = stmt.executeQuery();
        if (!rs.next()) {
            throw new ListenerException("could not retrieve message for messageid [" + messageId + "]");
        }
        return retrieveObject(rs, 1);
    } 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)

Example 8 with ListenerException

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

the class PullingJmsListener method getRawMessageFromDestination.

/**
 * Retrieves messages from queue or other channel under transaction control, but does no processing on it.
 */
private Object getRawMessageFromDestination(String correlationId, Map threadContext) throws ListenerException {
    Session session = null;
    Object msg = null;
    try {
        session = getSession(threadContext);
        MessageConsumer mc = null;
        try {
            mc = getReceiver(threadContext, session, correlationId);
            msg = mc.receive(getTimeOut());
            while (msg == null && correlationId == null && canGoOn() && !isTransacted()) {
                msg = mc.receive(getTimeOut());
            }
        } catch (JMSException e) {
            throw new ListenerException(getLogPrefix() + "exception retrieving message", e);
        } finally {
            releaseReceiver(mc, correlationId);
        }
    } finally {
        if (sessionNeedsToBeSavedForAfterProcessMessage(msg)) {
            threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
        } else {
            releaseSession(session);
        }
    }
    return msg;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ListenerException(nl.nn.adapterframework.core.ListenerException) JMSException(javax.jms.JMSException) Session(javax.jms.Session) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

Example 9 with ListenerException

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

the class PullingJmsListener method retrieveRawMessage.

/**
 * @see nl.nn.adapterframework.core.IPostboxListener#retrieveRawMessage(java.lang.String, java.util.Map)
 */
public Object retrieveRawMessage(String messageSelector, Map threadContext) throws ListenerException {
    Session session = null;
    try {
        session = getSession(threadContext);
        MessageConsumer mc = null;
        try {
            mc = getMessageConsumer(session, getDestination(), messageSelector);
            Object result = (getTimeOut() < 0) ? mc.receiveNoWait() : mc.receive(getTimeOut());
            return result;
        } finally {
            if (mc != null) {
                try {
                    mc.close();
                } catch (JMSException e) {
                    log.warn(getLogPrefix() + "exception closing messageConsumer", e);
                }
            }
        }
    } catch (Exception e) {
        throw new ListenerException(getLogPrefix() + "exception preparing to retrieve message", e);
    } finally {
        releaseSession(session);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ListenerException(nl.nn.adapterframework.core.ListenerException) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) ListenerException(nl.nn.adapterframework.core.ListenerException) Session(javax.jms.Session) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

Example 10 with ListenerException

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

the class JmsMessageBrowser method doBrowse.

protected Message doBrowse(Map selectors) throws ListenerException {
    QueueSession session = null;
    Message msg = null;
    QueueBrowser queueBrowser = null;
    try {
        session = (QueueSession) createSession();
        queueBrowser = session.createBrowser((Queue) getDestination(), getCombinedSelector(selectors));
        Enumeration msgenum = queueBrowser.getEnumeration();
        if (msgenum.hasMoreElements()) {
            msg = (Message) msgenum.nextElement();
        }
        return msg;
    } catch (Exception e) {
        throw new ListenerException(e);
    } finally {
        try {
            if (queueBrowser != null) {
                queueBrowser.close();
            }
        } catch (JMSException e1) {
            throw new ListenerException("exception closing queueBrowser", e1);
        }
        closeSession(session);
    }
}
Also used : ListenerException(nl.nn.adapterframework.core.ListenerException) Enumeration(java.util.Enumeration) Message(javax.jms.Message) JMSException(javax.jms.JMSException) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) QueueBrowser(javax.jms.QueueBrowser) JMSException(javax.jms.JMSException) ListenerException(nl.nn.adapterframework.core.ListenerException)

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