Federico Mariani created CAMEL-27011:
----------------------------------------
Summary: camel-jdbc / camel-sql - outputType=StreamList with
outputClass: a row that cannot be mapped is skipped by a redelivered split
Key: CAMEL-27011
URL: https://issues.apache.org/jira/browse/CAMEL-27011
Project: Camel
Issue Type: Bug
Components: camel-jdbc, camel-sql
Reporter: Federico Mariani
With {{outputType=StreamList}} and {{outputClass}}, each row is mapped to the
output class when the route reads it. When a row cannot be mapped (for example,
a column value that does not convert to the type of its bean property), the
exception of the first pass fails the split as expected. But the failure comes
from the iteration of the splitter itself, so, as in CAMEL-26996, the error
handler of the route redelivers to the splitter with the same body (the same
iterator), and that iterator no longer stops at the row that failed:
* *camel-jdbc* (and camel-spring-jdbc): the body is a {{StreamListIterator}}
({{core/camel-support/src/main/java/org/apache/camel/support/StreamListIterator.java}})
over the {{ResultSetIterator}}. {{next()}} takes the row from the result set
first, then maps it:
{code:java}
public E next() {
T row = delegate.next(); // the result set is now past this row
return rowMapper.map(row); // JdbcBeanMapper ->
JdbcHelper.newBeanInstance throws
}
{code}
A redelivered split goes on with the next row: the exchange succeeds *without
the row that could not be mapped*.
* *camel-sql*: the mapping is done in {{ResultSetIterator.next()}}
({{components/camel-sql/src/main/java/org/apache/camel/component/sql/ResultSetIterator.java}})
by Spring's {{BeanPropertyRowMapper}}. Since CAMEL-26996 an {{SQLException}}
keeps the iterator failing, but a mapper that fails with a {{RuntimeException}}
(such as Spring's {{TypeMismatchException}} for a value that does not convert
to an enum property, or a custom {{RowMapperFactory}}) is not caught. When the
split fails, the splitter closes the iterator body
({{Splitter.SplitterIterable.close()}} -> {{IOHelper.closeIterator}}), and
{{hasNext()}} is then {{!closed}}: a redelivered split finds no more rows and
the exchange succeeds *without that row and all the rows after it*.
The rows are lost without an error; the only trace is the DEBUG log of the
redelivery. Found while fixing CAMEL-26996 (fault-injection tests against a
real PostgreSQL).
h3. Steps to reproduce
{code:java}
// table item (id integer, status varchar(10)): (1, 'NEW'), (2, 'LOST'), (3,
'DONE')
// Item has int id and an enum Status { NEW, DONE } status: row 2 cannot be
mapped
from("direct:split")
.errorHandler(defaultErrorHandler().maximumRedeliveries(2).redeliveryDelay(0))
.to("jdbc:ds?outputType=StreamList&outputClass=com.foo.Item")
// or .to("sql:select * from item order by
id?outputType=StreamList&outputClass=com.foo.Item")
.split(body()).streaming()
.to("mock:row")
.end();
{code}
h3. Actual (4.24.0-SNAPSHOT, with CAMEL-26996 and CAMEL-26997)
* Without error handler: the exchange fails (correct).
* With the redelivery policy: the exchange succeeds. camel-jdbc routes rows 1
and 3 (row 2 is skipped); camel-sql routes row 1 only (rows 2 and 3 are
skipped).
h3. Expected
The exchange fails once the redeliveries are exhausted, as for a row that
cannot be read (CAMEL-26996): a row that cannot be mapped must not be skipped.
h3. Suggested fix
Same as CAMEL-26996: once mapping a row has failed, the iterator keeps failing
({{hasNext()}} and {{next()}} throw a {{RuntimeCamelException}} with the
mapping failure as cause), in {{StreamListIterator}} (camel-jdbc; also used by
camel-google-bigquery) and in camel-sql's {{ResultSetIterator}} (any
{{RuntimeException}} of the row mapper, also after {{close()}}). The first
failure stays the exception of the mapper.
_Claude Code on behalf of Croway_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)