Class DoclingServeClient

java.lang.Object
ai.docling.serve.client.operations.HttpOperations
ai.docling.serve.client.DoclingServeClient
All Implemented Interfaces:
ai.docling.serve.api.DoclingServeApi, ai.docling.serve.api.DoclingServeChunkApi, ai.docling.serve.api.DoclingServeClearApi, ai.docling.serve.api.DoclingServeConvertApi, ai.docling.serve.api.DoclingServeHealthApi, ai.docling.serve.api.DoclingServeTaskApi
Direct Known Subclasses:
DoclingServeJackson2Client, DoclingServeJackson3Client

public abstract class DoclingServeClient extends HttpOperations implements ai.docling.serve.api.DoclingServeApi
Abstract class representing a client for interacting with the Docling API.

This class handles the foundational functionality needed to perform HTTP requests to the Docling API, with customizable base URL and HTTP client configurations. It provides abstract methods for JSON serialization and deserialization, allowing implementation-specific customization.

The client is structured hierarchically, with separate nested implementations for each API interface (DoclingServeHealthApi, DoclingServeConvertApi, DoclingServeChunkApi, DoclingServeClearApi, DoclingServeTaskApi). These implementations share common HTTP execution logic and configuration.

Concrete subclasses must implement readValue(String, Class) and writeValueAsString(Object) for serialization and deserialization behavior.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Abstract base class for building instances of DoclingServeClient.

    Nested classes/interfaces inherited from interface ai.docling.serve.api.DoclingServeApi

    ai.docling.serve.api.DoclingServeApi.DoclingApiBuilder<T extends ai.docling.serve.api.DoclingServeApi,B extends ai.docling.serve.api.DoclingServeApi.DoclingApiBuilder<T,B>>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final URI
     

    Fields inherited from class ai.docling.serve.client.operations.HttpOperations

    API_KEY_HEADER_NAME
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    ai.docling.serve.api.chunk.response.ChunkDocumentResponse
    chunkSourceWithHierarchicalChunker(ai.docling.serve.api.chunk.request.HierarchicalChunkDocumentRequest request)
     
    CompletionStage<ai.docling.serve.api.chunk.response.ChunkDocumentResponse>
    chunkSourceWithHierarchicalChunkerAsync(ai.docling.serve.api.chunk.request.HierarchicalChunkDocumentRequest request)
     
    ai.docling.serve.api.chunk.response.ChunkDocumentResponse
    chunkSourceWithHybridChunker(ai.docling.serve.api.chunk.request.HybridChunkDocumentRequest request)
     
    CompletionStage<ai.docling.serve.api.chunk.response.ChunkDocumentResponse>
    chunkSourceWithHybridChunkerAsync(ai.docling.serve.api.chunk.request.HybridChunkDocumentRequest request)
     
    ai.docling.serve.api.chunk.response.ChunkDocumentResponse
    chunkTaskResult(ai.docling.serve.api.task.request.TaskResultRequest request)
     
    ai.docling.serve.api.clear.response.ClearResponse
    clearConverters(ai.docling.serve.api.clear.request.ClearConvertersRequest request)
     
    ai.docling.serve.api.clear.response.ClearResponse
    clearResults(ai.docling.serve.api.clear.request.ClearResultsRequest request)
     
    ai.docling.serve.api.convert.response.ConvertDocumentResponse
    convertSource(ai.docling.serve.api.convert.request.ConvertDocumentRequest request)
     
    CompletionStage<ai.docling.serve.api.convert.response.ConvertDocumentResponse>
    convertSourceAsync(ai.docling.serve.api.convert.request.ConvertDocumentRequest request)
     
    ai.docling.serve.api.convert.response.ConvertDocumentResponse
    convertTaskResult(ai.docling.serve.api.task.request.TaskResultRequest request)
     
    protected <I, O> HttpRequest.Builder
    createRequestBuilder(RequestContext<I,O> requestContext)
     
    protected <T> T
    execute(HttpRequest request, Class<T> expectedValueType)
     
    protected <I, O> O
    executeGet(RequestContext<I,O> requestContext)
    Executes an HTTP GET request using the details specified in the provided RequestContext.
    protected <I, O> O
    executePost(RequestContext<I,O> requestContext)
    Executes an HTTP POST request using the details provided in the RequestContext.
    protected <T> T
    getResponse(HttpRequest request, HttpResponse<String> response, Class<T> expectedReturnType)
     
    ai.docling.serve.api.health.HealthCheckResponse
     
    protected void
     
    protected void
    logResponse(HttpResponse<String> response, Optional<String> responseBody)
     
    ai.docling.serve.api.task.response.TaskStatusPollResponse
    pollTaskStatus(ai.docling.serve.api.task.request.TaskStatusPollRequest request)
     
    protected boolean
     
    protected abstract <T> T
    readValue(String json, Class<T> valueType)
    Reads and deserializes the given JSON string into an instance of the specified type.
    protected abstract <T> String
    Serializes the given object into its JSON string representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface ai.docling.serve.api.DoclingServeApi

    toBuilder

    Methods inherited from interface ai.docling.serve.api.DoclingServeChunkApi

    chunkFilesWithHierarchicalChunker, chunkFilesWithHierarchicalChunker, chunkFilesWithHierarchicalChunkerAsync, chunkFilesWithHierarchicalChunkerAsync, chunkFilesWithHybridChunker, chunkFilesWithHybridChunker, chunkFilesWithHybridChunkerAsync, chunkFilesWithHybridChunkerAsync

    Methods inherited from interface ai.docling.serve.api.DoclingServeConvertApi

    convertFiles, convertFiles, convertFilesAsync, convertFilesAsync
  • Field Details

    • DEFAULT_BASE_URL

      protected static final URI DEFAULT_BASE_URL
  • Constructor Details

  • Method Details

    • readValue

      protected abstract <T> T readValue(String json, Class<T> valueType)
      Reads and deserializes the given JSON string into an instance of the specified type.
      Type Parameters:
      T - the type of the object to be deserialized
      Parameters:
      json - the JSON string to deserialize; must not be null
      valueType - the Class of the target type; must not be null
      Returns:
      an instance of T deserialized from the provided JSON
      Throws:
      RuntimeException - if the JSON parsing fails
    • writeValueAsString

      protected abstract <T> String writeValueAsString(T value)
      Serializes the given object into its JSON string representation.
      Type Parameters:
      T - the type of the object to serialize
      Parameters:
      value - the object to serialize; must not be null
      Returns:
      the JSON string representation of the given object
      Throws:
      RuntimeException - if serialization fails
    • prettyPrintJson

      protected boolean prettyPrintJson()
    • logRequest

      protected void logRequest(HttpRequest request)
    • logResponse

      protected void logResponse(HttpResponse<String> response, Optional<String> responseBody)
    • execute

      protected <T> T execute(HttpRequest request, Class<T> expectedValueType)
    • executePost

      protected <I, O> O executePost(RequestContext<I,O> requestContext)
      Description copied from class: HttpOperations
      Executes an HTTP POST request using the details provided in the RequestContext. This method is designed to be implemented by subclasses and facilitates sending POST requests with a specified request payload and receiving a deserialized response.
      Specified by:
      executePost in class HttpOperations
      Type Parameters:
      I - the type of the request payload
      O - the type of the response object
      Parameters:
      requestContext - the context containing details such as the URI, request payload, and expected response type of the POST operation
      Returns:
      an instance of the response type O, which represents the deserialized response data
    • executeGet

      protected <I, O> O executeGet(RequestContext<I,O> requestContext)
      Description copied from class: HttpOperations
      Executes an HTTP GET request using the details specified in the provided RequestContext.
      Specified by:
      executeGet in class HttpOperations
      Type Parameters:
      I - the type of the request payload
      O - the type of the response object
      Parameters:
      requestContext - the context containing details such as the URI, request payload, and expected response type of the GET operation
      Returns:
      an instance of the response type O, which represents the deserialized response data
    • createRequestBuilder

      protected <I, O> HttpRequest.Builder createRequestBuilder(RequestContext<I,O> requestContext)
    • getResponse

      protected <T> T getResponse(HttpRequest request, HttpResponse<String> response, Class<T> expectedReturnType)
    • health

      public ai.docling.serve.api.health.HealthCheckResponse health()
      Specified by:
      health in interface ai.docling.serve.api.DoclingServeHealthApi
    • convertSource

      public ai.docling.serve.api.convert.response.ConvertDocumentResponse convertSource(ai.docling.serve.api.convert.request.ConvertDocumentRequest request)
      Specified by:
      convertSource in interface ai.docling.serve.api.DoclingServeConvertApi
    • chunkSourceWithHierarchicalChunker

      public ai.docling.serve.api.chunk.response.ChunkDocumentResponse chunkSourceWithHierarchicalChunker(ai.docling.serve.api.chunk.request.HierarchicalChunkDocumentRequest request)
      Specified by:
      chunkSourceWithHierarchicalChunker in interface ai.docling.serve.api.DoclingServeChunkApi
    • chunkSourceWithHybridChunker

      public ai.docling.serve.api.chunk.response.ChunkDocumentResponse chunkSourceWithHybridChunker(ai.docling.serve.api.chunk.request.HybridChunkDocumentRequest request)
      Specified by:
      chunkSourceWithHybridChunker in interface ai.docling.serve.api.DoclingServeChunkApi
    • chunkSourceWithHierarchicalChunkerAsync

      public CompletionStage<ai.docling.serve.api.chunk.response.ChunkDocumentResponse> chunkSourceWithHierarchicalChunkerAsync(ai.docling.serve.api.chunk.request.HierarchicalChunkDocumentRequest request)
      Specified by:
      chunkSourceWithHierarchicalChunkerAsync in interface ai.docling.serve.api.DoclingServeChunkApi
    • chunkSourceWithHybridChunkerAsync

      public CompletionStage<ai.docling.serve.api.chunk.response.ChunkDocumentResponse> chunkSourceWithHybridChunkerAsync(ai.docling.serve.api.chunk.request.HybridChunkDocumentRequest request)
      Specified by:
      chunkSourceWithHybridChunkerAsync in interface ai.docling.serve.api.DoclingServeChunkApi
    • pollTaskStatus

      public ai.docling.serve.api.task.response.TaskStatusPollResponse pollTaskStatus(ai.docling.serve.api.task.request.TaskStatusPollRequest request)
      Specified by:
      pollTaskStatus in interface ai.docling.serve.api.DoclingServeTaskApi
    • convertTaskResult

      public ai.docling.serve.api.convert.response.ConvertDocumentResponse convertTaskResult(ai.docling.serve.api.task.request.TaskResultRequest request)
      Specified by:
      convertTaskResult in interface ai.docling.serve.api.DoclingServeTaskApi
    • chunkTaskResult

      public ai.docling.serve.api.chunk.response.ChunkDocumentResponse chunkTaskResult(ai.docling.serve.api.task.request.TaskResultRequest request)
      Specified by:
      chunkTaskResult in interface ai.docling.serve.api.DoclingServeTaskApi
    • clearConverters

      public ai.docling.serve.api.clear.response.ClearResponse clearConverters(ai.docling.serve.api.clear.request.ClearConvertersRequest request)
      Specified by:
      clearConverters in interface ai.docling.serve.api.DoclingServeClearApi
    • clearResults

      public ai.docling.serve.api.clear.response.ClearResponse clearResults(ai.docling.serve.api.clear.request.ClearResultsRequest request)
      Specified by:
      clearResults in interface ai.docling.serve.api.DoclingServeClearApi
    • convertSourceAsync

      public CompletionStage<ai.docling.serve.api.convert.response.ConvertDocumentResponse> convertSourceAsync(ai.docling.serve.api.convert.request.ConvertDocumentRequest request)
      Specified by:
      convertSourceAsync in interface ai.docling.serve.api.DoclingServeConvertApi