This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch ci-issue-docling-serve-client-upgrade in repository https://gitbox.apache.org/repos/asf/camel.git
commit beb462055fa5d9aa3d2ace0e12f7a7772779d081 Author: Andrea Cosentino <[email protected]> AuthorDate: Tue Mar 31 12:35:09 2026 +0200 Bump ai.docling:docling-serve-client from 0.4.7 to 0.5.0 Adapt to API breaking change: ConvertDocumentResponse is now a sealed abstract class. The getDocument() method moved to the InBodyConvertDocumentResponse subclass. Use instanceof pattern matching to handle the polymorphic response type. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --- .../camel/component/docling/DoclingProducer.java | 79 ++++++++++++---------- .../docling/DoclingAsyncConversionTest.java | 3 +- parent/pom.xml | 2 +- 3 files changed, 47 insertions(+), 37 deletions(-) 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 f3f71e7fafe2..03a573705f81 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 @@ -70,6 +70,7 @@ import ai.docling.serve.api.convert.request.source.FileSource; import ai.docling.serve.api.convert.request.source.HttpSource; import ai.docling.serve.api.convert.response.ConvertDocumentResponse; import ai.docling.serve.api.convert.response.DocumentResponse; +import ai.docling.serve.api.convert.response.InBodyConvertDocumentResponse; import ai.docling.serve.api.task.request.TaskStatusPollRequest; import ai.docling.serve.api.task.response.TaskStatus; import ai.docling.serve.api.task.response.TaskStatusPollResponse; @@ -1124,15 +1125,19 @@ public class DoclingProducer extends DefaultProducer { } private DoclingDocument extractDoclingDocument(ConvertDocumentResponse response) throws IOException { - DocumentResponse document = response.getDocument(); - if (document == null) { - throw new IOException("No document in response"); - } - DoclingDocument result = document.getJsonContent(); - if (result == null) { - throw new IOException("No JSON content in document response"); + if (response instanceof InBodyConvertDocumentResponse inBodyResponse) { + DocumentResponse document = inBodyResponse.getDocument(); + if (document == null) { + throw new IOException("No document in response"); + } + DoclingDocument result = document.getJsonContent(); + if (result == null) { + throw new IOException("No JSON content in document response"); + } + return result; + } else { + throw new IOException("Unsupported response type: cannot extract DoclingDocument"); } - return result; } private void processBatchStructuredData(Exchange exchange) throws Exception { @@ -1555,35 +1560,39 @@ public class DoclingProducer extends DefaultProducer { private String extractConvertedContent(ConvertDocumentResponse response, String outputFormat) throws IOException { try { - DocumentResponse document = response.getDocument(); + if (response instanceof InBodyConvertDocumentResponse inBodyResponse) { + DocumentResponse document = inBodyResponse.getDocument(); - if (document == null) { - throw new IOException("No document in response"); - } + if (document == null) { + throw new IOException("No document in response"); + } - String format = mapOutputFormat(outputFormat); - - switch (format) { - case "md": - String markdown = document.getMarkdownContent(); - return markdown != null ? markdown : ""; - case "html": - String html = document.getHtmlContent(); - return html != null ? html : ""; - case "text": - String text = document.getTextContent(); - return text != null ? text : ""; - case "json": - // Return the document JSON content - var jsonDoc = document.getJsonContent(); - if (jsonDoc != null) { - return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonDoc); - } - return "{}"; - default: - // Default to markdown - String defaultMarkdown = document.getMarkdownContent(); - return defaultMarkdown != null ? defaultMarkdown : ""; + String format = mapOutputFormat(outputFormat); + + switch (format) { + case "md": + String markdown = document.getMarkdownContent(); + return markdown != null ? markdown : ""; + case "html": + String html = document.getHtmlContent(); + return html != null ? html : ""; + case "text": + String text = document.getTextContent(); + return text != null ? text : ""; + case "json": + // Return the document JSON content + var jsonDoc = document.getJsonContent(); + if (jsonDoc != null) { + return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonDoc); + } + return "{}"; + default: + // Default to markdown + String defaultMarkdown = document.getMarkdownContent(); + return defaultMarkdown != null ? defaultMarkdown : ""; + } + } else { + throw new IOException("Unsupported response type: cannot extract converted content"); } } catch (Exception e) { LOG.warn("Failed to extract content from response: {}", e.getMessage()); diff --git a/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingAsyncConversionTest.java b/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingAsyncConversionTest.java index 3bf29ebfe075..abe897deb289 100644 --- a/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingAsyncConversionTest.java +++ b/components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingAsyncConversionTest.java @@ -22,6 +22,7 @@ import java.util.concurrent.CompletableFuture; import ai.docling.serve.api.convert.response.ConvertDocumentResponse; import ai.docling.serve.api.convert.response.DocumentResponse; +import ai.docling.serve.api.convert.response.InBodyConvertDocumentResponse; import org.apache.camel.CamelExecutionException; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; @@ -94,7 +95,7 @@ class DoclingAsyncConversionTest extends CamelTestSupport { Map<String, CompletableFuture<ConvertDocumentResponse>> pendingTasks = getPendingAsyncTasks(producer); // Create a completed future with a mock response - ConvertDocumentResponse mockResponse = ConvertDocumentResponse.builder() + ConvertDocumentResponse mockResponse = InBodyConvertDocumentResponse.builder() .document(DocumentResponse.builder() .markdownContent("# Converted Document") .build()) diff --git a/parent/pom.xml b/parent/pom.xml index 3f5b1ecc3f43..49b749076524 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -156,7 +156,7 @@ <dnsjava-version>3.6.4</dnsjava-version> <djl-version>0.36.0</djl-version> <djl-python-version>0.34.0</djl-python-version> - <docling-java-version>0.4.7</docling-java-version> + <docling-java-version>0.5.0</docling-java-version> <docker-java-version>3.7.1</docker-java-version> <dropbox-version>7.0.0</dropbox-version> <eddsa-version>0.3.0</eddsa-version>
