Package org.apache.tika.http
Class TikaHttpClient
java.lang.Object
org.apache.tika.http.TikaHttpClient
- All Implemented Interfaces:
Closeable,AutoCloseable
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 Summary
Modifier and TypeMethodDescriptionstatic TikaHttpClientbuild(int connectTimeoutSeconds) Create a newTikaHttpClientwith a daemon-thread executor.voidclose()GETurland return the response body as a string.POST a JSON body tourland return the response body as a string.
-
Method Details
-
build
Create a newTikaHttpClientwith 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, TikaExceptionPOST a JSON body tourland return the response body as a string.- Parameters:
url- target URLjsonBody- request body (UTF-8 JSON)headers- additional HTTP headers (e.g.Authorization)timeoutSeconds- read timeout;0uses the default timeout- Returns:
- response body string
- Throws:
IOException- on network errorTikaException- on non-2xx HTTP status
-
get
public String get(String url, Map<String, String> headers, int timeoutSeconds) throws IOException, TikaExceptionGETurland return the response body as a string. Useful for health-check probes at init time.- Parameters:
url- target URLheaders- additional HTTP headerstimeoutSeconds- read timeout;0uses the default timeout- Returns:
- response body string
- Throws:
IOException- on network errorTikaException- on non-2xx HTTP status
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-