This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27202-docling-ocr-language in repository https://gitbox.apache.org/repos/asf/camel.git
commit 29a4a1561bbb844fb9987a0a3af53393ee665381 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Nov 24 16:47:09 2026 +0100 CAMEL-27202: camel-docling - send the ocrLanguage option to docling-serve With docling-serve, the ocrLanguage option was only sent when doOcr=true was set, as its default (en) could not be told apart from a configured language. The option has no default now: when it is set, the request has do_ocr=true and the language, as with the CamelDoclingOCRLanguage header, unless enableOCR or doOcr is false. The docling CLI still uses en when no language is set. In sync mode, the "Task result not found" answer of docling-serve now says that the conversion failed on the server, and points to the server log or useAsyncMode=true for the error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../apache/camel/catalog/components/docling.json | 8 +- .../camel/catalog/docs/docling-component.adoc | 8 +- .../apache/camel/component/docling/docling.json | 8 +- .../src/main/docs/docling-component.adoc | 8 +- .../component/docling/DoclingConfiguration.java | 8 +- .../camel/component/docling/DoclingProducer.java | 67 +++++++++++-- .../component/docling/DoclingOcrHeadersTest.java | 65 ++++++++++++ .../docling/DoclingServeSyncFailureTest.java | 109 +++++++++++++++++++++ .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 11 +++ .../dsl/DoclingComponentBuilderFactory.java | 13 +-- .../dsl/DoclingEndpointBuilderFactory.java | 54 +++++----- 11 files changed, 306 insertions(+), 53 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/docling.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/docling.json index 2df8ad2ce3dd..d23ec0f285a5 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/docling.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/docling.json @@ -29,7 +29,7 @@ "doclingServeUrl": { "index": 2, "kind": "property", "displayName": "Docling Serve Url", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "http:\/\/localhost:5001", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Docling-serve API URL (e.g., http:\/\/localhost:5001)" }, "enableOCR": { "index": 3, "kind": "property", "displayName": "Enable OCR", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing for scanned documents" }, "includeLayoutInfo": { "index": 4, "kind": "property", "displayName": "Include Layout Info", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Show layout information with bounding boxes" }, - "ocrLanguage": { "index": 5, "kind": "property", "displayName": "Ocr Language", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "en", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Language code for OCR processing" }, + "ocrLanguage": { "index": 5, "kind": "property", "displayName": "Ocr Language", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Language code for OCR processing. With the docling CLI, en is used when it is not set. With docling-serve, settin [...] "operation": { "index": 6, "kind": "property", "displayName": "Operation", "group": "common", "label": "", "required": true, "type": "enum", "javaType": "org.apache.camel.component.docling.DoclingOperations", "enum": [ "CONVERT_TO_MARKDOWN", "CONVERT_TO_HTML", "CONVERT_TO_JSON", "EXTRACT_TEXT", "EXTRACT_STRUCTURED_DATA", "SUBMIT_ASYNC_CONVERSION", "CHECK_CONVERSION_STATUS", "BATCH_CONVERT_TO_MARKDOWN", "BATCH_CONVERT_TO_HTML", "BATCH_CONVERT_TO_JSON", "BATCH_EXTRACT_TEXT", "BATCH_EXT [...] "outputFormat": { "index": 7, "kind": "property", "displayName": "Output Format", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "markdown", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Output format of the SUBMIT_ASYNC_CONVERSION operation; the other operations always [...] "useDoclingServe": { "index": 8, "kind": "property", "displayName": "Use Docling Serve", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Use docling-serve API instead of CLI command" }, @@ -44,7 +44,7 @@ "doCodeEnrichment": { "index": 17, "kind": "property", "displayName": "Do Code Enrichment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable code enrichment in document processing" }, "documentTimeout": { "index": 18, "kind": "property", "displayName": "Document Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Document processing timeout in seconds" }, "doFormulaEnrichment": { "index": 19, "kind": "property", "displayName": "Do Formula Enrichment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable formula enrichment in document processing" }, - "doOcr": { "index": 20, "kind": "property", "displayName": "Do Ocr", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing in docling-serve API mode. When not set, the server uses its own defaults. Set enableOCR t [...] + "doOcr": { "index": 20, "kind": "property", "displayName": "Do Ocr", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing in docling-serve API mode. When not set, OCR is turned on if ocrLanguage is set, and other [...] "doPictureClassification": { "index": 21, "kind": "property", "displayName": "Do Picture Classification", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable picture classification in document processing" }, "doPictureDescription": { "index": 22, "kind": "property", "displayName": "Do Picture Description", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable picture description generation in document processing" }, "doTableStructure": { "index": 23, "kind": "property", "displayName": "Do Table Structure", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable table structure recognition" }, @@ -132,7 +132,7 @@ "doclingServeUrl": { "index": 2, "kind": "parameter", "displayName": "Docling Serve Url", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "http:\/\/localhost:5001", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Docling-serve API URL (e.g., http:\/\/localhost:5001)" }, "enableOCR": { "index": 3, "kind": "parameter", "displayName": "Enable OCR", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing for scanned documents" }, "includeLayoutInfo": { "index": 4, "kind": "parameter", "displayName": "Include Layout Info", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Show layout information with bounding boxes" }, - "ocrLanguage": { "index": 5, "kind": "parameter", "displayName": "Ocr Language", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "en", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Language code for OCR processing" }, + "ocrLanguage": { "index": 5, "kind": "parameter", "displayName": "Ocr Language", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Language code for OCR processing. With the docling CLI, en is used when it is not set. With docling-serve, setti [...] "operation": { "index": 6, "kind": "parameter", "displayName": "Operation", "group": "common", "label": "", "required": true, "type": "enum", "javaType": "org.apache.camel.component.docling.DoclingOperations", "enum": [ "CONVERT_TO_MARKDOWN", "CONVERT_TO_HTML", "CONVERT_TO_JSON", "EXTRACT_TEXT", "EXTRACT_STRUCTURED_DATA", "SUBMIT_ASYNC_CONVERSION", "CHECK_CONVERSION_STATUS", "BATCH_CONVERT_TO_MARKDOWN", "BATCH_CONVERT_TO_HTML", "BATCH_CONVERT_TO_JSON", "BATCH_EXTRACT_TEXT", "BATCH_EX [...] "outputFormat": { "index": 7, "kind": "parameter", "displayName": "Output Format", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "markdown", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Output format of the SUBMIT_ASYNC_CONVERSION operation; the other operations alway [...] "useDoclingServe": { "index": 8, "kind": "parameter", "displayName": "Use Docling Serve", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Use docling-serve API instead of CLI command" }, @@ -150,7 +150,7 @@ "doCodeEnrichment": { "index": 20, "kind": "parameter", "displayName": "Do Code Enrichment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable code enrichment in document processing" }, "documentTimeout": { "index": 21, "kind": "parameter", "displayName": "Document Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Document processing timeout in seconds" }, "doFormulaEnrichment": { "index": 22, "kind": "parameter", "displayName": "Do Formula Enrichment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable formula enrichment in document processing" }, - "doOcr": { "index": 23, "kind": "parameter", "displayName": "Do Ocr", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing in docling-serve API mode. When not set, the server uses its own defaults. Set enableOCR [...] + "doOcr": { "index": 23, "kind": "parameter", "displayName": "Do Ocr", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing in docling-serve API mode. When not set, OCR is turned on if ocrLanguage is set, and othe [...] "doPictureClassification": { "index": 24, "kind": "parameter", "displayName": "Do Picture Classification", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable picture classification in document processing" }, "doPictureDescription": { "index": 25, "kind": "parameter", "displayName": "Do Picture Description", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable picture description generation in document processing" }, "doTableStructure": { "index": 26, "kind": "parameter", "displayName": "Do Table Structure", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable table structure recognition" }, diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/docling-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/docling-component.adoc index 42e1dde0f028..0cf7ca02d95c 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/docling-component.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/docling-component.adoc @@ -1024,7 +1024,11 @@ When using docling-serve API mode (`useDoclingServe=true`), the component expose | `doOcr` | _not set_ -| Enable OCR processing in docling-serve API mode. When not set, the server uses its own defaults. Set `enableOCR` to `false` to explicitly disable OCR. +| Enable OCR processing in docling-serve API mode. When not set, OCR is turned on if `ocrLanguage` is set, and otherwise the server uses its own defaults. Set `enableOCR` to `false` to explicitly disable OCR. + +| `ocrLanguage` +| _not set_ +| Language for OCR. When set, it is sent as `ocr_lang` with `do_ocr=true`, unless `enableOCR` or `doOcr` is `false`. When not set, the server uses its own default languages. In CLI mode, `en` is used when it is not set. | `forceOcr` | _not set_ @@ -1036,7 +1040,7 @@ When using docling-serve API mode (`useDoclingServe=true`), the component expose |=== -NOTE: The `enableOCR` and `ocrLanguage` settings are primarily for CLI mode. In API mode, use `doOcr` to explicitly control OCR behavior. When `doOcr` is not set, the server uses its own defaults. Setting `enableOCR=false` will send `doOcr(false)` to the server to disable OCR. +NOTE: In API mode, use `doOcr` to explicitly control OCR behavior. When `doOcr` is not set, a configured `ocrLanguage` turns OCR on, the same way as the `CamelDoclingOCRLanguage` header; otherwise the server uses its own defaults. Setting `enableOCR=false` will send `doOcr(false)` to the server to disable OCR. === Table and Structure Options diff --git a/components/camel-ai/camel-docling/src/generated/resources/META-INF/org/apache/camel/component/docling/docling.json b/components/camel-ai/camel-docling/src/generated/resources/META-INF/org/apache/camel/component/docling/docling.json index 2df8ad2ce3dd..d23ec0f285a5 100644 --- a/components/camel-ai/camel-docling/src/generated/resources/META-INF/org/apache/camel/component/docling/docling.json +++ b/components/camel-ai/camel-docling/src/generated/resources/META-INF/org/apache/camel/component/docling/docling.json @@ -29,7 +29,7 @@ "doclingServeUrl": { "index": 2, "kind": "property", "displayName": "Docling Serve Url", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "http:\/\/localhost:5001", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Docling-serve API URL (e.g., http:\/\/localhost:5001)" }, "enableOCR": { "index": 3, "kind": "property", "displayName": "Enable OCR", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing for scanned documents" }, "includeLayoutInfo": { "index": 4, "kind": "property", "displayName": "Include Layout Info", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Show layout information with bounding boxes" }, - "ocrLanguage": { "index": 5, "kind": "property", "displayName": "Ocr Language", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "en", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Language code for OCR processing" }, + "ocrLanguage": { "index": 5, "kind": "property", "displayName": "Ocr Language", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Language code for OCR processing. With the docling CLI, en is used when it is not set. With docling-serve, settin [...] "operation": { "index": 6, "kind": "property", "displayName": "Operation", "group": "common", "label": "", "required": true, "type": "enum", "javaType": "org.apache.camel.component.docling.DoclingOperations", "enum": [ "CONVERT_TO_MARKDOWN", "CONVERT_TO_HTML", "CONVERT_TO_JSON", "EXTRACT_TEXT", "EXTRACT_STRUCTURED_DATA", "SUBMIT_ASYNC_CONVERSION", "CHECK_CONVERSION_STATUS", "BATCH_CONVERT_TO_MARKDOWN", "BATCH_CONVERT_TO_HTML", "BATCH_CONVERT_TO_JSON", "BATCH_EXTRACT_TEXT", "BATCH_EXT [...] "outputFormat": { "index": 7, "kind": "property", "displayName": "Output Format", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "markdown", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Output format of the SUBMIT_ASYNC_CONVERSION operation; the other operations always [...] "useDoclingServe": { "index": 8, "kind": "property", "displayName": "Use Docling Serve", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Use docling-serve API instead of CLI command" }, @@ -44,7 +44,7 @@ "doCodeEnrichment": { "index": 17, "kind": "property", "displayName": "Do Code Enrichment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable code enrichment in document processing" }, "documentTimeout": { "index": 18, "kind": "property", "displayName": "Document Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Document processing timeout in seconds" }, "doFormulaEnrichment": { "index": 19, "kind": "property", "displayName": "Do Formula Enrichment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable formula enrichment in document processing" }, - "doOcr": { "index": 20, "kind": "property", "displayName": "Do Ocr", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing in docling-serve API mode. When not set, the server uses its own defaults. Set enableOCR t [...] + "doOcr": { "index": 20, "kind": "property", "displayName": "Do Ocr", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing in docling-serve API mode. When not set, OCR is turned on if ocrLanguage is set, and other [...] "doPictureClassification": { "index": 21, "kind": "property", "displayName": "Do Picture Classification", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable picture classification in document processing" }, "doPictureDescription": { "index": 22, "kind": "property", "displayName": "Do Picture Description", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable picture description generation in document processing" }, "doTableStructure": { "index": 23, "kind": "property", "displayName": "Do Table Structure", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable table structure recognition" }, @@ -132,7 +132,7 @@ "doclingServeUrl": { "index": 2, "kind": "parameter", "displayName": "Docling Serve Url", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "http:\/\/localhost:5001", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Docling-serve API URL (e.g., http:\/\/localhost:5001)" }, "enableOCR": { "index": 3, "kind": "parameter", "displayName": "Enable OCR", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing for scanned documents" }, "includeLayoutInfo": { "index": 4, "kind": "parameter", "displayName": "Include Layout Info", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Show layout information with bounding boxes" }, - "ocrLanguage": { "index": 5, "kind": "parameter", "displayName": "Ocr Language", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "en", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Language code for OCR processing" }, + "ocrLanguage": { "index": 5, "kind": "parameter", "displayName": "Ocr Language", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Language code for OCR processing. With the docling CLI, en is used when it is not set. With docling-serve, setti [...] "operation": { "index": 6, "kind": "parameter", "displayName": "Operation", "group": "common", "label": "", "required": true, "type": "enum", "javaType": "org.apache.camel.component.docling.DoclingOperations", "enum": [ "CONVERT_TO_MARKDOWN", "CONVERT_TO_HTML", "CONVERT_TO_JSON", "EXTRACT_TEXT", "EXTRACT_STRUCTURED_DATA", "SUBMIT_ASYNC_CONVERSION", "CHECK_CONVERSION_STATUS", "BATCH_CONVERT_TO_MARKDOWN", "BATCH_CONVERT_TO_HTML", "BATCH_CONVERT_TO_JSON", "BATCH_EXTRACT_TEXT", "BATCH_EX [...] "outputFormat": { "index": 7, "kind": "parameter", "displayName": "Output Format", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "markdown", "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Output format of the SUBMIT_ASYNC_CONVERSION operation; the other operations alway [...] "useDoclingServe": { "index": 8, "kind": "parameter", "displayName": "Use Docling Serve", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Use docling-serve API instead of CLI command" }, @@ -150,7 +150,7 @@ "doCodeEnrichment": { "index": 20, "kind": "parameter", "displayName": "Do Code Enrichment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable code enrichment in document processing" }, "documentTimeout": { "index": 21, "kind": "parameter", "displayName": "Document Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Document processing timeout in seconds" }, "doFormulaEnrichment": { "index": 22, "kind": "parameter", "displayName": "Do Formula Enrichment", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable formula enrichment in document processing" }, - "doOcr": { "index": 23, "kind": "parameter", "displayName": "Do Ocr", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing in docling-serve API mode. When not set, the server uses its own defaults. Set enableOCR [...] + "doOcr": { "index": 23, "kind": "parameter", "displayName": "Do Ocr", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable OCR processing in docling-serve API mode. When not set, OCR is turned on if ocrLanguage is set, and othe [...] "doPictureClassification": { "index": 24, "kind": "parameter", "displayName": "Do Picture Classification", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable picture classification in document processing" }, "doPictureDescription": { "index": 25, "kind": "parameter", "displayName": "Do Picture Description", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable picture description generation in document processing" }, "doTableStructure": { "index": 26, "kind": "parameter", "displayName": "Do Table Structure", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.docling.DoclingConfiguration", "configurationField": "configuration", "description": "Enable table structure recognition" }, diff --git a/components/camel-ai/camel-docling/src/main/docs/docling-component.adoc b/components/camel-ai/camel-docling/src/main/docs/docling-component.adoc index 42e1dde0f028..0cf7ca02d95c 100644 --- a/components/camel-ai/camel-docling/src/main/docs/docling-component.adoc +++ b/components/camel-ai/camel-docling/src/main/docs/docling-component.adoc @@ -1024,7 +1024,11 @@ When using docling-serve API mode (`useDoclingServe=true`), the component expose | `doOcr` | _not set_ -| Enable OCR processing in docling-serve API mode. When not set, the server uses its own defaults. Set `enableOCR` to `false` to explicitly disable OCR. +| Enable OCR processing in docling-serve API mode. When not set, OCR is turned on if `ocrLanguage` is set, and otherwise the server uses its own defaults. Set `enableOCR` to `false` to explicitly disable OCR. + +| `ocrLanguage` +| _not set_ +| Language for OCR. When set, it is sent as `ocr_lang` with `do_ocr=true`, unless `enableOCR` or `doOcr` is `false`. When not set, the server uses its own default languages. In CLI mode, `en` is used when it is not set. | `forceOcr` | _not set_ @@ -1036,7 +1040,7 @@ When using docling-serve API mode (`useDoclingServe=true`), the component expose |=== -NOTE: The `enableOCR` and `ocrLanguage` settings are primarily for CLI mode. In API mode, use `doOcr` to explicitly control OCR behavior. When `doOcr` is not set, the server uses its own defaults. Setting `enableOCR=false` will send `doOcr(false)` to the server to disable OCR. +NOTE: In API mode, use `doOcr` to explicitly control OCR behavior. When `doOcr` is not set, a configured `ocrLanguage` turns OCR on, the same way as the `CamelDoclingOCRLanguage` header; otherwise the server uses its own defaults. Setting `enableOCR=false` will send `doOcr(false)` to the server to disable OCR. === Table and Structure Options diff --git a/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingConfiguration.java b/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingConfiguration.java index 890801b9ddcc..8116394a7f18 100644 --- a/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingConfiguration.java +++ b/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingConfiguration.java @@ -47,9 +47,11 @@ public class DoclingConfiguration implements Cloneable { private boolean enableOCR = true; @UriParam - @Metadata(description = "Language code for OCR processing", defaultValue = "en", + @Metadata(description = "Language code for OCR processing. With the docling CLI, en is used when it is not set." + + " With docling-serve, setting it turns OCR on (do_ocr=true) unless enableOCR or doOcr is false," + + " and when it is not set the server uses its own default languages.", enums = "en,es,fr,de,it,pt,ru,zh,ja,ko,ar,hi,th,vi,tr,pl,nl,sv,da,no,fi,cs,hu,el,he,fa,ur,bn,ta,te,ml,kn,gu,pa,or,as,ne,si,my,lo,km,ka,hy,eu,mt,is,ga,cy,gd,br,oc,ca,gl,ast,an,lad,la,eo,ia,ie,vo,jbo,tlh") - private String ocrLanguage = "en"; + private String ocrLanguage; @UriParam @Metadata(description = "Output format of the SUBMIT_ASYNC_CONVERSION operation; the other operations always use their own format. The html_split_page value is rejected, as docling-serve does not return the split pages; use html instead", @@ -187,7 +189,7 @@ public class DoclingConfiguration implements Cloneable { private boolean includeRawMetadata = false; @UriParam(label = "advanced") - @Metadata(description = "Enable OCR processing in docling-serve API mode. When not set, the server uses its own defaults. Set enableOCR to false to explicitly disable OCR.") + @Metadata(description = "Enable OCR processing in docling-serve API mode. When not set, OCR is turned on if ocrLanguage is set, and otherwise the server uses its own defaults. Set enableOCR to false to explicitly disable OCR.") private Boolean doOcr; @UriParam(label = "advanced") diff --git a/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java b/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java index e526d37d1c11..323f2366da82 100644 --- a/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java +++ b/components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingProducer.java @@ -81,6 +81,7 @@ import ai.docling.serve.api.task.request.TaskStatusPollRequest; import ai.docling.serve.api.task.response.TaskStatus; import ai.docling.serve.api.task.response.TaskStatusPollResponse; import ai.docling.serve.client.DoclingServeClientBuilderFactory; +import ai.docling.serve.client.DoclingServeClientException; import org.apache.camel.Exchange; import org.apache.camel.InvalidPayloadException; import org.apache.camel.StreamCache; @@ -103,6 +104,16 @@ public class DoclingProducer extends DefaultProducer { private static final Logger LOG = LoggerFactory.getLogger(DoclingProducer.class); + /** + * The OCR language of the docling CLI command when neither the endpoint nor the message names one. + */ + static final String DEFAULT_CLI_OCR_LANGUAGE = "en"; + + /** + * What the sync endpoint of docling-serve answers, with a 404, when the conversion task failed on the server. + */ + private static final String TASK_RESULT_NOT_FOUND = "Task result not found"; + /** * Recognized docling CLI flags. Only these flags are permitted in custom arguments (allowlist approach). Flags * managed by the producer ({@code --output}, {@code -o}) are excluded and checked separately. @@ -674,7 +685,7 @@ public class DoclingProducer extends DefaultProducer { try { response = doclingServeApi.convertSource(request); } catch (Exception e) { - throw new IOException("Failed to convert document for metadata extraction: " + e.getMessage(), e); + throw syncConversionFailed("Failed to convert document for metadata extraction", e); } DoclingDocument doclingDocument = extractDoclingDocument(response); @@ -1233,7 +1244,14 @@ public class DoclingProducer extends DefaultProducer { } } else { LOG.debug("Using sync mode for DoclingDocument conversion"); - response = doclingServeApi.convertSource(request); + try { + response = doclingServeApi.convertSource(request); + } catch (DoclingServeClientException e) { + if (isLostSyncResult(e)) { + throw syncConversionFailed("Failed to convert document", e); + } + throw e; + } } return extractDoclingDocument(response); @@ -1468,6 +1486,31 @@ public class DoclingProducer extends DefaultProducer { return results; } + /** + * The exception of a failed sync conversion. + * <p> + * When the conversion fails on the server, the sync endpoint of docling-serve does not return the error: it answers + * with a 404 "Task result not found", which reads as if the client asked for the wrong task. That answer is turned + * into a message saying that the conversion failed on the server and where to find the reason. + */ + private static IOException syncConversionFailed(String message, Exception e) { + if (isLostSyncResult(e)) { + return new IOException( + message + ": the conversion failed on the docling-serve server, which answered \"" + + TASK_RESULT_NOT_FOUND + "\" in sync mode. The cause is in the docling-serve log," + + " or use useAsyncMode=true to get the error of the conversion", + e); + } + return new IOException(message + ": " + e.getMessage(), e); + } + + private static boolean isLostSyncResult(Exception e) { + return e instanceof DoclingServeClientException clientException + && clientException.getStatusCode() == 404 + && clientException.getResponseBody() != null + && clientException.getResponseBody().contains(TASK_RESULT_NOT_FOUND); + } + private String convertDocumentSync(String inputSource, String outputFormat, OcrSettings ocrSettings) throws IOException { LOG.debug("Converting document using docling-java (sync): {}", inputSource); @@ -1478,7 +1521,7 @@ public class DoclingProducer extends DefaultProducer { ConvertDocumentResponse response = doclingServeApi.convertSource(request); return extractConvertedContent(response, outputFormat); } catch (Exception e) { - throw new IOException("Failed to convert document: " + e.getMessage(), e); + throw syncConversionFailed("Failed to convert document", e); } } @@ -1489,7 +1532,7 @@ public class DoclingProducer extends DefaultProducer { ConvertDocumentResponse response = doclingServeApi.convertSource(request); return extractConvertedContent(response, "json"); } catch (Exception e) { - throw new IOException("Failed to convert document: " + e.getMessage(), e); + throw syncConversionFailed("Failed to convert document", e); } } @@ -1623,15 +1666,19 @@ public class DoclingProducer extends DefaultProducer { * that DoclingOcrHeadersTest can resolve them the way the producer does. */ OcrSettings resolveOcrSettings(Exchange exchange) { - // Send doOcr only when explicitly configured via the doOcr property, - // or when enableOCR has been explicitly disabled. When both are at their - // defaults (doOcr=null, enableOCR=true), let the server use its own defaults - // to preserve backward compatibility. + // Send doOcr only when explicitly configured via the doOcr property, when enableOCR has been explicitly + // disabled, or when an OCR language is configured. When all are at their defaults (doOcr=null, + // enableOCR=true, no ocrLanguage), let the server use its own defaults to preserve backward compatibility. Boolean doOcr = configuration.getDoOcr(); String ocrLanguage = configuration.getOcrLanguage(); if (doOcr == null && !configuration.isEnableOCR()) { doOcr = Boolean.FALSE; } + if (doOcr == null && ObjectHelper.isNotEmpty(ocrLanguage)) { + // a configured language is asking for OCR, as the language header is; ocrLanguage has no default, so a + // language here was set on purpose and does not override the server defaults on every request + doOcr = Boolean.TRUE; + } // The per-message headers win over the endpoint configuration, as they do on the CLI path: a scanned // attachment in an otherwise text-based route, or a foreign-language one, can then be OCRed without a @@ -2369,6 +2416,10 @@ public class DoclingProducer extends DefaultProducer { if (ObjectHelper.isEmpty(ocrLanguage)) { ocrLanguage = configuration.getOcrLanguage(); } + if (ObjectHelper.isEmpty(ocrLanguage)) { + // the docling CLI has always been given a language, so keep English when none is configured + ocrLanguage = DEFAULT_CLI_OCR_LANGUAGE; + } if (!enableOcr) { command.add("--no-ocr"); diff --git a/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingOcrHeadersTest.java b/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingOcrHeadersTest.java index f323f1f43317..7ae5ac938e91 100644 --- a/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingOcrHeadersTest.java +++ b/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingOcrHeadersTest.java @@ -42,6 +42,9 @@ class DoclingOcrHeadersTest extends CamelTestSupport { private static final String OCR_OFF = "docling:convert?operation=CONVERT_TO_MARKDOWN&enableOCR=false&ocrLanguage=de"; private static final String OCR_ON_IN_FRENCH = "docling:convert?operation=CONVERT_TO_MARKDOWN&doOcr=true&ocrLanguage=fr"; + private static final String FRENCH = "docling:convert?operation=CONVERT_TO_MARKDOWN&ocrLanguage=fr"; + private static final String DO_OCR_OFF_IN_FRENCH + = "docling:convert?operation=CONVERT_TO_MARKDOWN&doOcr=false&ocrLanguage=fr"; // --- the docling CLI command @@ -134,6 +137,68 @@ class DoclingOcrHeadersTest extends CamelTestSupport { assertThat(options.getOcrLang()).isNullOrEmpty(); } + // --- CAMEL-27202: the ocrLanguage option of the endpoint, without doOcr + + @Test + void theLanguageOfTheEndpointTurnsOnOcrInTheServeRequest() throws Exception { + // doOcr is not set and enableOCR is at its default: a configured language is asking for OCR, as the header is + ConvertDocumentOptions options = serveOptions(FRENCH, null, null); + + assertThat(options.getDoOcr()).isTrue(); + assertThat(options.getOcrLang()).containsExactly("fr"); + } + + @Test + void theLanguageHeaderWinsOverTheLanguageOfTheEndpointInTheServeRequest() throws Exception { + ConvertDocumentOptions options = serveOptions(FRENCH, null, "es"); + + assertThat(options.getDoOcr()).isTrue(); + assertThat(options.getOcrLang()).containsExactly("es"); + } + + @Test + void theLanguageOfTheEndpointDoesNotTurnOnOcrThatEnableOcrDisabled() throws Exception { + ConvertDocumentOptions options = serveOptions(OCR_OFF, null, null); + + assertThat(options.getDoOcr()).isFalse(); + assertThat(options.getOcrLang()).isNullOrEmpty(); + } + + @Test + void theLanguageOfTheEndpointDoesNotTurnOnOcrThatDoOcrDisabled() throws Exception { + ConvertDocumentOptions options = serveOptions(DO_OCR_OFF_IN_FRENCH, null, null); + + assertThat(options.getDoOcr()).isFalse(); + assertThat(options.getOcrLang()).isNullOrEmpty(); + } + + @Test + void theEnableOcrHeaderTurnsOffOcrThatTheLanguageOfTheEndpointTurnedOn() throws Exception { + ConvertDocumentOptions options = serveOptions(FRENCH, false, null); + + assertThat(options.getDoOcr()).isFalse(); + assertThat(options.getOcrLang()).isNullOrEmpty(); + } + + @Test + void theEnableOcrHeaderAloneLeavesTheLanguageToTheServer() throws Exception { + // ocrLanguage has no default, so en is no longer sent in place of the server's own default languages + ConvertDocumentOptions options = serveOptions(DEFAULT, true, null); + + assertThat(options.getDoOcr()).isTrue(); + assertThat(options.getOcrLang()).isNullOrEmpty(); + } + + @Test + void theLanguageOfTheEndpointReachesTheCli() throws Exception { + assertThat(commandFor(FRENCH, null, null)).contains("--ocr-lang", "fr").doesNotContain("--no-ocr"); + } + + @Test + void theCliKeepsEnglishWhenNoLanguageIsConfigured() throws Exception { + assertThat(commandFor(DEFAULT, true, null)).contains("--ocr-lang", DoclingProducer.DEFAULT_CLI_OCR_LANGUAGE); + } + // --- the language is docling's own identifier, so it is passed on as it is @Test diff --git a/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingServeSyncFailureTest.java b/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingServeSyncFailureTest.java new file mode 100644 index 000000000000..7dcf25a9527f --- /dev/null +++ b/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingServeSyncFailureTest.java @@ -0,0 +1,109 @@ +/* + * 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.docling; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; + +import com.sun.net.httpserver.HttpServer; +import org.apache.camel.Exchange; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * CAMEL-27202: when a conversion fails on the server, the sync endpoint of docling-serve answers with a 404 "Task + * result not found" instead of the error. The producer says that the conversion failed on the server, using a stub + * docling-serve instead of a real one. + */ +class DoclingServeSyncFailureTest extends CamelTestSupport { + + private static final String SOURCE = "https://example.com/report.pdf"; + private static final String TASK_RESULT_NOT_FOUND + = "{\"detail\":\"Task result not found. Please wait for a completion status.\"}"; + + private HttpServer server; + + @AfterEach + void stopStubServer() { + if (server != null) { + server.stop(0); + server = null; + } + } + + @Test + void aLostSyncResultSaysThatTheConversionFailedOnTheServer() throws Exception { + startStubServer(404, TASK_RESULT_NOT_FOUND); + + Exception exception = convert("CONVERT_TO_MARKDOWN"); + + assertThat(exception).isInstanceOf(IOException.class) + .hasMessageContaining("the conversion failed on the docling-serve server") + .hasMessageContaining("docling-serve log") + .hasMessageContaining("useAsyncMode=true"); + } + + @Test + void aLostSyncResultOfAJsonConversionSaysThatTheConversionFailedOnTheServer() throws Exception { + startStubServer(404, TASK_RESULT_NOT_FOUND); + + Exception exception = convert("CONVERT_TO_JSON"); + + assertThat(exception).isInstanceOf(IOException.class) + .hasMessageContaining("the conversion failed on the docling-serve server"); + } + + @Test + void otherErrorsKeepTheMessageOfTheServer() throws Exception { + startStubServer(500, "{\"detail\":\"Internal Server Error\"}"); + + Exception exception = convert("CONVERT_TO_MARKDOWN"); + + assertThat(exception).isInstanceOf(IOException.class) + .hasMessageStartingWith("Failed to convert document: ") + .hasMessageContaining("Internal Server Error") + .hasMessageNotContaining("docling-serve log"); + } + + private Exception convert(String operation) { + String uri = "docling:convert?operation=" + operation + + "&useDoclingServe=true&allowUrlSource=true&doclingServeUrl=http://localhost:" + + server.getAddress().getPort(); + Exchange exchange = template.send(uri, e -> e.getIn().setBody(SOURCE)); + + return exchange.getException(); + } + + private void startStubServer(int status, String answer) throws IOException { + server = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0); + server.createContext("/", exchange -> { + byte[] body = answer.getBytes(StandardCharsets.UTF_8); + exchange.getResponseHeaders().add("Content-Type", "application/json"); + exchange.sendResponseHeaders(status, body.length); + try (OutputStream out = exchange.getResponseBody()) { + out.write(body); + } + }); + server.start(); + } +} diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc index 8e892f5ce65b..9301ae0112f9 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc @@ -10966,6 +10966,17 @@ not pass a language on; a language header alone turns OCR on, unless the endpoin The language itself is passed to docling untouched, in both forms: it is docling's own identifier (language codes such as `en,de`, BCP-47 tags such as `iso:zh-Hant`, or `script/Latin`), and docling validates it. +=== camel-docling - the ocrLanguage option is sent to docling-serve + +With docling-serve (`useDoclingServe=true`), the `ocrLanguage` option was only sent when `doOcr=true` was also set; +otherwise it was dropped and the server used its own default languages. The option now works like the +`CamelDoclingOCRLanguage` header: when it is set, the request has `do_ocr=true` and the language, unless `enableOCR` or +`doOcr` is `false`. Remove `ocrLanguage` from the endpoint if OCR should stay at the server defaults. + +The option no longer has a default value (it was `en`). The docling CLI path still uses `en` when no language is set. +On the docling-serve path, `doOcr=true` or a `CamelDoclingEnableOCR=true` header without a language no longer sends +`en`: the server uses its own default languages. Set `ocrLanguage=en` to keep English. + === camel-spiffe - SpiffeSecurityPolicy reads the TLS peer from servlet, Undertow and Vert.x consumers `SpiffeSecurityPolicy` now recognizes authenticated TLS peer certificates supplied by servlet/Jetty, Undertow, diff --git a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/DoclingComponentBuilderFactory.java b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/DoclingComponentBuilderFactory.java index 5e744e77f753..9c2fefc13a07 100644 --- a/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/DoclingComponentBuilderFactory.java +++ b/dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/DoclingComponentBuilderFactory.java @@ -135,13 +135,14 @@ public interface DoclingComponentBuilderFactory { return this; } - /** - * Language code for OCR processing. + * Language code for OCR processing. With the docling CLI, en is used + * when it is not set. With docling-serve, setting it turns OCR on + * (do_ocr=true) unless enableOCR or doOcr is false, and when it is not + * set the server uses its own default languages. * * The option is a: <code>java.lang.String</code> type. * - * Default: en * Group: common * * @param ocrLanguage the value to set @@ -410,9 +411,9 @@ public interface DoclingComponentBuilderFactory { } /** - * Enable OCR processing in docling-serve API mode. When not set, the - * server uses its own defaults. Set enableOCR to false to explicitly - * disable OCR. + * Enable OCR processing in docling-serve API mode. When not set, OCR is + * turned on if ocrLanguage is set, and otherwise the server uses its + * own defaults. Set enableOCR to false to explicitly disable OCR. * * The option is a: <code>java.lang.Boolean</code> type. * diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DoclingEndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DoclingEndpointBuilderFactory.java index 3f43d5daad36..1b262eace5b0 100644 --- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DoclingEndpointBuilderFactory.java +++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DoclingEndpointBuilderFactory.java @@ -151,11 +151,13 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Language code for OCR processing. + * Language code for OCR processing. With the docling CLI, en is used + * when it is not set. With docling-serve, setting it turns OCR on + * (do_ocr=true) unless enableOCR or doOcr is false, and when it is not + * set the server uses its own default languages. * * The option is a: <code>java.lang.String</code> type. * - * Default: en * Group: common * * @param ocrLanguage the value to set @@ -1749,9 +1751,9 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Enable OCR processing in docling-serve API mode. When not set, the - * server uses its own defaults. Set enableOCR to false to explicitly - * disable OCR. + * Enable OCR processing in docling-serve API mode. When not set, OCR is + * turned on if ocrLanguage is set, and otherwise the server uses its + * own defaults. Set enableOCR to false to explicitly disable OCR. * * The option is a: <code>java.lang.Boolean</code> type. * @@ -1765,9 +1767,9 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Enable OCR processing in docling-serve API mode. When not set, the - * server uses its own defaults. Set enableOCR to false to explicitly - * disable OCR. + * Enable OCR processing in docling-serve API mode. When not set, OCR is + * turned on if ocrLanguage is set, and otherwise the server uses its + * own defaults. Set enableOCR to false to explicitly disable OCR. * * The option will be converted to a <code>java.lang.Boolean</code> * type. @@ -2261,11 +2263,13 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Language code for OCR processing. + * Language code for OCR processing. With the docling CLI, en is used + * when it is not set. With docling-serve, setting it turns OCR on + * (do_ocr=true) unless enableOCR or doOcr is false, and when it is not + * set the server uses its own default languages. * * The option is a: <code>java.lang.String</code> type. * - * Default: en * Group: common * * @param ocrLanguage the value to set @@ -3220,9 +3224,9 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Enable OCR processing in docling-serve API mode. When not set, the - * server uses its own defaults. Set enableOCR to false to explicitly - * disable OCR. + * Enable OCR processing in docling-serve API mode. When not set, OCR is + * turned on if ocrLanguage is set, and otherwise the server uses its + * own defaults. Set enableOCR to false to explicitly disable OCR. * * The option is a: <code>java.lang.Boolean</code> type. * @@ -3236,9 +3240,9 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Enable OCR processing in docling-serve API mode. When not set, the - * server uses its own defaults. Set enableOCR to false to explicitly - * disable OCR. + * Enable OCR processing in docling-serve API mode. When not set, OCR is + * turned on if ocrLanguage is set, and otherwise the server uses its + * own defaults. Set enableOCR to false to explicitly disable OCR. * * The option will be converted to a <code>java.lang.Boolean</code> * type. @@ -3733,11 +3737,13 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Language code for OCR processing. + * Language code for OCR processing. With the docling CLI, en is used + * when it is not set. With docling-serve, setting it turns OCR on + * (do_ocr=true) unless enableOCR or doOcr is false, and when it is not + * set the server uses its own default languages. * * The option is a: <code>java.lang.String</code> type. * - * Default: en * Group: common * * @param ocrLanguage the value to set @@ -4649,9 +4655,9 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Enable OCR processing in docling-serve API mode. When not set, the - * server uses its own defaults. Set enableOCR to false to explicitly - * disable OCR. + * Enable OCR processing in docling-serve API mode. When not set, OCR is + * turned on if ocrLanguage is set, and otherwise the server uses its + * own defaults. Set enableOCR to false to explicitly disable OCR. * * The option is a: <code>java.lang.Boolean</code> type. * @@ -4665,9 +4671,9 @@ public interface DoclingEndpointBuilderFactory { return this; } /** - * Enable OCR processing in docling-serve API mode. When not set, the - * server uses its own defaults. Set enableOCR to false to explicitly - * disable OCR. + * Enable OCR processing in docling-serve API mode. When not set, OCR is + * turned on if ocrLanguage is set, and otherwise the server uses its + * own defaults. Set enableOCR to false to explicitly disable OCR. * * The option will be converted to a <code>java.lang.Boolean</code> * type.
