Class TikaResource
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTikaResource(TikaLoader tikaLoader, ServerStatus serverStatus, PipesParsingHelper pipesParsingHelper, boolean allowPerRequestConfig) -
Method Summary
Modifier and TypeMethodDescriptionCreates a ParseContext holding only what this request itself specifies.static StringdetectFilename(jakarta.ws.rs.core.MultivaluedMap<String, String> httpHeaders) static voidfillMetadata(Parser parser, Metadata metadata, jakarta.ws.rs.core.MultivaluedMap<String, String> httpHeaders) jakarta.ws.rs.core.ResponsegetDefault(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return Markdown content.jakarta.ws.rs.core.ResponsegetHtml(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return HTML content.getJson(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders, String handlerTypeName) Parse document and return JSON with metadata and the named handler's content.getJsonDefault(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return JSON with metadata and Markdown content (the default handler).jakarta.ws.rs.core.ResponsegetMarkdown(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return Markdown content.Gets the PipesParsingHelper instance.jakarta.ws.rs.core.ResponsegetText(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return body-only plain text.jakarta.ws.rs.core.ResponsegetXml(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return XML content.static voidlogRequest(org.slf4j.Logger logger, String endpoint, Metadata metadata) static voidmergeParseContextFromConfig(String configJson, ParseContext context) Parses config JSON and merges parseContext entries into the provided ParseContext.A fresh copy of the config'sunpack-config, or null if none is declared.Creates request metadata bounded by the config's metadata write limiter.parseWithPipes(TikaInputStream tis, Metadata metadata, ParseContext parseContext, ParseMode parseMode) Parses using pipes-based parsing with process isolation.jakarta.ws.rs.core.ResponsepostHtml(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, jakarta.ws.rs.core.HttpHeaders httpHeaders) Multipart document with optional config; returns HTML.postJson(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, jakarta.ws.rs.core.HttpHeaders httpHeaders) Multipart document with optional config; returns JSON with the default (markdown) handler.postJsonWithHandler(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, jakarta.ws.rs.core.HttpHeaders httpHeaders, String handlerTypeName) Multipart sibling ofPUT /tika/json/{handlerType}.jakarta.ws.rs.core.ResponsepostMarkdown(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, jakarta.ws.rs.core.HttpHeaders httpHeaders) Multipart document with optional config; returns Markdown.jakarta.ws.rs.core.ResponsepostRaw(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, jakarta.ws.rs.core.HttpHeaders httpHeaders) Multipart document with optional config; returns Markdown unless the config names a handler.jakarta.ws.rs.core.ResponsepostText(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, jakarta.ws.rs.core.HttpHeaders httpHeaders) Multipart document with optional config; returns body-only plain text.jakarta.ws.rs.core.ResponsepostXml(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, jakarta.ws.rs.core.HttpHeaders httpHeaders) Multipart document with optional config; returns XML.voidsetupContentHandlerFactory(ParseContext context, String handlerTypeName) Sets up the ContentHandlerFactory in the ParseContext, taking the write limits fromOutputLimitsin the context.voidsetupContentHandlerFactoryIfNeeded(ParseContext context, String handlerTypeName) Sets up the ContentHandlerFactory in the ParseContext if not already set.setupMultipartConfig(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, Metadata metadata, ParseContext context) Processes multipart attachments for /config endpoints.
-
Field Details
-
GREETING
-
-
Constructor Details
-
TikaResource
public TikaResource(TikaLoader tikaLoader, ServerStatus serverStatus, PipesParsingHelper pipesParsingHelper, boolean allowPerRequestConfig) - Parameters:
tikaLoader- the Tika loaderserverStatus- server status trackerpipesParsingHelper- helper for pipes-based parsing, may be null if /tika endpoint is not enabledallowPerRequestConfig- whether per-request config injection is permitted
-
-
Method Details
-
getPipesParsingHelper
Gets the PipesParsingHelper instance.- Returns:
- the helper
-
createRequestContext
Creates a ParseContext holding only what this request itself specifies.Config-level
parse-contextdefaults are deliberately absent. The forked worker loads them from the same config and overlays the request on top, so sending them is redundant -- and worse than redundant at the trust boundary: the worker clamps request-supplied timeout limits but trusts its own config's, so a default that arrives as request data gets treated as caller input and clamped.- Returns:
- an empty, request-scoped ParseContext
-
newRequestMetadata
Creates request metadata bounded by the config's metadata write limiter.The limiter no longer rides in the request context, so it is applied here instead. This metadata holds caller-supplied values (filename, headers), which is exactly what the limiter is meant to bound.
-
newConfigUnpackConfig
A fresh copy of the config'sunpack-config, or null if none is declared.The unpack path is the one place a config default must still travel: it is mutated per request (zip, suffix strategy, emitter) and so overrides whatever the worker would have loaded. Starting from a default-constructed instance instead would silently reset operator settings the request never touches --
maxUnpackBytes, for one. Re-read per call because the caller mutates the result; unpack requests are heavyweight enough that the config read does not register. -
getTikaLoader
-
detectFilename
-
mergeParseContextFromConfig
public static void mergeParseContextFromConfig(String configJson, ParseContext context) throws IOException, TikaConfigException Parses config JSON and merges parseContext entries into the provided ParseContext.- Parameters:
configJson- the JSON config stringcontext- the ParseContext to merge into- Throws:
IOException- if parsing failsTikaConfigException
-
fillMetadata
-
setupMultipartConfig
public TikaInputStream setupMultipartConfig(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, Metadata metadata, ParseContext context) throws IOException, TikaConfigException Processes multipart attachments for /config endpoints. Extracts the "file" and optional "config" attachments, sets up metadata (filename, content-type) from the file attachment, and processes any config JSON into the ParseContext.- Parameters:
attachments- the multipart attachmentsmetadata- metadata to populate with filename and content-typecontext- parse context to populate from config JSON- Returns:
- TikaInputStream wrapping the file attachment's content
- Throws:
IOException- if file attachment is missing or config processing failsTikaConfigException
-
parseWithPipes
public List<Metadata> parseWithPipes(TikaInputStream tis, Metadata metadata, ParseContext parseContext, ParseMode parseMode) throws IOException Parses using pipes-based parsing with process isolation.The TikaInputStream should already be spooled to a temp file via
TikaInputStream.getPath(). The caller is responsible for closing the TikaInputStream after this method returns, which will clean up any temp files.- Parameters:
tis- the TikaInputStream to parsemetadata- metadata to pass to the parserparseContext- parse context with handler configurationparseMode- RMETA or CONCATENATE- Returns:
- list of metadata objects from parsing
- Throws:
IOException- if parsing fails
-
logRequest
-
setupContentHandlerFactory
Sets up the ContentHandlerFactory in the ParseContext, taking the write limits fromOutputLimitsin the context.- Parameters:
context- the ParseContext to configurehandlerTypeName- the handler type name (text, html, xml, ignore), may be null for default
-
setupContentHandlerFactoryIfNeeded
Sets up the ContentHandlerFactory in the ParseContext if not already set. Used when a ParseContext may already have a factory configured.- Parameters:
context- the ParseContext to configurehandlerTypeName- the handler type name
-
getMessage
-
getDefault
@PUT @Consumes("*/*") @Produces("text/plain;charset=UTF-8") public jakarta.ws.rs.core.Response getDefault(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException Parse document and return Markdown content. This is the default output of the bare /tika endpoint; use /tika/xml, /tika/html, /tika/text for the other formats.- Throws:
IOException
-
getText
@PUT @Consumes("*/*") @Produces("text/plain;charset=UTF-8") @Path("text") public jakarta.ws.rs.core.Response getText(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException Parse document and return body-only plain text.- Throws:
IOException
-
getHtml
@PUT @Consumes("*/*") @Produces("text/html;charset=UTF-8") @Path("html") public jakarta.ws.rs.core.Response getHtml(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException Parse document and return HTML content.- Throws:
IOException
-
getXml
@PUT @Consumes("*/*") @Produces("text/xml;charset=UTF-8") @Path("xml") public jakarta.ws.rs.core.Response getXml(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException Parse document and return XML content.- Throws:
IOException
-
getMarkdown
@PUT @Consumes("*/*") @Produces("text/plain;charset=UTF-8") @Path("md") public jakarta.ws.rs.core.Response getMarkdown(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException Parse document and return Markdown content.- Throws:
IOException
-
getJsonDefault
@PUT @Consumes("*/*") @Produces("application/json") @Path("json") public Metadata getJsonDefault(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException Parse document and return JSON with metadata and Markdown content (the default handler).- Throws:
IOException
-
getJson
@PUT @Consumes("*/*") @Produces("application/json") @Path("json/{handler}") public Metadata getJson(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("handler") String handlerTypeName) throws IOException Parse document and return JSON with metadata and the named handler's content.- Parameters:
handlerTypeName- content handler type: text, html, xml, body, markdown, ignore- Throws:
IOException
-
postRaw
@POST @Consumes("multipart/form-data") @Produces("text/plain;charset=UTF-8") @Path("config") public jakarta.ws.rs.core.Response postRaw(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException, TikaConfigException Multipart document with optional config; returns Markdown unless the config names a handler.- Throws:
IOExceptionTikaConfigException
-
postText
@POST @Consumes("multipart/form-data") @Produces("text/plain;charset=UTF-8") @Path("config/text") public jakarta.ws.rs.core.Response postText(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException, TikaConfigException Multipart document with optional config; returns body-only plain text.- Throws:
IOExceptionTikaConfigException
-
postHtml
@POST @Consumes("multipart/form-data") @Produces("text/html;charset=UTF-8") @Path("config/html") public jakarta.ws.rs.core.Response postHtml(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException, TikaConfigException Multipart document with optional config; returns HTML.- Throws:
IOExceptionTikaConfigException
-
postXml
@POST @Consumes("multipart/form-data") @Produces("text/xml;charset=UTF-8") @Path("config/xml") public jakarta.ws.rs.core.Response postXml(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException, TikaConfigException Multipart document with optional config; returns XML.- Throws:
IOExceptionTikaConfigException
-
postMarkdown
@POST @Consumes("multipart/form-data") @Produces("text/plain;charset=UTF-8") @Path("config/md") public jakarta.ws.rs.core.Response postMarkdown(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException, TikaConfigException Multipart document with optional config; returns Markdown.- Throws:
IOExceptionTikaConfigException
-
postJson
@POST @Consumes("multipart/form-data") @Produces("application/json") @Path("config/json") public Metadata postJson(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders) throws IOException, TikaConfigException Multipart document with optional config; returns JSON with the default (markdown) handler.- Throws:
IOExceptionTikaConfigException
-
postJsonWithHandler
@POST @Consumes("multipart/form-data") @Produces("application/json") @Path("config/json/{handler}") public Metadata postJsonWithHandler(List<org.apache.cxf.jaxrs.ext.multipart.Attachment> attachments, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("handler") String handlerTypeName) throws IOException, TikaConfigException Multipart sibling ofPUT /tika/json/{handlerType}. Without it, a POST caller who wants text-in-JSON has nowhere to go: /tika/config/text returns raw text with no metadata envelope.- Parameters:
handlerTypeName- content handler type: text, html, xml, body, markdown, ignore- Throws:
IOExceptionTikaConfigException
-