Class TikaResource

java.lang.Object
org.apache.tika.server.core.resource.TikaResource

@Path("/tika") public class TikaResource extends Object
  • Field Details

    • GREETING

      public static final String GREETING
  • Constructor Details

    • TikaResource

      public TikaResource(TikaLoader tikaLoader, ServerStatus serverStatus, PipesParsingHelper pipesParsingHelper, boolean allowPerRequestConfig)
      Parameters:
      tikaLoader - the Tika loader
      serverStatus - server status tracker
      pipesParsingHelper - helper for pipes-based parsing, may be null if /tika endpoint is not enabled
      allowPerRequestConfig - whether per-request config injection is permitted
  • Method Details

    • createPresetContext

      public ParseContext 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).
      Throws:
      jakarta.ws.rs.NotFoundException - if no preset has this name
    • getPipesParsingHelper

      public PipesParsingHelper getPipesParsingHelper()
      Gets the PipesParsingHelper instance.
      Returns:
      the helper
    • getExceptionReporting

      public ExceptionReporting getExceptionReporting()
      The config's exception-reporting policy, for channels that have no ParseContext.
    • createRequestContext

      public ParseContext createRequestContext()
      Creates a ParseContext holding only what this request itself specifies.

      Config-level parse-context defaults 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

      public Metadata 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

      public UnpackConfig newConfigUnpackConfig()
      A fresh copy of the config's unpack-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

      public TikaLoader getTikaLoader()
    • detectFilename

      public static String detectFilename(jakarta.ws.rs.core.MultivaluedMap<String,String> httpHeaders)
    • 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 string
      context - the ParseContext to merge into
      Throws:
      IOException - if parsing fails
      TikaConfigException
    • fillMetadata

      public static void fillMetadata(Parser parser, Metadata metadata, jakarta.ws.rs.core.MultivaluedMap<String,String> httpHeaders)
    • 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 attachments
      metadata - metadata to populate with filename and content-type
      context - 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 fails
      TikaConfigException
    • parseWithPipes

      public List<Metadata> parseWithPipes(TikaInputStream tis, Metadata metadata, ParseContext parseContext, ParseMode parseMode) throws IOException
      Throws:
      IOException
    • logRequest

      public static void logRequest(org.slf4j.Logger logger, String endpoint, Metadata metadata)
    • setupContentHandlerFactory

      public void setupContentHandlerFactory(ParseContext context, String handlerTypeName)
      Sets up the ContentHandlerFactory in the ParseContext, taking the write limits from OutputLimits in the context.
      Parameters:
      context - the ParseContext to configure
      handlerTypeName - the handler type name (text, html, xml, ignore), may be null for default
    • setupContentHandlerFactoryIfNeeded

      public void setupContentHandlerFactoryIfNeeded(ParseContext context, String handlerTypeName)
      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 configure
      handlerTypeName - the handler type name
    • getMessage

      @GET @Produces("text/plain;charset=UTF-8") public String 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 @Produces is 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:
      IOException
      TikaConfigException
    • 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:
      IOException
      TikaConfigException
    • 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:
      IOException
      TikaConfigException
    • 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:
      IOException
      TikaConfigException
    • 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:
      IOException
      TikaConfigException
    • 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:
      IOException
      TikaConfigException
    • 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 of PUT /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:
      IOException
      TikaConfigException