Skip to content

TIKA-5025: Set the server block's fields from the command line and environment (TIKA_SERVER_SETTING_<FIELD>) - #3519

Merged
tballison merged 4 commits into
apache:mainfrom
dschmidt:TIKA-5025-server-env
Nov 5, 2026
Merged

tballison merged 4 commits into
apache:mainfrom
dschmidt:TIKA-5025-server-env

Conversation

@dschmidt

@dschmidt dschmidt commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

The fields of the config's server block (maxRequestSizeBytes, maxRequestReadMillis, maxInFlightRequestBytes, idleTimeoutMillis, allowHttp2, cors, ...) can only be set in the config file. In the Docker image that means mounting a file and passing -c for a single number, for example to raise the 1 GiB request body limit for large audio or video files.

tika-server now also takes --serverSetting <field>=<value> (repeatable) and the environment variable TIKA_SERVER_SETTING_<FIELD>, the field's name in upper snake case:

java -jar tika-server-standard-X.Y.Z.jar --serverSetting maxRequestSizeBytes=4294967296
docker run -e TIKA_SERVER_SETTING_MAX_REQUEST_SIZE_BYTES=4294967296 apache/tika:X.Y.Z-full

Every field of the block is covered the same way, so nothing has to be added per field.

The prefix is TIKA_SERVER_SETTING_ rather than TIKA_SERVER_ because Kubernetes gives every pod TIKA_SERVER_PORT=tcp://..., TIKA_SERVER_SERVICE_HOST and more for a Service named tika-server; with the shorter prefix those would set the port to a URL or name an unknown field, and an existing deployment would stop starting on upgrade. The test puts those variables into the environment and expects them ignored.

Implementation: TikaServerConfig.load collects the option values and the matching environment variables, logs each with its source (and the file value it replaces, if any), and applies them to the TikaServerConfig with Jackson's readerForUpdating after the file's server block has been deserialized. Because that is the same binding the file goes through, the field's own setter checks the value (e.g. requestLogLevel must be one of 'debug' or 'info'), a value of the wrong type is reported with the variable's name and value, and an unknown field fails startup with the list of fields that exist. Precedence: option over variable over file; -p, -h, -i and --metricsPort still override everything as before. configPath is refused with a pointer to -c. tlsConfig and endpoints take an object and a list and remain file-only. Only the front end reads the server block, so the forked workers' config is untouched.

The 413 response body now names the limit and how to raise it: Request body exceeds maxRequestSizeBytes (1073741824 bytes); raise it in the config's server block or with TIKA_SERVER_SETTING_MAX_REQUEST_SIZE_BYTES, for a declared Content-Length and a chunked body alike.

Tests: TikaServerConfigTest covers parsing of option and variable, precedence, overriding a file value, the error messages and the name mapping. ServerSettingsIntegrationTest starts the real server with TIKA_SERVER_SETTING_MAX_REQUEST_SIZE_BYTES=10 and with --serverSetting, checks the 413 and its hint, and that an unknown field fails startup.

Docs: server page (options table, configuration section), Docker page, CHANGES.

Open question: the option is a generic --serverSetting <field>=<value> because commons-cli needs options registered up front. A generated --<field> option per setter would be possible if that is preferred. Values are plain numbers, no 4g style suffixes.

https://issues.apache.org/jira/browse/TIKA-5025

…vironment

tika-server takes --serverSetting <field>=<value> (repeatable) and
TIKA_SERVER_<FIELD> (TIKA_SERVER_MAX_REQUEST_SIZE_BYTES), bound through
the same Jackson path as the config file, so the setter checks the value
and an unknown field fails startup. Option over variable over file. The
413 names the limit and where to raise it.
@dschmidt
dschmidt marked this pull request as ready for review November 3, 2026 11:34
Kubernetes gives every pod TIKA_SERVER_PORT=tcp://..., TIKA_SERVER_SERVICE_HOST
and more for a Service named tika-server; with TIKA_SERVER_ as the prefix
those would set the port to a URL or name an unknown field, and the server
would stop starting on upgrade with no config change. The prefix is
TIKA_SERVER_SETTING_ now, the test puts those variables into the environment,
and the javadoc and the docs say why the prefix is this long.
@dschmidt

dschmidt commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Good catch, thanks. The prefix is TIKA_SERVER_SETTING_ now (ab1f350); the test puts TIKA_SERVER_PORT=tcp://..., TIKA_SERVER_SERVICE_HOST and TIKA_SERVER_PORT_9998_TCP_ADDR into the environment and expects them ignored, and the docs say why the prefix is this long. Unknown fields under the new prefix still fail startup, since nothing but an operator writes them.

@dschmidt
dschmidt force-pushed the TIKA-5025-server-env branch from ab1f350 to 28dd01a Compare November 4, 2026 16:10
@tballison

Copy link
Copy Markdown
Contributor

Only nits from by 🤖 . Let me know what you think

Edge cases (worth fixing):
  1. An option silently cancels a setting in Docker. The Docker entrypoint always passes -h 0.0.0.0. So
     TIKA_SERVER_SETTING_HOST=127.0.0.1 is logged as "set by TIKA_SERVER_SETTING_HOST", and then -h replaces it with
     no message. My probe got host=0.0.0.0. The same happens with PORT against -p, ID against -i and METRICS_PORT
     against --metricsPort. A user who tries to narrow the bind address gets the wider one. Cheapest fix: fail at
     startup, or at least warn, when an option and a setting name the same field.
  2. Text values are mangled. The PR converts any value that looks like a number into a number before binding, so
     TIKA_SERVER_SETTING_ID=007 becomes id 7, and the same would happen with cors or host. Passing every value as a
     plain string fixes this: Jackson already converts strings to long and boolean. My probes showed it rejects "1.5"
     for an int field and accepts "TRUE". That also removes the valueNode helper and its 18-digit regex.
  3. Two variables can name the same field. ALLOW_PIPES and ALLOW__PIPES both become allowPipes. The first one read
     wins, and the environment's order isn't defined, so which value applies is arbitrary and nothing says so. Fix:
     refuse two sources for the same field at the same level.
  4. TIKA_SERVER_SETTING_PRESETS is accepted and then thrown away. Startup succeeds and the presets list is empty. It
     should be refused with a pointer to TIKA_PRESETS, the way configPath is already refused with a pointer to -c.

  Minor clean-ups:
  - The PR title and the first commit message still say TIKA_SERVER_<FIELD>. A squash merge would put the wrong
    variable name in the history.
  - The server docs open with "Every field can also be set", then exclude tlsConfig and endpoints a few lines later.
    Saying "every field except tlsConfig and endpoints" up front would be clearer.

@dschmidt dschmidt changed the title TIKA-5025: Set the server block's fields from the command line and environment (TIKA_SERVER_<FIELD>) TIKA-5025: Set the server block's fields from the command line and environment (TIKA_SERVER_SETTING_<FIELD>) Nov 4, 2026
@dschmidt

dschmidt commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all four fixed in f48b1a6: a setting and -h/-p/-i/--metricsPort for the same field now fail startup naming both; values go to Jackson as strings, so 007 stays 007; two options or two variables for the same field are refused; presets, tlsConfig and endpoints are refused with a pointer to where they are set, like configPath. The docs put the exceptions up front and mention that TIKA_SERVER_SETTING_HOST fails in the Docker image because of its -h 0.0.0.0.

@tballison
tballison merged commit 82141b6 into apache:main Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants