Class TikaResource
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTikaResource(TikaLoader tikaLoader, ServerStatus serverStatus, PipesParsingHelper pipesParsingHelper, boolean allowPerRequestConfig) -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyExplicitFormat(ParseContext context, String handlerTypeName, boolean explicitFormat) Binds the format named by an explicit path segment, refusing the request if the config part named a handler too.createPresetContext(String presetName) A request context carrying only the preset selection: the forked worker resolves the content from its own copy of this config at config-tier trust, so a preset is never treated as caller-supplied wire data (which would screen out wire-blocked components and clamp its timeouts).Creates 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.ResponsegetDefaultWithPreset(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders, String presetName) As the bare /tika endpoint, with the named preset applied.The config's exception-reporting policy, for channels that have no ParseContext.jakarta.ws.rs.core.ResponsegetHtml(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return HTML content.jakarta.ws.rs.core.ResponsegetHtmlWithPreset(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders, String presetName) As /tika/html, with the named preset applied.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).getJsonDefaultWithPreset(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders, String presetName) As /tika/json, with the named preset applied.getJsonWithPreset(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders, String presetName, String handlerTypeName) As /tika/json/{handlerType}, with the named preset applied.jakarta.ws.rs.core.ResponsegetMarkdown(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return Markdown content.jakarta.ws.rs.core.ResponsegetMarkdownWithPreset(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders, String presetName) As /tika/md, with the named preset applied.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.ResponsegetTextWithPreset(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders, String presetName) As /tika/text, with the named preset applied.jakarta.ws.rs.core.ResponsegetXml(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders) Parse document and return XML content.jakarta.ws.rs.core.ResponsegetXmlWithPreset(InputStream is, jakarta.ws.rs.core.HttpHeaders httpHeaders, String presetName) As /tika/xml, with the named preset applied.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) 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
-
createPresetContext
A request context carrying only the preset selection: the forked worker resolves the content from its own copy of this config at config-tier trust, so a preset is never treated as caller-supplied wire data (which would screen out wire-blocked components and clamp its timeouts).- Throws:
jakarta.ws.rs.NotFoundException- if no preset has this name
-
getPipesParsingHelper
Gets the PipesParsingHelper instance.- Returns:
- the helper
-
getExceptionReporting
The config's exception-reporting policy, for channels that have no ParseContext. -
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 - Throws:
IOException
-
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
-
getDefaultWithPreset
@PUT @Consumes("*/*") @Produces("text/plain;charset=UTF-8") @Path("preset/{presetName}") public jakarta.ws.rs.core.Response getDefaultWithPreset(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("presetName") String presetName) throws IOException As the bare /tika endpoint, with the named preset applied. A factory the preset binds decides the output format here; without one the Markdown default applies.- Throws:
IOException
-
getTextWithPreset
@PUT @Consumes("*/*") @Produces("text/plain;charset=UTF-8") @Path("preset/{presetName}/text") public jakarta.ws.rs.core.Response getTextWithPreset(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("presetName") String presetName) throws IOException As /tika/text, with the named preset applied.- Throws:
IOException
-
getHtmlWithPreset
@PUT @Consumes("*/*") @Produces("text/html;charset=UTF-8") @Path("preset/{presetName}/html") public jakarta.ws.rs.core.Response getHtmlWithPreset(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("presetName") String presetName) throws IOException As /tika/html, with the named preset applied.- Throws:
IOException
-
getXmlWithPreset
@PUT @Consumes("*/*") @Produces("text/xml;charset=UTF-8") @Path("preset/{presetName}/xml") public jakarta.ws.rs.core.Response getXmlWithPreset(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("presetName") String presetName) throws IOException As /tika/xml, with the named preset applied.- Throws:
IOException
-
getMarkdownWithPreset
@PUT @Consumes("*/*") @Produces("text/plain;charset=UTF-8") @Path("preset/{presetName}/md") public jakarta.ws.rs.core.Response getMarkdownWithPreset(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("presetName") String presetName) throws IOException As /tika/md, with the named preset applied.- Throws:
IOException
-
getJsonDefaultWithPreset
@PUT @Consumes("*/*") @Produces("application/json") @Path("preset/{presetName}/json") public Metadata getJsonDefaultWithPreset(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("presetName") String presetName) throws IOException As /tika/json, with the named preset applied.- Throws:
IOException
-
getJsonWithPreset
@PUT @Consumes("*/*") @Produces("application/json") @Path("preset/{presetName}/json/{handler}") public Metadata getJsonWithPreset(InputStream is, @Context jakarta.ws.rs.core.HttpHeaders httpHeaders, @PathParam("presetName") String presetName, @PathParam("handler") String handlerTypeName) throws IOException As /tika/json/{handlerType}, with the named preset applied.- Throws:
IOException
-
applyExplicitFormat
public void applyExplicitFormat(ParseContext context, String handlerTypeName, boolean explicitFormat) Binds the format named by an explicit path segment, refusing the request if the config part named a handler too. Silently picking either one is worse than a 400: the route's@Producesis fixed by the segment, so letting the config part win makes /tika/config/xml answer text/xml with a markdown body. Any factory in the context at this point came from the config part -- createRequestContext carries request deltas only. -
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
-