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 1daa5dba43d1 CAMEL-23946: propagate safeSearch to LangChain4j 
WebSearchRequest
1daa5dba43d1 is described below

commit 1daa5dba43d16ab9c1fcc6e377d2ccf0ab6f45e6
Author: Omar Atie <[email protected]>
AuthorDate: Tue Jul 21 00:35:23 2026 -0700

    CAMEL-23946: propagate safeSearch to LangChain4j WebSearchRequest
    
    The safeSearch endpoint option was accepted on
    LangChain4jWebSearchConfiguration but never passed to the WebSearchRequest
    builder, so configuring safeSearch=false had no effect (LangChain4j defaults
    safeSearch to true).
    
    Co-authored-by: Claude Opus 4.8 <[email protected]>
    Co-authored-by: Cursor <[email protected]>
---
 .../web/search/LangChain4jWebSearchProducer.java   |  1 +
 .../search/LangChain4jWebSearchSafeSearchTest.java | 99 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_22.adoc    |  7 ++
 3 files changed, 107 insertions(+)

diff --git 
a/components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java
 
b/components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java
index 10d9242b3ddb..d226ca247822 100644
--- 
a/components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java
+++ 
b/components/camel-ai/camel-langchain4j-web-search/src/main/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchProducer.java
@@ -55,6 +55,7 @@ public class LangChain4jWebSearchProducer extends 
DefaultProducer {
                     
.geoLocation(getEndpoint().getConfiguration().getGeoLocation())
                     .startPage(getEndpoint().getConfiguration().getStartPage())
                     
.startIndex(getEndpoint().getConfiguration().getStartIndex())
+                    
.safeSearch(getEndpoint().getConfiguration().getSafeSearch())
                     
.additionalParams(getEndpoint().getConfiguration().getAdditionalParams())
                     .build();
         }
diff --git 
a/components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchSafeSearchTest.java
 
b/components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchSafeSearchTest.java
new file mode 100644
index 000000000000..9c4d861e0e84
--- /dev/null
+++ 
b/components/camel-ai/camel-langchain4j-web-search/src/test/java/org/apache/camel/component/langchain4j/web/search/LangChain4jWebSearchSafeSearchTest.java
@@ -0,0 +1,99 @@
+/*
+ * 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.langchain4j.web.search;
+
+import java.net.URI;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import dev.langchain4j.web.search.WebSearchEngine;
+import dev.langchain4j.web.search.WebSearchInformationResult;
+import dev.langchain4j.web.search.WebSearchOrganicResult;
+import dev.langchain4j.web.search.WebSearchRequest;
+import dev.langchain4j.web.search.WebSearchResults;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class LangChain4jWebSearchSafeSearchTest extends CamelTestSupport {
+
+    private final AtomicReference<WebSearchRequest> capturedRequest = new 
AtomicReference<>();
+
+    private final WebSearchEngine capturingEngine = request -> {
+        capturedRequest.set(request);
+        return WebSearchResults.from(
+                WebSearchInformationResult.from(1L),
+                List.of(WebSearchOrganicResult.from(
+                        "Title", URI.create("https://example.com";), "snippet", 
"content")));
+    };
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        context.getRegistry().bind("capturingEngine", capturingEngine);
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:search-false")
+                        
.to("langchain4j-web-search:test?webSearchEngine=#capturingEngine&safeSearch=false");
+
+                from("direct:search-true")
+                        
.to("langchain4j-web-search:test?webSearchEngine=#capturingEngine&safeSearch=true");
+
+                from("direct:search-with-params")
+                        
.to("langchain4j-web-search:test?webSearchEngine=#capturingEngine&safeSearch=false"
+                            + "&maxResults=3&language=en&geoLocation=US");
+            }
+        };
+    }
+
+    @Test
+    void safeSearchFalseIsPropagatedToWebSearchRequest() {
+        template.sendBody("direct:search-false", "apache camel");
+
+        WebSearchRequest request = capturedRequest.get();
+        assertNotNull(request);
+        assertFalse(request.safeSearch(), "safeSearch=false must be propagated 
to the WebSearchRequest");
+        assertEquals("apache camel", request.searchTerms());
+    }
+
+    @Test
+    void safeSearchTrueIsPropagatedToWebSearchRequest() {
+        template.sendBody("direct:search-true", "apache camel");
+
+        WebSearchRequest request = capturedRequest.get();
+        assertNotNull(request);
+        assertTrue(request.safeSearch(), "safeSearch=true must be propagated 
to the WebSearchRequest");
+    }
+
+    @Test
+    void safeSearchIsPropagatedAlongsideOtherRequestParameters() {
+        template.sendBody("direct:search-with-params", "apache camel");
+
+        WebSearchRequest request = capturedRequest.get();
+        assertNotNull(request);
+        assertFalse(request.safeSearch());
+        assertEquals(3, request.maxResults());
+        assertEquals("en", request.language());
+        assertEquals("US", request.geoLocation());
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
index 5013105a3376..bc8d96dacf41 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
@@ -188,6 +188,13 @@ They were not wired into the component; the `chatModel` is 
autowired instead.
 
 If you used these helpers directly, configure your `ChatModel` with 
LangChain4j's own builders or Spring Boot starters
 and inject it into the component.
+
+=== camel-langchain4j-web-search
+
+The `safeSearch` endpoint option is now correctly propagated to the 
LangChain4j `WebSearchRequest`.
+Previously the option was accepted on the endpoint but ignored, so 
`safeSearch=false` still sent
+`safeSearch=true` to the search engine (the LangChain4j default).
+
 === camel-openai
 
 The `conversationMemory` feature on the `chat-completion` operation has two 
behavior fixes:

Reply via email to