This is an automated email from the ASF dual-hosted git repository.
oscerd 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 07318cfe7e07 CAMEL-24420: camel-hazelcast - apply the default
serialization filter to Camel-built client configurations (#25595)
07318cfe7e07 is described below
commit 07318cfe7e07379a6155117d9c2cf27e99af4687
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Aug 24 07:45:10 2026 +0200
CAMEL-24420: camel-hazelcast - apply the default serialization filter to
Camel-built client configurations (#25595)
getOrCreateHzClientInstance() builds its own ClientConfig when neither a
referenced ClientConfig nor hazelcastConfigUri is supplied, but never
applied a default JavaSerializationFilterConfig. The node-mode
counterpart getOrCreateHzInstance() has applied one since CAMEL-23414,
so the two modes behaved differently for an otherwise identical endpoint
configuration.
Add an applyDefault(ClientConfig) overload to
HazelcastSerializationFilterHelper, sharing the existing logic through a
private applyDefaultFilter(SerializationConfig), and call it on the
Camel-built branch of getOrCreateHzClientInstance().
A user-supplied ClientConfig or a pre-built HazelcastInstance is left
untouched, as established by CAMEL-23414.
The existing handlesNullConfigGracefully test now casts its argument
because the new overload makes an untyped null ambiguous.
Signed-off-by: Andrea Cosentino <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
---
.../hazelcast/HazelcastDefaultComponent.java | 1 +
.../HazelcastSerializationFilterHelper.java | 28 ++++++++++++++----
.../HazelcastSerializationFilterHelperTest.java | 34 ++++++++++++++++++++--
.../ROOT/pages/camel-4x-upgrade-guide-4_23.adoc | 4 +++
4 files changed, 59 insertions(+), 8 deletions(-)
diff --git
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultComponent.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultComponent.java
index 2a5d133cfe25..636d4af66318 100644
---
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultComponent.java
+++
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultComponent.java
@@ -217,6 +217,7 @@ public abstract class HazelcastDefaultComponent extends
DefaultComponent {
// Disable the version check
config.getProperties().setProperty("hazelcast.version.check.enabled", "false");
config.getProperties().setProperty("hazelcast.phone.home.enabled", "false");
+ HazelcastSerializationFilterHelper.applyDefault(config);
hzInstance = HazelcastClient.newHazelcastClient(config);
} else if (config != null) {
diff --git
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastSerializationFilterHelper.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastSerializationFilterHelper.java
index 536fc08ee7b9..633d3844fcaa 100644
---
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastSerializationFilterHelper.java
+++
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastSerializationFilterHelper.java
@@ -16,18 +16,19 @@
*/
package org.apache.camel.component.hazelcast;
+import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.ClassFilter;
import com.hazelcast.config.Config;
import com.hazelcast.config.JavaSerializationFilterConfig;
import com.hazelcast.config.SerializationConfig;
/**
- * Applies a default {@link JavaSerializationFilterConfig} to Hazelcast {@link
Config} instances built by Camel when the
- * user has not configured one. The default whitelists {@code java.}, {@code
javax.} and {@code org.apache.camel.} class
- * name prefixes and blacklists {@code java.net.}.
+ * Applies a default {@link JavaSerializationFilterConfig} to Hazelcast {@link
Config} and {@link ClientConfig}
+ * instances built by Camel when the user has not configured one. The default
whitelists {@code java.}, {@code javax.}
+ * and {@code org.apache.camel.} class name prefixes and blacklists {@code
java.net.}.
* <p>
- * If the supplied {@link Config} already declares a {@link
JavaSerializationFilterConfig} (e.g. provided by the user
- * via a reference or XML/YAML configuration), it is left untouched.
+ * If the supplied configuration already declares a {@link
JavaSerializationFilterConfig} (e.g. provided by the user via
+ * a reference or XML/YAML configuration), it is left untouched.
*/
public final class HazelcastSerializationFilterHelper {
@@ -46,7 +47,22 @@ public final class HazelcastSerializationFilterHelper {
if (config == null) {
return;
}
- SerializationConfig serializationConfig =
config.getSerializationConfig();
+ applyDefaultFilter(config.getSerializationConfig());
+ }
+
+ /**
+ * Applies the default {@link JavaSerializationFilterConfig} on the {@link
SerializationConfig} of the given
+ * {@link ClientConfig} when one is not already set. Has no effect when
{@code config} is {@code null} or the user
+ * has already configured a {@link JavaSerializationFilterConfig}.
+ */
+ public static void applyDefault(ClientConfig config) {
+ if (config == null) {
+ return;
+ }
+ applyDefaultFilter(config.getSerializationConfig());
+ }
+
+ private static void applyDefaultFilter(SerializationConfig
serializationConfig) {
if (serializationConfig == null) {
return;
}
diff --git
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSerializationFilterHelperTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSerializationFilterHelperTest.java
index b85167081ce7..903703604767 100644
---
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSerializationFilterHelperTest.java
+++
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSerializationFilterHelperTest.java
@@ -16,12 +16,14 @@
*/
package org.apache.camel.component.hazelcast;
+import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.ClassFilter;
import com.hazelcast.config.Config;
import com.hazelcast.config.JavaSerializationFilterConfig;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -66,8 +68,36 @@ class HazelcastSerializationFilterHelperTest {
assertTrue(actual.getWhitelist().getPrefixes().contains("com.example."));
}
+ @Test
+ void appliesDefaultToClientConfigWhenNoneConfigured() {
+ ClientConfig config = new ClientConfig();
+
assertThat(config.getSerializationConfig().getJavaSerializationFilterConfig()).isNull();
+
+ HazelcastSerializationFilterHelper.applyDefault(config);
+
+ JavaSerializationFilterConfig filter =
config.getSerializationConfig().getJavaSerializationFilterConfig();
+ assertThat(filter).isNotNull();
+ assertThat(filter.getWhitelist().getPrefixes()).contains("java.",
"javax.", "org.apache.camel.");
+ assertThat(filter.getBlacklist().getPrefixes()).contains("java.net.");
+ }
+
+ @Test
+ void respectsExistingUserConfigurationOnClientConfig() {
+ ClientConfig config = new ClientConfig();
+ JavaSerializationFilterConfig userFilter = new
JavaSerializationFilterConfig();
+ userFilter.setWhitelist(new ClassFilter().addPrefixes("com.example."));
+
config.getSerializationConfig().setJavaSerializationFilterConfig(userFilter);
+
+ HazelcastSerializationFilterHelper.applyDefault(config);
+
+
assertThat(config.getSerializationConfig().getJavaSerializationFilterConfig()).isSameAs(userFilter);
+
assertThat(userFilter.getWhitelist().getPrefixes()).containsExactly("com.example.");
+ }
+
@Test
void handlesNullConfigGracefully() {
- assertDoesNotThrow(() ->
HazelcastSerializationFilterHelper.applyDefault(null));
+ assertThatCode(() ->
HazelcastSerializationFilterHelper.applyDefault((Config)
null)).doesNotThrowAnyException();
+ assertThatCode(() ->
HazelcastSerializationFilterHelper.applyDefault((ClientConfig) null))
+ .doesNotThrowAnyException();
}
}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
index 3445aca8a37b..7de03cbc6c53 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
@@ -81,6 +81,10 @@ Applications that aggregate classes outside the default
whitelist through the re
without supplying their own `hazelcastInstance` must now provide a `Config`
with a
`JavaSerializationFilterConfig` covering their class names.
+The same default is now also applied to the `ClientConfig` that Camel builds
for `hazelcastMode=client`
+endpoints, when neither a referenced `ClientConfig` nor `hazelcastConfigUri`
is supplied. Client mode
+previously behaved differently from node mode for an otherwise identical
endpoint configuration.
+
=== camel-mail
`MimeMultipartDataFormat` now uses `MailHeaderFilterStrategy` instead of a
plain