Class TikaHttpClient

java.lang.Object
org.apache.tika.http.TikaHttpClient
All Implemented Interfaces:
Closeable, AutoCloseable

public class TikaHttpClient extends Object implements Closeable
Lightweight HTTP client for Tika parser modules that call external REST endpoints (embedding APIs, VLM services, etc.).

Built on HttpClient with a daemon thread executor so the JVM — including forked PipesServer processes — shuts down cleanly without waiting for idle HTTP threads.

This class has no runtime dependencies beyond the JDK and tika-core. Obtain an instance via build(int) and close it when done to release the underlying executor.

Since:
Apache Tika 4.0
  • Method Details

    • build

      public static TikaHttpClient build(int connectTimeoutSeconds)
      Create a new TikaHttpClient with a daemon-thread executor.
      Parameters:
      connectTimeoutSeconds - TCP connection timeout in seconds
    • postJson

      public String postJson(String url, String jsonBody, Map<String,String> headers, int timeoutSeconds) throws IOException, TikaException
      POST a JSON body to url and return the response body as a string.
      Parameters:
      url - target URL
      jsonBody - request body (UTF-8 JSON)
      headers - additional HTTP headers (e.g. Authorization)
      timeoutSeconds - read timeout; 0 uses the default timeout
      Returns:
      response body string
      Throws:
      IOException - on network error
      TikaException - on non-2xx HTTP status
    • get

      public String get(String url, Map<String,String> headers, int timeoutSeconds) throws IOException, TikaException
      GET url and return the response body as a string. Useful for health-check probes at init time.
      Parameters:
      url - target URL
      headers - additional HTTP headers
      timeoutSeconds - read timeout; 0 uses the default timeout
      Returns:
      response body string
      Throws:
      IOException - on network error
      TikaException - on non-2xx HTTP status
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable