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());
}
}
}
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);
}
}
}
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);
}
}
}
}
}
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);
}
}
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);
}
}
}
Aggregations