gnodet-bot commented on code in PR #27440:
URL: https://github.com/apache/camel/pull/27440#discussion_r4215635129


##########
components/camel-openfeature/src/main/java/org/apache/camel/component/openfeature/OpenFeatureConfiguration.java:
##########
@@ -0,0 +1,235 @@
+/*
+ * 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.openfeature;
+
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@UriParams
+public class OpenFeatureConfiguration implements Cloneable {
+
+    @UriParam(label = "common",
+              description = "The feature flag key to evaluate. Can be 
overridden per message via the CamelOpenFeatureFlagKey header.")
+    private String flagKey;
+
+    @UriParam(label = "common", defaultValue = "false",
+              description = "Default value when flag evaluation fails. When 
evaluationType is not set,"
+                            + " also determines the evaluation type: \"true\" 
or \"false\" (case-insensitive)"
+                            + " selects boolean evaluation, any other value 
selects string evaluation.")
+    private String defaultValue = "false";
+
+    @UriParam(label = "common", enums = "boolean,variant,isEnabled",
+              description = "The evaluation type. 'boolean' and 'isEnabled' 
use boolean evaluation (getBooleanValue)."
+                            + " 'variant' uses string evaluation 
(getStringValue)."
+                            + " When not set, the type is inferred from 
defaultValue."
+                            + " Can also be set as a path parameter in the 
endpoint URI, which takes precedence.")
+    private String evaluationType;
+
+    @UriParam(label = "producer",
+              description = "Store the evaluation result in this exchange 
property, preserving the original message body.")
+    private String resultProperty;
+
+    @UriParam(label = "common", description = "Remote flagd service host. When 
set, the flagd RPC resolver is used.")
+    private String host;
+
+    @UriParam(label = "common", defaultValue = "8013", description = "Remote 
flagd service port.")
+    private int port = 8013;
+
+    @UriParam(label = "common,security", defaultValue = "false",
+              description = "Whether to use TLS for the remote flagd 
connection.")
+    private boolean tls;
+
+    @UriParam(label = "common,security",
+              description = "Path to the TLS certificate for the remote flagd 
connection.")
+    private String certPath;
+
+    @UriParam(label = "common", defaultValue = "500",

Review Comment:
   💡 **Label convention: `"security"` only, not `"common,security"`**
   
   Camel convention for TLS/credential parameters is `label = "security"`. The 
`"common"` group is for parameters that are both commonly used and belong in 
the "common" UI tab — security params like `tls` and `certPath` should appear 
under `"security"` only.
   
   ```suggestion
       @UriParam(label = "security", defaultValue = "false",
                 description = "Whether to use TLS for the remote flagd 
connection.")
   ```



##########
components/camel-openfeature/src/main/java/org/apache/camel/component/openfeature/OpenFeatureComponent.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.openfeature;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import dev.openfeature.sdk.Client;
+import dev.openfeature.sdk.FeatureProvider;
+import dev.openfeature.sdk.OpenFeatureAPI;
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.Component;
+import org.apache.camel.support.DefaultComponent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component("openfeature")
+public class OpenFeatureComponent extends DefaultComponent {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(OpenFeatureComponent.class);
+
+    @Metadata
+    private OpenFeatureConfiguration configuration = new 
OpenFeatureConfiguration();
+
+    private volatile OpenFeatureAPI api;
+    private final Map<String, DomainBinding> domainBindings = new 
ConcurrentHashMap<>();
+    private final ConcurrentHashMap<String, Object> domainLocks = new 
ConcurrentHashMap<>();
+
+    private static class DomainBinding {
+        final FeatureProvider provider;
+        final boolean owned;
+        int refCount;
+        File tempFlagFile;
+        private final AtomicBoolean shutdownCalled = new AtomicBoolean();
+
+        DomainBinding(FeatureProvider provider, boolean owned) {
+            this.provider = provider;
+            this.owned = owned;
+            this.refCount = 1;
+        }
+
+        void shutdown() {
+            if (!shutdownCalled.compareAndSet(false, true)) {
+                return;
+            }
+            if (owned) {
+                try {
+                    provider.shutdown();
+                } catch (Exception e) {
+                    LOG.debug("Error shutting down owned provider: {}", 
e.getMessage(), e);
+                }
+            }
+
+            if (tempFlagFile != null) {
+                try {
+                    Files.deleteIfExists(tempFlagFile.toPath());
+                } catch (IOException e) {
+                    LOG.debug("Error deleting temp flag file: {}", 
e.getMessage(), e);
+                }
+                tempFlagFile = null;
+            }
+        }
+    }
+
+    static class ProviderRegistration {
+        final FeatureProvider provider;
+        final boolean owned;
+        File tempFlagFile;
+
+        ProviderRegistration(FeatureProvider provider, boolean owned) {
+            this.provider = provider;
+            this.owned = owned;
+        }
+    }
+
+    @FunctionalInterface
+    interface ProviderSupplier {
+        ProviderRegistration get() throws Exception;
+    }
+
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {
+        String domain = remaining;
+        String evaluationType = null;
+        int idx = remaining.indexOf('/');
+        if (idx >= 0) {
+            domain = remaining.substring(0, idx);
+            String pathValue = remaining.substring(idx + 1);
+            if (!pathValue.isBlank()) {
+                evaluationType = pathValue;
+            }
+        }
+        OpenFeatureEndpoint endpoint = new OpenFeatureEndpoint(uri, this, 
domain, evaluationType, configuration.copy());
+        setProperties(endpoint, parameters);
+        return endpoint;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        api = OpenFeatureAPI.createIsolated();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        OpenFeatureAPI localApi = api;
+        api = null;
+        for (DomainBinding binding : domainBindings.values()) {
+            binding.shutdown();
+        }
+        domainBindings.clear();
+        if (localApi != null) {
+            try {
+                localApi.shutdown();
+            } catch (Exception e) {
+                LOG.debug("Error shutting down OpenFeature API: {}", 
e.getMessage(), e);
+            }
+        }
+        super.doStop();
+    }
+
+    Client acquireOrRegister(String domain, ProviderSupplier providerSupplier) 
throws Exception {
+        Object lock = domainLocks.computeIfAbsent(domain, k -> new Object());
+        synchronized (lock) {
+            DomainBinding existing = domainBindings.get(domain);
+            if (existing != null) {
+                existing.refCount++;
+                return api.getClient(domain);
+            }
+
+            ProviderRegistration reg = providerSupplier.get();
+            try {
+                api.setProviderAndWait(domain, reg.provider);
+            } catch (Exception e) {
+                if (reg.owned) {
+                    try {
+                        reg.provider.shutdown();
+                    } catch (Exception suppressed) {
+                        e.addSuppressed(suppressed);
+                    }
+                }
+                if (reg.tempFlagFile != null) {
+                    try {
+                        Files.deleteIfExists(reg.tempFlagFile.toPath());
+                    } catch (IOException suppressed) {
+                        e.addSuppressed(suppressed);
+                    }
+                }
+                throw e;
+            }
+            DomainBinding binding = new DomainBinding(reg.provider, reg.owned);
+            binding.tempFlagFile = reg.tempFlagFile;
+            domainBindings.put(domain, binding);
+            return api.getClient(domain);
+        }
+    }
+
+    void unregisterEndpoint(String domain) {
+        Object lock = domainLocks.computeIfAbsent(domain, k -> new Object());
+        synchronized (lock) {
+            DomainBinding binding = domainBindings.get(domain);
+            if (binding != null) {
+                binding.refCount--;
+                if (binding.refCount <= 0) {
+                    domainBindings.remove(domain);
+                    domainLocks.remove(domain);

Review Comment:
   ⚠️ **Race condition: lock invalidated before `shutdown()` completes**
   
   `domainLocks.remove(domain)` is called while still holding `lock`. A 
concurrent `acquireOrRegister()` call at this point will `computeIfAbsent` a 
**new** lock object (the old one is gone), acquire it immediately, and proceed 
to register a new provider concurrently with `binding.shutdown()` still running.
   
   Fix: defer `domainLocks.remove(domain)` until **after** 
`binding.shutdown()`, so the lock remains valid for the full duration of 
shutdown:
   
   ```suggestion
                       domainBindings.remove(domain);
                       binding.shutdown();
                       domainLocks.remove(domain);
   ```



##########
components/camel-openfeature/src/main/java/org/apache/camel/component/openfeature/OpenFeatureConfiguration.java:
##########
@@ -0,0 +1,235 @@
+/*
+ * 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.openfeature;
+
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@UriParams
+public class OpenFeatureConfiguration implements Cloneable {
+
+    @UriParam(label = "common",
+              description = "The feature flag key to evaluate. Can be 
overridden per message via the CamelOpenFeatureFlagKey header.")
+    private String flagKey;
+
+    @UriParam(label = "common", defaultValue = "false",
+              description = "Default value when flag evaluation fails. When 
evaluationType is not set,"
+                            + " also determines the evaluation type: \"true\" 
or \"false\" (case-insensitive)"
+                            + " selects boolean evaluation, any other value 
selects string evaluation.")
+    private String defaultValue = "false";
+
+    @UriParam(label = "common", enums = "boolean,variant,isEnabled",
+              description = "The evaluation type. 'boolean' and 'isEnabled' 
use boolean evaluation (getBooleanValue)."
+                            + " 'variant' uses string evaluation 
(getStringValue)."
+                            + " When not set, the type is inferred from 
defaultValue."
+                            + " Can also be set as a path parameter in the 
endpoint URI, which takes precedence.")
+    private String evaluationType;
+
+    @UriParam(label = "producer",
+              description = "Store the evaluation result in this exchange 
property, preserving the original message body.")
+    private String resultProperty;
+
+    @UriParam(label = "common", description = "Remote flagd service host. When 
set, the flagd RPC resolver is used.")
+    private String host;
+
+    @UriParam(label = "common", defaultValue = "8013", description = "Remote 
flagd service port.")
+    private int port = 8013;
+
+    @UriParam(label = "common,security", defaultValue = "false",
+              description = "Whether to use TLS for the remote flagd 
connection.")
+    private boolean tls;
+
+    @UriParam(label = "common,security",
+              description = "Path to the TLS certificate for the remote flagd 
connection.")
+    private String certPath;
+
+    @UriParam(label = "common", defaultValue = "500",
+              description = "Deadline in milliseconds for the remote flagd 
connection.")
+    private int deadline = 500;
+
+    @UriParam(label = "common",

Review Comment:
   💡 **Same label convention issue as `tls`** — use `label = "security"` only:
   
   ```suggestion
       @UriParam(label = "security",
                 description = "Path to the TLS certificate for the remote 
flagd connection.")
   ```



##########
components/camel-openfeature/src/test/java/org/apache/camel/component/openfeature/OpenFeatureProducerTest.java:
##########
@@ -0,0 +1,361 @@
+/*
+ * 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.openfeature;
+
+import java.util.List;
+import java.util.Map;
+
+import dev.openfeature.sdk.MutableContext;
+import dev.openfeature.sdk.Value;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class OpenFeatureProducerTest extends CamelTestSupport {
+
+    private static final String FLAGS_RESOURCE = 
"classpath:openfeature/flags.json";
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:boolean-flag")
+                        
.to("openfeature:test?flagKey=enrichment-enabled&flagsResource=" + 
FLAGS_RESOURCE);
+
+                from("direct:disabled-flag")
+                        
.to("openfeature:test-disabled?flagKey=disabled-flag&flagsResource=" + 
FLAGS_RESOURCE);
+
+                from("direct:string-flag")
+                        
.to("openfeature:test-string?flagKey=new-routing-algorithm&defaultValue=unknown&flagsResource="
+                            + FLAGS_RESOURCE);
+
+                from("direct:result-property")
+                        
.to("openfeature:test-prop?flagKey=enrichment-enabled&resultProperty=flagResult&flagsResource="
+                            + FLAGS_RESOURCE);
+
+                from("direct:targeted-flag")
+                        
.to("openfeature:test-targeted?flagKey=hazmat-compliance-v2&defaultValue=v1&flagsResource="
+                            + FLAGS_RESOURCE
+                            + "&contextFromBody=true");
+
+                from("direct:variant-type")
+                        
.to("openfeature:test-variant/variant?flagKey=new-routing-algorithm&flagsResource="
+                            + FLAGS_RESOURCE);
+
+                from("direct:boolean-type-explicit")
+                        
.to("openfeature:test-bool-type/boolean?flagKey=enrichment-enabled&flagsResource="
+                            + FLAGS_RESOURCE);
+
+                from("direct:is-enabled")
+                        
.to("openfeature:test-is-enabled/isEnabled?flagKey=enrichment-enabled&flagsResource="
+                            + FLAGS_RESOURCE);
+
+                from("direct:targeted-boolean")
+                        
.to("openfeature:test-targeted-bool?flagKey=targeted-boolean&flagsResource="
+                            + FLAGS_RESOURCE
+                            + "&contextFromBody=true");
+
+                from("direct:targeted-boolean-header")
+                        
.to("openfeature:test-targeted-bool-hdr?flagKey=targeted-boolean&flagsResource="
+                            + FLAGS_RESOURCE);
+            }
+        };
+    }
+
+    @Test
+    void testBooleanFlagEvaluationTrue() {
+        Object result = template.requestBody("direct:boolean-flag", "ignored");
+        assertThat(result).isEqualTo(true);
+    }
+
+    @Test
+    void testDisabledFlagReturnsDefault() {
+        Object result = template.requestBody("direct:disabled-flag", 
"ignored");
+        assertThat(result).isEqualTo(false);
+    }
+
+    @Test
+    void testStringFlagEvaluation() {
+        Object result = template.requestBody("direct:string-flag", "ignored");
+        assertThat(result).isEqualTo("content-based-router");
+    }
+
+    @Test
+    void testResultPropertyPreservesBody() {
+        Exchange exchange = template.request("direct:result-property", e -> 
e.getMessage().setBody("original"));
+        
assertThat(exchange.getMessage().getBody(String.class)).isEqualTo("original");
+        assertThat(exchange.getProperty("flagResult")).isEqualTo(true);
+    }
+
+    @Test
+    void testEvaluationContextTargetedEnterprise() {
+        Object result = template.requestBody("direct:targeted-flag",
+                Map.of("targetingKey", "order-123", "customer_tier", 
"ENTERPRISE"));
+        assertThat(result).isEqualTo("v2");
+    }
+
+    @Test
+    void testEvaluationContextTargetedVip() {
+        Object result = template.requestBody("direct:targeted-flag",
+                Map.of("targetingKey", "order-456", "customer_tier", "VIP"));
+        assertThat(result).isEqualTo("v2");
+    }
+
+    @Test
+    void testEvaluationContextTargetedStandard() {
+        Object result = template.requestBody("direct:targeted-flag",
+                Map.of("targetingKey", "order-789", "customer_tier", 
"STANDARD"));
+        assertThat(result).isEqualTo("v1");
+    }
+
+    @Test
+    void testFlagKeyHeaderOverride() {
+        Object result = template.requestBodyAndHeader(
+                "direct:boolean-flag", "ignored",
+                OpenFeatureConstants.FLAG_KEY, "disabled-flag");
+        assertThat(result).isEqualTo(false);
+    }
+
+    @Test
+    void testTargetingKeyHeader() {
+        Exchange exchange = template.request("direct:targeted-flag", e -> {
+            e.getMessage().setBody(Map.of("customer_tier", "ENTERPRISE"));
+            e.getMessage().setHeader(OpenFeatureConstants.TARGETING_KEY, 
"order-header-123");
+        });
+        assertThat(exchange.getMessage().getBody()).isEqualTo("v2");
+    }
+
+    @Test
+    void testTargetingKeyProperty() {
+        Exchange exchange = template.request("direct:targeted-flag", e -> {
+            e.getMessage().setBody(Map.of("customer_tier", "VIP"));
+            e.setProperty(OpenFeatureConstants.TARGETING_KEY, 
"order-prop-456");
+        });
+        assertThat(exchange.getMessage().getBody()).isEqualTo("v2");
+    }
+
+    @Test
+    void testContextHeader() {
+        Exchange exchange = template.request("direct:targeted-flag", e -> {
+            e.getMessage().setBody("ignored");
+            e.getMessage().setHeader(OpenFeatureConstants.EVALUATION_CONTEXT,
+                    Map.of("targetingKey", "order-ctx-789", "customer_tier", 
"ENTERPRISE"));
+        });
+        assertThat(exchange.getMessage().getBody()).isEqualTo("v2");
+    }
+
+    @Test
+    void testContextHeaderOverridesBody() {
+        Exchange exchange = template.request("direct:targeted-flag", e -> {
+            e.getMessage().setBody(Map.of("targetingKey", "order-body", 
"customer_tier", "STANDARD"));
+            e.getMessage().setHeader(OpenFeatureConstants.EVALUATION_CONTEXT,
+                    Map.of("customer_tier", "ENTERPRISE"));
+        });
+        assertThat(exchange.getMessage().getBody()).isEqualTo("v2");
+    }
+
+    @Test
+    void testVariantEvaluationTypeWithDefaultDefaultValue() {
+        Object result = template.requestBody("direct:variant-type", "ignored");
+        assertThat(result).isEqualTo("content-based-router");
+    }
+
+    @Test
+    void testExplicitBooleanEvaluationType() {
+        Object result = template.requestBody("direct:boolean-type-explicit", 
"ignored");
+        assertThat(result).isEqualTo(true);
+    }
+
+    @Test
+    void testIsEnabledEvaluationType() {
+        Object result = template.requestBody("direct:is-enabled", "ignored");
+        assertThat(result).isInstanceOf(Boolean.class);
+        assertThat(result).isEqualTo(true);
+    }
+
+    @Test
+    void testIsEnabledDisabledFlag() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:is-enabled-disabled")
+                        
.to("openfeature:test-is-enabled-off/isEnabled?flagKey=disabled-flag&flagsResource="
+                            + FLAGS_RESOURCE);
+            }
+        });
+        Object result = template.requestBody("direct:is-enabled-disabled", 
"ignored");
+        assertThat(result).isInstanceOf(Boolean.class);
+        assertThat(result).isEqualTo(false);
+    }
+
+    @Test
+    void testInlineFlags() throws Exception {
+        String inlineFlags = """
+                
{"flags":{"inline-flag":{"state":"ENABLED","variants":{"on":true,"off":false},"defaultVariant":"on"}}}""";
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:inline-flag")
+                        
.to("openfeature:test-inline?flagKey=inline-flag&flags=" + inlineFlags);
+            }
+        });
+        Object result = template.requestBody("direct:inline-flag", "ignored");
+        assertThat(result).isEqualTo(true);
+    }
+
+    @Test
+    void testBooleanFlagWithTargetingKeyReturnsBooleanNotString() {
+        Exchange exchange = template.request("direct:targeted-boolean", e -> {
+            e.getMessage().setBody(Map.of("customer_tier", "ENTERPRISE"));
+            e.getMessage().setHeader(OpenFeatureConstants.TARGETING_KEY, 
"user-123");
+        });
+        Object result = exchange.getMessage().getBody();
+        assertThat(result).isInstanceOf(Boolean.class);
+        assertThat(result).isEqualTo(true);
+    }
+
+    @Test
+    void testBooleanFlagWithTargetingKeyDefaultVariant() {
+        Exchange exchange = template.request("direct:targeted-boolean", e -> {
+            e.getMessage().setBody(Map.of("customer_tier", "STANDARD"));
+            e.getMessage().setHeader(OpenFeatureConstants.TARGETING_KEY, 
"user-456");
+        });
+        Object result = exchange.getMessage().getBody();
+        assertThat(result).isInstanceOf(Boolean.class);
+        assertThat(result).isEqualTo(false);
+    }
+
+    @Test
+    void testBooleanFlagWithMapBodyReturnsBoolean() {
+        Object result = template.requestBody("direct:targeted-boolean",
+                Map.of("targetingKey", "user-789", "customer_tier", "VIP"));
+        assertThat(result).isInstanceOf(Boolean.class);
+        assertThat(result).isEqualTo(true);
+    }
+
+    @Test
+    void testMapBodyNotUsedAsContextByDefault() {
+        Object result = template.requestBody("direct:targeted-boolean-header",
+                Map.of("targetingKey", "user-789", "customer_tier", 
"ENTERPRISE"));
+        assertThat(result).isInstanceOf(Boolean.class);
+        assertThat(result).isEqualTo(false);
+    }
+
+    @Test
+    void testEvaluationDetailsHeaders() {
+        Exchange exchange = template.request("direct:boolean-flag", e -> 
e.getMessage().setBody("ignored"));
+        
assertThat(exchange.getMessage().getHeader(OpenFeatureConstants.EVALUATION_VARIANT,
 String.class))
+                .isNotNull();
+        
assertThat(exchange.getMessage().getHeader(OpenFeatureConstants.EVALUATION_REASON,
 String.class))
+                .isNotNull();
+        
assertThat(exchange.getMessage().getHeader(OpenFeatureConstants.EVALUATION_ERROR_CODE))
+                .isNull();
+    }
+
+    @Test
+    void testStaleErrorHeaderClearedOnSuccess() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:stale-header-test")
+                        
.to("openfeature:test-stale?flagKey=enrichment-enabled&flagsResource=" + 
FLAGS_RESOURCE);
+            }
+        });
+
+        Exchange exchange = template.request("direct:stale-header-test", e -> {
+            e.getMessage().setBody("ignored");
+            
e.getMessage().setHeader(OpenFeatureConstants.EVALUATION_ERROR_CODE, 
"FLAG_NOT_FOUND");
+        });
+        assertThat(exchange.getMessage().getBody()).isEqualTo(true);
+        
assertThat(exchange.getMessage().getHeader(OpenFeatureConstants.EVALUATION_ERROR_CODE)).isNull();
+    }
+
+    @Test
+    void testToValuePreservesLargeLong() {
+        long largeLong = Long.MAX_VALUE;
+        MutableContext ctx = OpenFeatureEndpoint.buildMutableContext(
+                "user-1", Map.of("signupTs", largeLong));
+        Value value = ctx.getValue("signupTs");
+        assertThat(value).isNotNull();
+        assertThat(value.asLong()).isEqualTo(largeLong);
+    }
+
+    @Test
+    void testToValueHandlesFloat() {
+        MutableContext ctx = OpenFeatureEndpoint.buildMutableContext(
+                "user-1", Map.of("score", 3.14f));
+        Value value = ctx.getValue("score");
+        assertThat(value).isNotNull();
+        assertThat(value.asDouble()).isCloseTo(3.14, 
org.assertj.core.data.Offset.offset(0.01));
+    }
+
+    @Test
+    void testToValueHandlesNestedMap() {
+        Map<String, Object> nested = Map.of("city", "Berlin", "zip", 10115);
+        MutableContext ctx = OpenFeatureEndpoint.buildMutableContext(
+                "user-1", Map.of("address", nested));
+        Value value = ctx.getValue("address");
+        assertThat(value).isNotNull();
+        assertThat(value.isStructure()).isTrue();
+        
assertThat(value.asStructure().getValue("city").asString()).isEqualTo("Berlin");
+        
assertThat(value.asStructure().getValue("zip").asInteger()).isEqualTo(10115);
+    }
+
+    @Test
+    void testToValueHandlesList() {
+        MutableContext ctx = OpenFeatureEndpoint.buildMutableContext(
+                "user-1", Map.of("tags", List.of("premium", "beta")));
+        Value value = ctx.getValue("tags");
+        assertThat(value).isNotNull();
+        assertThat(value.isList()).isTrue();
+        assertThat(value.asList()).hasSize(2);
+        assertThat(value.asList().get(0).asString()).isEqualTo("premium");
+    }
+
+    @Test
+    void testFailedEndpointStartDoesNotAffectSharedDomain() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:shared-domain")
+                        
.to("openfeature:shared?flagKey=enrichment-enabled&flagsResource=" + 
FLAGS_RESOURCE);
+            }
+        });
+
+        Object result = template.requestBody("direct:shared-domain", 
"ignored");
+        assertThat(result).isEqualTo(true);
+
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() {
+                    from("direct:bad-endpoint")
+                            
.to("openfeature:shared-bad?flagKey=enrichment-enabled&provider=#nonexistent");

Review Comment:
   💡 **Add a brief comment explaining why a distinct domain is used here**
   
   The name `shared-bad` is not self-evident. A one-liner clarifies the intent 
— that a *different* domain from the shared one is intentional, to isolate the 
failure:
   
   ```suggestion
                       from("direct:bad-endpoint")
                               // Use a distinct domain so the failure doesn't 
pollute the shared one
                               
.to("openfeature:shared-bad?flagKey=enrichment-enabled&provider=#nonexistent");
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to