From 211aba702f234a6826e394f14196d54948f485a8 Mon Sep 17 00:00:00 2001 From: croway Date: Thu, 3 Sep 2026 19:24:02 +0200 Subject: [PATCH] Fix docling example metadata extraction writing invalid JSON The document-metadata-extractor route used docling:EXTRACT_STRUCTURED_DATA as the endpoint URI path, but camel-docling only dispatches on the "operation" query parameter (or the CamelDoclingOperation header) - the URI path segment is descriptive only. Without it, the endpoint silently fell back to its CONVERT_TO_MARKDOWN default, so the "metadata" route was actually just converting to markdown and writing it into a .json file. Also add the missing operation query parameter, and marshal the DoclingDocument result to JSON explicitly (EXTRACT_STRUCTURED_DATA returns a structured object, not JSON text, and camel-docling has no built-in type converter for it), via camel-jackson. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Hs6c6LpuL8ZZ3gaSXwt7CS --- docling/pom.xml | 4 ++++ .../camel/example/springboot/docling/DoclingServeRoute.java | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docling/pom.xml b/docling/pom.xml index d38db59f7..f6ce0648c 100644 --- a/docling/pom.xml +++ b/docling/pom.xml @@ -79,6 +79,10 @@ org.apache.camel.springboot camel-file-starter + + org.apache.camel.springboot + camel-jackson-starter + diff --git a/docling/src/main/java/org/apache/camel/example/springboot/docling/DoclingServeRoute.java b/docling/src/main/java/org/apache/camel/example/springboot/docling/DoclingServeRoute.java index bfa27ab7a..569aaec1e 100644 --- a/docling/src/main/java/org/apache/camel/example/springboot/docling/DoclingServeRoute.java +++ b/docling/src/main/java/org/apache/camel/example/springboot/docling/DoclingServeRoute.java @@ -17,6 +17,7 @@ package org.apache.camel.example.springboot.docling; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.dataformat.JsonLibrary; import org.springframework.stereotype.Component; @Component @@ -28,7 +29,7 @@ public void configure() throws Exception { from("file:{{documents.directory}}?delete=true&include=.*\\.(pdf|docx|pptx|html|md)$") .routeId("document-to-markdown-converter") .log("Processing document: ${header.CamelFileName}") - .to("docling:CONVERT_TO_MARKDOWN?useDoclingServe=true&doclingServeUrl={{docling.serve.url}}&contentInBody=true") + .to("docling:convert-to-markdown?operation=CONVERT_TO_MARKDOWN&useDoclingServe=true&doclingServeUrl={{docling.serve.url}}&contentInBody=true") .log("Document converted to Markdown: ${header.CamelFileName}") .setHeader("CamelFileName", simple("${file:name.noext}.md")) .to("file:{{output.directory}}") @@ -37,7 +38,8 @@ public void configure() throws Exception { from("file:{{documents.directory}}/extract?delete=true&include=.*\\.(pdf|docx|pptx)$") .routeId("document-metadata-extractor") .log("Extracting metadata from: ${header.CamelFileName}") - .to("docling:EXTRACT_STRUCTURED_DATA?useDoclingServe=true&doclingServeUrl={{docling.serve.url}}&outputFormat=json&contentInBody=true") + .to("docling:extract-structured-data?operation=EXTRACT_STRUCTURED_DATA&useDoclingServe=true&doclingServeUrl={{docling.serve.url}}&contentInBody=true") + .marshal().json(JsonLibrary.Jackson) .log("Metadata extracted from: ${header.CamelFileName}") .setHeader("CamelFileName", simple("${file:name.noext}.json")) .to("file:{{output.directory}}/metadata")