shashank created CAMEL-25361:
--------------------------------
Summary: camel-couchbase - with useView=true and
fullDocument=false the body is an Optional, and fullDocument is documented as
default false although it defaults to true
Key: CAMEL-25361
URL: https://issues.apache.org/jira/browse/CAMEL-25361
Project: Camel
Issue Type: Bug
Components: camel-couchbase
Reporter: shashank
*The body of a view row is an {{Optional}}.* With {{useView=true}} and
{{fullDocument=false}} the consumer sets the body to
{{row.valueAs(Object.class)}}. In the Couchbase Java SDK 3 {{ViewRow.valueAs}}
returns {{Optional<T>}}, so the body is {{Optional[value]}} instead of the
value the view emitted, and {{Optional.empty}} when the view emitted {{null}}
(for example {{emit(doc._id, null)}}). The call dates from the option itself
(CAMEL-15792, 3.7, the SDK 3 migration); no test or IT covered
{{fullDocument=false}} with a view. The SQL++ path ({{useView=false}}, the
default since CAMEL-23218) is not affected: it uses {{row.toString()}}, the row
as a JSON string.
*The default of {{fullDocument}} is documented wrongly.* The field is {{private
boolean fullDocument = true}}, but its {{@UriParam}} says {{defaultValue =
"false"}}, so the component JSON, the catalog, the endpoint DSL javadoc
("Default: false") and the option table on the component page all say false.
Both date from CAMEL-15792 (commit e4c4d0e101f9). True is the intended and
actual default: before that commit the consumer always fetched the document, so
true keeps that behaviour, and the SQL++ section of the component page already
says "When {{fullDocument}} is {{true}} (the default)". A user or tool that
relies on the documented default and leaves the option out gets the full
document.
h3. Reproduction
New {{CouchbaseConsumerBodyTest}} (mocked cluster, the test calls {{poll()}}):
* {{theValueEmittedByTheViewIsTheBodyWithoutFullDocument}}: on main {{expected:
<[{name=Alice}, Bob]> but was: <[Optional[{name=Alice}], Optional[Bob]]>}};
* {{theBodyIsNullWhenTheViewEmitsNoValue}}: on main {{expected: <null> but was:
<Optional.empty>}};
* controls, pass on main: {{theQueryRowIsTheBodyWithoutFullDocument}} (SQL++
row as JSON string) and {{theFullDocumentIsTheBodyByDefault}} (without the
option the consumer fetches the document).
The two view tests fail in two runs on main.
h3. Proposed fix
* {{row.valueAs(Object.class).orElse(null)}}: the body is the value the view
emitted, or {{null}} when it emitted none (an empty message, as for any
consumer without content).
* {{@UriParam(defaultValue = "true")}} on {{fullDocument}}; component JSON,
catalog JSON and endpoint DSL regenerated. No runtime change.
* Upgrade guide 4.23, under {{=== camel-couchbase}}: the body change for views
with {{fullDocument=false}}; and under the existing {{====
consumerProcessedStrategy=delete}} the line asked for in the review of #27347:
a view or SQL++ query that returns several rows for one document now delivers
only the first of these rows with {{delete}} (checked against the code: the
first row marks the document in progress, the other rows are skipped, and the
completed exchange removes the document; in 4.22 the next row of the already
removed document failed the whole poll).
Module: 61 tests pass.
In the same review Claus also suggested clearing the set of documents in
progress in {{doStop}}/{{doStart}}, as the set would survive
{{stopRoute}}/{{startRoute}}. That turned out unnecessary: a route restart
creates a new consumer ({{RouteService}} sets the route up again and
{{DefaultRoute.initializeServices}} calls {{endpoint.createConsumer}}), so the
set starts empty after a route restart. It is not part of this change.
Affected: the {{Optional}} body and the documented default in 4.14.x, 4.18.x
and main. The body fix changes what routes receive, so it is proposed for main
with the upgrade note; the upgrade-guide line on several rows applies only to
4.23 (CAMEL-25221).
Duplicate check (2026-10-05): JIRA "fullDocument" (only a camel-mongodb issue),
"valueAs" (none), component camel-couchbase with "Optional" (none relevant),
open camel-couchbase issues (CAMEL-23625, CAMEL-23626, integration tests and
examples). GitHub pull requests "couchbase fullDocument", "couchbase Optional",
"couchbase valueAs": none.
_Filed with Claude Code on behalf of allthingssecurity._
--
This message was sent by Atlassian Jira
(v8.20.10#820010)