davsclaus commented on code in PR #27817:
URL: https://github.com/apache/camel/pull/27817#discussion_r4269066434


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ToolRegistry.java:
##########
@@ -1130,45 +1150,60 @@ private static void registerExampleTools() {
                 }));
 
         register(tool("get_example_file",
-                "Get the content of a file from a bundled Camel CLI example.")
-                .param("example", "string",
-                        "Example name (e.g., timer-log, rest-api, 
circuit-breaker)", true)
-                .param("file", "string",
-                        "File name within the example (e.g., 
route.camel.yaml)", true)
-                .executor((ctx, args) -> {
-                    String example = args.get("example");
-                    String file = args.get("file");
-                    if (example == null || example.isBlank()) {
-                        throw new ToolExecutionException("example name is 
required");
-                    }
-                    if (file == null || file.isBlank()) {
-                        throw new ToolExecutionException("file name is 
required");
-                    }
-                    List<JsonObject> catalog2 = ExampleHelper.loadCatalog();
-                    JsonObject entry = ExampleHelper.findExample(catalog2, 
example);
-                    if (entry == null) {
-                        return "Example not found: " + example;
-                    }
-                    List<String> files = ExampleHelper.getFiles(entry);
-                    if (!files.contains(file)) {
-                        return "File '" + file + "' not found in example '" + 
example + "'. Available: " + files;
-                    }
-                    if (ExampleHelper.isBundled(entry)) {
-                        String resourcePath = "examples/" + example + "/" + 
file;
-                        try (InputStream is
-                                = 
ExampleHelper.class.getClassLoader().getResourceAsStream(resourcePath)) {
-                            if (is != null) {
-                                return IOHelper.loadText(is);
-                            }
-                        } catch (Exception e) {
-                            return "Error reading file: " + e.getMessage();
-                        }
-                        return "Could not read bundled file: " + resourcePath;
-                    } else {
-                        return "This example is not bundled. View it on 
GitHub: "
-                               + ExampleHelper.getGithubUrl(entry) + "/" + 
file;
-                    }
-                }));
+                "Get the content of a file from a Camel CLI example: the 
content of a bundled example, the GitHub "
+                                          + "URL of the file for the others. 
Returns the full name of the example.")
+                .param("example", "string", EXAMPLE_NAME_DESC, true)
+                .param("file", "string", EXAMPLE_FILE_DESC, true)
+                .executor((ctx, args) -> exampleFile(args.get("example"), 
args.get("file")).toJson()));
+    }
+
+    /**
+     * A file of an example: the catalog entry is found by its full or short 
name and the bundled resource is read from
+     * the entry's name, so a short name reads the file as well (CAMEL-25535).
+     */
+    static JsonObject exampleFile(String example, String file) {
+        if (example == null || example.isBlank()) {
+            throw new ToolExecutionException("example name is required");
+        }
+        if (file == null || file.isBlank()) {
+            throw new ToolExecutionException("file name is required");
+        }
+        String wanted = example.trim();
+        String fileName = file.trim();
+        List<JsonObject> catalog = ExampleHelper.loadCatalog();
+        JsonObject entry = ExampleHelper.findExample(catalog, wanted);

Review Comment:
   `findExample` takes the first entry with this short name. `Run` and 
`LaunchManager` use `ExampleHelper.findExamplesByShortName` to report an 
ambiguous short name. Worth doing the same here, so a future duplicate answers 
with the candidates rather than with a file from the wrong group.



##########
core/camel-core-engine/src/main/docs/modules/eips/pages/throwException-eip.adoc:
##########
@@ -1,7 +1,7 @@
-= Stop EIP
-:doctitle: Stop
-:shortname: stop
-:description: Stops the processing of the current message
+= Throw Exception EIP
+:doctitle: Throw Exception
+:shortname: throwException
+:description: Throws an exception

Review Comment:
   Suggest the model's description, as the other EIP pages have it:
   ```suggestion
   :description: Throws an exception during route processing, either creating a 
new exception instance or re-throwing an existing one
   ```
   (and the same line in the catalog mirror).



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