This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 3b955d3a9637 CAMEL-27620: camel-browse - the filter only chooses what
is browsed, the consumer gets every exchange (#30989)
3b955d3a9637 is described below
commit 3b955d3a9637e6aed8836345df0d83ca74a663a8
Author: allthingssecurity <[email protected]>
AuthorDate: Fri Nov 27 20:26:33 2026 +0530
CAMEL-27620: camel-browse - the filter only chooses what is browsed, the
consumer gets every exchange (#30989)
1. The producer of a browse endpoint tested the filter before it called
onExchange(), which both adds the exchange to the browse list and passes
it to the route that consumes from the endpoint. So when the filter
returned false, that route never got the exchange, and nothing was
logged. The filter is meant to choose the messages kept for browsing, as
its option description says. onExchange() now applies the filter only to
adding the exchange to the list, and always passes the exchange to the
consumer. The description of the filter option, which CAMEL-23832
(#30958) changed to say that a skipped message is also not passed to
the consuming route, now says that the consuming route gets every
message. The component JSON, its catalog copy and the endpoint DSL are
regenerated. The 4.24 upgrade guide has an entry for the change.
2. The doc page now says that the endpoint keeps the exchanges themselves,
not copies, so later steps of the route and of the consuming route change
what is browsed, and how to browse a copy. It also says what the filter
does. The catalog copy of the doc page is updated. No code change for
this point.
BrowseFilterConsumerTest (camel-core, next to the other browse tests)
checks that the consuming route gets all exchanges while the browse list
keeps only the filtered ones.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/catalog/components/browse.json | 2 +-
.../camel/catalog/docs/browse-component.adoc | 9 +++
.../org/apache/camel/component/browse/browse.json | 2 +-
.../src/main/docs/browse-component.adoc | 9 +++
.../camel/component/browse/BrowseEndpoint.java | 32 ++++++-----
.../component/browse/BrowseFilterConsumerTest.java | 66 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 6 ++
.../endpoint/dsl/BrowseEndpointBuilderFactory.java | 36 ++++++------
8 files changed, 127 insertions(+), 35 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/browse.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/browse.json
index 255e8eb25cc1..f4268903e975 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/browse.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/browse.json
@@ -42,6 +42,6 @@
"exchangePattern": { "index": 3, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
"lazyStartProducer": { "index": 4, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
"browseLimit": { "index": 5, "kind": "parameter", "displayName": "Browse
Limit", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "description": "The maximum number of messages that the
endpoint keeps in memory for browsing. When a new message goes over the limit,
the oldest message is removed from the list. The default is the browseLimit of
the component, and 0 means no limit, [...]
- "filter": { "index": 6, "kind": "parameter", "displayName": "Filter",
"group": "advanced", "label": "advanced", "required": false, "type": "object",
"javaType": "java.util.function.Predicate<org.apache.camel.Exchange>",
"deprecated": false, "autowired": false, "secret": false, "description": "A
predicate that the producer tests on each message: true keeps the message for
browsing, false skips it. A skipped message is also not passed to the route
that consumes from the endpoint. If no [...]
+ "filter": { "index": 6, "kind": "parameter", "displayName": "Filter",
"group": "advanced", "label": "advanced", "required": false, "type": "object",
"javaType": "java.util.function.Predicate<org.apache.camel.Exchange>",
"deprecated": false, "autowired": false, "secret": false, "description": "A
predicate that the producer tests on each message: true keeps the message for
browsing, false skips it. The filter only chooses what is browsed: the route
that consumes from the endpoint gets [...]
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/browse-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/browse-component.adoc
index 981649698cc0..5bbfcbaf217f 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/browse-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/browse-component.adoc
@@ -90,3 +90,12 @@ public void inspectReceivedOrders() {
}
}
----
+
+NOTE: The endpoint keeps the exchanges themselves, not copies. The route goes
on with the same exchange after the
+`browse:` endpoint, and so does a route that consumes from it, so a later step
that changes the message also changes
+what is browsed. To browse a message as it was when it reached the endpoint,
send a copy of the exchange, for example
+with `.wireTap("browse:orderReceived")`. The copy has its own headers, but a
body object that can be changed is still
+shared.
+
+The `filter` option only chooses which exchanges are kept for browsing. A
route that consumes from the same endpoint
+gets every exchange, also the ones the filter does not keep.
diff --git
a/components/camel-browse/src/generated/resources/META-INF/org/apache/camel/component/browse/browse.json
b/components/camel-browse/src/generated/resources/META-INF/org/apache/camel/component/browse/browse.json
index 255e8eb25cc1..f4268903e975 100644
---
a/components/camel-browse/src/generated/resources/META-INF/org/apache/camel/component/browse/browse.json
+++
b/components/camel-browse/src/generated/resources/META-INF/org/apache/camel/component/browse/browse.json
@@ -42,6 +42,6 @@
"exchangePattern": { "index": 3, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
"lazyStartProducer": { "index": 4, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
"browseLimit": { "index": 5, "kind": "parameter", "displayName": "Browse
Limit", "group": "advanced", "label": "advanced", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "description": "The maximum number of messages that the
endpoint keeps in memory for browsing. When a new message goes over the limit,
the oldest message is removed from the list. The default is the browseLimit of
the component, and 0 means no limit, [...]
- "filter": { "index": 6, "kind": "parameter", "displayName": "Filter",
"group": "advanced", "label": "advanced", "required": false, "type": "object",
"javaType": "java.util.function.Predicate<org.apache.camel.Exchange>",
"deprecated": false, "autowired": false, "secret": false, "description": "A
predicate that the producer tests on each message: true keeps the message for
browsing, false skips it. A skipped message is also not passed to the route
that consumes from the endpoint. If no [...]
+ "filter": { "index": 6, "kind": "parameter", "displayName": "Filter",
"group": "advanced", "label": "advanced", "required": false, "type": "object",
"javaType": "java.util.function.Predicate<org.apache.camel.Exchange>",
"deprecated": false, "autowired": false, "secret": false, "description": "A
predicate that the producer tests on each message: true keeps the message for
browsing, false skips it. The filter only chooses what is browsed: the route
that consumes from the endpoint gets [...]
}
}
diff --git a/components/camel-browse/src/main/docs/browse-component.adoc
b/components/camel-browse/src/main/docs/browse-component.adoc
index 981649698cc0..5bbfcbaf217f 100644
--- a/components/camel-browse/src/main/docs/browse-component.adoc
+++ b/components/camel-browse/src/main/docs/browse-component.adoc
@@ -90,3 +90,12 @@ public void inspectReceivedOrders() {
}
}
----
+
+NOTE: The endpoint keeps the exchanges themselves, not copies. The route goes
on with the same exchange after the
+`browse:` endpoint, and so does a route that consumes from it, so a later step
that changes the message also changes
+what is browsed. To browse a message as it was when it reached the endpoint,
send a copy of the exchange, for example
+with `.wireTap("browse:orderReceived")`. The copy has its own headers, but a
body object that can be changed is still
+shared.
+
+The `filter` option only chooses which exchanges are kept for browsing. A
route that consumes from the same endpoint
+gets every exchange, also the ones the filter does not keep.
diff --git
a/components/camel-browse/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java
b/components/camel-browse/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java
index 6b1a2483cc04..0753a7e3fd1b 100644
---
a/components/camel-browse/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java
+++
b/components/camel-browse/src/main/java/org/apache/camel/component/browse/BrowseEndpoint.java
@@ -66,8 +66,8 @@ public class BrowseEndpoint extends DefaultEndpoint
implements BrowsableEndpoint
private int browseLimit;
@UriParam(label = "advanced",
description = "A predicate that the producer tests on each
message: true keeps the message for browsing,"
- + " false skips it. A skipped message is also not
passed to the route that consumes from the"
- + " endpoint. If not set, every message is kept.")
+ + " false skips it. The filter only chooses what
is browsed: the route that consumes from the"
+ + " endpoint gets every message. If not set, every
message is kept.")
private Predicate<Exchange> filter;
private final Lock limitLock = new ReentrantLock();
@@ -109,13 +109,7 @@ public class BrowseEndpoint extends DefaultEndpoint
implements BrowsableEndpoint
public Producer createProducer() throws Exception {
return new DefaultProducer(this) {
public void process(Exchange exchange) throws Exception {
- boolean accept = true;
- if (filter != null) {
- accept = filter.test(exchange);
- }
- if (accept) {
- onExchange(exchange);
- }
+ onExchange(exchange);
}
};
}
@@ -154,6 +148,20 @@ public class BrowseEndpoint extends DefaultEndpoint
implements BrowsableEndpoint
* @throws Exception is thrown if failed to process the exchange
*/
protected void onExchange(Exchange exchange) throws Exception {
+ // the filter only chooses the exchanges that are kept for browsing:
the route that consumes from this endpoint
+ // gets every exchange
+ if (filter == null || filter.test(exchange)) {
+ addExchange(exchange);
+ }
+
+ // now fire the consumer
+ Processor processor = onExchangeProcessor;
+ if (processor != null) {
+ processor.process(exchange);
+ }
+ }
+
+ private void addExchange(Exchange exchange) {
List<Exchange> list = exchanges;
if (browseLimit > 0) {
// add first and then remove the oldest from the list itself: a
sub list is only a view that keeps them
@@ -172,12 +180,6 @@ public class BrowseEndpoint extends DefaultEndpoint
implements BrowsableEndpoint
} else {
list.add(exchange);
}
-
- // now fire the consumer
- Processor processor = onExchangeProcessor;
- if (processor != null) {
- processor.process(exchange);
- }
}
/**
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/browse/BrowseFilterConsumerTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/browse/BrowseFilterConsumerTest.java
new file mode 100644
index 000000000000..a359c430ea69
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/component/browse/BrowseFilterConsumerTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.browse;
+
+import java.util.List;
+import java.util.function.Predicate;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.BrowsableEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The filter of a browse endpoint only chooses the exchanges kept for
browsing: the route that consumes from the
+ * endpoint gets every exchange.
+ */
+class BrowseFilterConsumerTest extends ContextTestSupport {
+
+ @Test
+ void theConsumerGetsTheExchangesTheFilterDoesNotKeep() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:consumed");
+ mock.expectedBodiesReceived("one", "two", "three", "four");
+
+ for (String body : List.of("one", "two", "three", "four")) {
+ template.sendBody("direct:start", body);
+ }
+
+ assertMockEndpointsSatisfied();
+ BrowsableEndpoint browse =
context.getEndpoint("browse:bar?filter=#evenFilter", BrowsableEndpoint.class);
+ assertEquals(List.of("two", "four"),
+ browse.getExchanges().stream().map(e ->
e.getMessage().getBody(String.class)).toList());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ context.getRegistry().bind("evenFilter", (Predicate<Exchange>)
exchange -> {
+ String body = exchange.getMessage().getBody(String.class);
+ return "two".equals(body) || "four".equals(body);
+ });
+
+ from("direct:start").to("browse:bar?filter=#evenFilter");
+ from("browse:bar?filter=#evenFilter").to("mock:consumed");
+ }
+ };
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index b70db850eb10..976331bd9859 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -496,6 +496,12 @@ exchanges is low enough again.
A custom `RoutePolicySupport` can take part by overriding
`isConsumerKeptSuspended(Route)`.
+=== camel-browse - the filter only chooses the messages kept for browsing
+
+The `filter` option of a browse endpoint now only chooses the messages that
the endpoint keeps for browsing. A route
+that consumes from the endpoint gets every message. Before, a message that the
filter skipped was not passed to the
+consuming route either. To drop messages in the consuming route, use the
Filter EIP in that route.
+
=== camel-seda - a discarded request-reply message fails at once
When the SEDA producer waits for the reply (`InOut` messages, or
`waitForTaskToComplete=Always`) and discards the
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/BrowseEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/BrowseEndpointBuilderFactory.java
index 982295e6b764..3796d24ba265 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/BrowseEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/BrowseEndpointBuilderFactory.java
@@ -210,9 +210,9 @@ public interface BrowseEndpointBuilderFactory {
}
/**
* A predicate that the producer tests on each message: true keeps the
- * message for browsing, false skips it. A skipped message is also not
- * passed to the route that consumes from the endpoint. If not set,
- * every message is kept.
+ * message for browsing, false skips it. The filter only chooses what
is
+ * browsed: the route that consumes from the endpoint gets every
+ * message. If not set, every message is kept.
*
* The option is a:
*
<code>java.util.function.Predicate<org.apache.camel.Exchange></code> type.
@@ -228,9 +228,9 @@ public interface BrowseEndpointBuilderFactory {
}
/**
* A predicate that the producer tests on each message: true keeps the
- * message for browsing, false skips it. A skipped message is also not
- * passed to the route that consumes from the endpoint. If not set,
- * every message is kept.
+ * message for browsing, false skips it. The filter only chooses what
is
+ * browsed: the route that consumes from the endpoint gets every
+ * message. If not set, every message is kept.
*
* The option will be converted to a
*
<code>java.util.function.Predicate<org.apache.camel.Exchange></code> type.
@@ -350,9 +350,9 @@ public interface BrowseEndpointBuilderFactory {
}
/**
* A predicate that the producer tests on each message: true keeps the
- * message for browsing, false skips it. A skipped message is also not
- * passed to the route that consumes from the endpoint. If not set,
- * every message is kept.
+ * message for browsing, false skips it. The filter only chooses what
is
+ * browsed: the route that consumes from the endpoint gets every
+ * message. If not set, every message is kept.
*
* The option is a:
*
<code>java.util.function.Predicate<org.apache.camel.Exchange></code> type.
@@ -368,9 +368,9 @@ public interface BrowseEndpointBuilderFactory {
}
/**
* A predicate that the producer tests on each message: true keeps the
- * message for browsing, false skips it. A skipped message is also not
- * passed to the route that consumes from the endpoint. If not set,
- * every message is kept.
+ * message for browsing, false skips it. The filter only chooses what
is
+ * browsed: the route that consumes from the endpoint gets every
+ * message. If not set, every message is kept.
*
* The option will be converted to a
*
<code>java.util.function.Predicate<org.apache.camel.Exchange></code> type.
@@ -448,9 +448,9 @@ public interface BrowseEndpointBuilderFactory {
}
/**
* A predicate that the producer tests on each message: true keeps the
- * message for browsing, false skips it. A skipped message is also not
- * passed to the route that consumes from the endpoint. If not set,
- * every message is kept.
+ * message for browsing, false skips it. The filter only chooses what
is
+ * browsed: the route that consumes from the endpoint gets every
+ * message. If not set, every message is kept.
*
* The option is a:
*
<code>java.util.function.Predicate<org.apache.camel.Exchange></code> type.
@@ -466,9 +466,9 @@ public interface BrowseEndpointBuilderFactory {
}
/**
* A predicate that the producer tests on each message: true keeps the
- * message for browsing, false skips it. A skipped message is also not
- * passed to the route that consumes from the endpoint. If not set,
- * every message is kept.
+ * message for browsing, false skips it. The filter only chooses what
is
+ * browsed: the route that consumes from the endpoint gets every
+ * message. If not set, every message is kept.
*
* The option will be converted to a
*
<code>java.util.function.Predicate<org.apache.camel.Exchange></code> type.