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


##########
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;

Review Comment:
   🔴 **`AtomicBoolean` idempotent shutdown guard removed**
   
   SHA `308a4e18` had:
   
   
   
   This was the direct fix for the race between `doStop()` and 
`unregisterEndpoint()` both calling `binding.shutdown()`. It has been removed. 
Without it, `provider.shutdown()` and `Files.deleteIfExists()` can be called 
concurrently from two threads — double-closing a gRPC channel or racing to 
delete the temp file.
   
   Add it back:
   
   



##########
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);

Review Comment:
   🔴 **Per-domain locking reverted**
   
   SHA `308a4e18` had per-domain locking via `domainLocks = new 
ConcurrentHashMap<String, Object>()`, so that starting endpoints on domain A 
and domain B concurrently did not contend. The new commits revert this to a 
component-level `synchronized` method.
   
   Two problems with the global lock:
   
   1. **Lock contention:** `api.setProviderAndWait()` inside this synchronized 
block is a blocking RPC call (up to `deadline` ms). All other endpoint starts 
block behind it for the entire duration.
   
   2. **Double-shutdown is not protected:** `doStop()` (line 118) iterates 
`domainBindings.values()` and calls `binding.shutdown()` outside any lock. 
`unregisterEndpoint()` is synchronized and also calls `binding.shutdown()` when 
refCount reaches zero. With a single global lock, `doStop()` cannot acquire it 
while `unregisterEndpoint()` holds it — but `doStop()` does NOT try to acquire 
the lock at all. The concurrent path is still open.
   
   Restore the per-domain locking that was in `308a4e18`:
   
   



##########
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 = "security", defaultValue = "false",
+              description = "Whether to use TLS for the remote flagd 
connection.")
+    private boolean tls;
+
+    @UriParam(label = "security",
+              description = "Path to the TLS certificate for the remote flagd 
connection.")
+    private String certPath;

Review Comment:
   🟡 **Same label issue as `tls`** — `certPath` should also use `label = 
"security"` only:
   
   



##########
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 = "security", defaultValue = "false",
+              description = "Whether to use TLS for the remote flagd 
connection.")
+    private boolean tls;

Review Comment:
   🟡 **TLS label regression — should be `security` only**
   
   Round 4 feedback (threads `PRRT_kwDOAAMl7c6qOuRt` / `PRRT_kwDOAAMl7c6qOuR1`) 
asked for `label = "security"` only. The previous SHA had `label = 
"common,security"` (partially correct). The new commits changed this to `label 
= "common"`, dropping `security` entirely. Camel convention for TLS/credential 
parameters is the `"security"` group only.
   
   



##########
components/camel-openfeature/src/test/java/org/apache/camel/component/openfeature/OpenFeatureProducerTest.java:
##########
@@ -0,0 +1,362 @@
+/*
+ * 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")
+                            // Distinct domain so the failure exercises the 
provider-lookup path

Review Comment:
   🟡 **Test domain regression — back to `shared`, not `shared-bad`**
   
   SHA `308a4e18` correctly used `openfeature:shared-bad` here (after I raised 
this in thread `PRRT_kwDOAAMl7c6qC_2s`). The new commits revert it to 
`openfeature:shared`.
   
   With both endpoints on the same domain, `acquireOrRegister()` for the bad 
endpoint hits the fast path (domain already registered → increment refCount, 
return existing client) without ever invoking `providerSupplier.get()`. So the 
test does **not** exercise the scenario its name describes — provider 
resolution failure on a new domain registration does not affect the shared 
domain. Instead, it only tests that calling `addRoutes` for an already-known 
domain and then triggering a route error does not break things.
   
   Use a distinct domain:
   
   



-- 
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