Skip to content

Commit 9753c8a

Browse files
authored
TIKA-4809 stage 5
2 parents 2a59ed2 + 87747b3 commit 9753c8a

5 files changed

Lines changed: 33 additions & 132 deletions

File tree

docs/modules/ROOT/pages/using-tika/server/index.adoc

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@ The server starts on `localhost:9998` by default.
9292
|`-c <file>` or `--config <file>`
9393
|Path to `tika-config.json`. See <<_configuration,Configuration>> below.
9494

95-
|`-a <file>` or `--pluginsConfig <file>`
96-
|Path to the Tika Pipes plugins configuration file.
97-
9895
|`-i <id>` or `--id <id>`
99-
|Server ID, surfaced in the `/status` endpoint and in logs.
96+
|Server ID, written to the startup log. Defaults to a random UUID.
10097

10198
|`-?` or `--help`
10299
|Print the usage message.
@@ -171,7 +168,7 @@ curl -T document.pdf http://localhost:9998/meta/Content-Type # single field
171168
=== Other endpoints
172169

173170
* `/version` — server version
174-
* `/status` — health/status (includes server ID)
171+
* `/status` — health/status: state, active task count, files processed
175172
* `/parsers` and `/parsers/details` — registered parsers
176173
* `/detectors` — registered detectors
177174
* `/mime-types` — known MIME types
@@ -311,23 +308,18 @@ Server behavior beyond host/port is controlled by a JSON config file passed via
311308
|`false`
312309
|Include parser stack traces in error responses. Useful in dev, dangerous in production (leaks internals).
313310

314-
|`digest`
315-
|`""` (off)
316-
|Compute a digest of the parsed bytes. Comma-separated algorithm names: `md5`, `sha1`, `sha256`, `sha384`, `sha512`.
317-
318-
|`digestMarkLimit`
319-
|`20971520` (20 MiB)
320-
|Max bytes buffered for digest computation.
321-
322311
|`logLevel`
323312
|_inherited_
324313
|`debug` or `info` to override the runtime log level.
325314

326-
|`idBase`
315+
|`id`
327316
|random UUID
328-
|Override the auto-generated server ID (the `-i` CLI flag is the same setting).
317+
|Override the auto-generated server ID, which is written to the startup log (the `-i` CLI flag is the same setting).
329318
|===
330319

320+
NOTE: Digests are configured in `parse-context`, not in the `server` section. See
321+
xref:configuration/digesters.adoc[Digesters].
322+
331323
For the full Pipes-related sections (`pipes`, `fetchers`, `emitters`, `parse-context`)
332324
that tika-server 4.x requires, see
333325
xref:migration-to-4x/migrating-tika-server-4x.adoc#_configuration_changes[Configuration Changes].

tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/TikaServerCli.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ private static Options getOptions() {
4343
"listen port (default = 9998)\n");
4444
options.addOption("?", "help", false, "this help message");
4545
options.addOption("c", "config", true, "tika-config file");
46-
options.addOption("a", "pluginsConfig", true, "tike pipes config");
47-
4846
options.addOption("i", "id", true, "id to use for server in" + " the server status endpoint and logging");
4947
return options;
5048
}
@@ -69,7 +67,7 @@ public static void main(String[] args) {
6967
private static void usage(Options options) throws IOException {
7068
HelpFormatter helpFormatter = HelpFormatter.builder().get();
7169
helpFormatter.printHelp("tikaserver", null, options, null, true);
72-
System.exit(-1);
70+
System.exit(0);
7371
}
7472

7573
}

tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/TikaServerConfig.java

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public class TikaServerConfig {
3939

4040
public static final int DEFAULT_PORT = 9998;
4141
public static final String DEFAULT_HOST = "localhost";
42-
public static final Set<String> LOG_LEVELS = new HashSet<>(Arrays.asList("debug", "info"));
4342
private static final Logger LOG = LoggerFactory.getLogger(TikaServerConfig.class);
44-
private static final int DEFAULT_DIGEST_MARK_LIMIT = 20 * 1024 * 1024;
4543
/**
4644
* Endpoints that expose the pipes/fetch machinery (process-isolated pipes
4745
* parsing and async batch processing). Selecting any of these requires
@@ -71,20 +69,15 @@ public class TikaServerConfig {
7169
private boolean allowPerRequestConfig = false;
7270
private String cors = "";
7371
private boolean returnStackTrace = false;
74-
private String idBase = UUID
72+
private String id = UUID
7573
.randomUUID()
7674
.toString();
7775
private int port = DEFAULT_PORT;
7876
private String host = DEFAULT_HOST;
79-
private int digestMarkLimit = DEFAULT_DIGEST_MARK_LIMIT;
80-
private String digest = "";
81-
//debug or info only
82-
private String logLevel = "";
77+
private String requestLogLevel = "";
8378
private Path configPath;
8479
private ArrayList<String> endpoints = new ArrayList<>();
8580

86-
private boolean preventStopMethod = false;
87-
8881
private TlsConfig tlsConfig = new TlsConfig();
8982

9083
/**
@@ -98,7 +91,6 @@ public static TikaServerConfig load(CommandLine commandLine) throws IOException,
9891

9992
TikaServerConfig config = null;
10093
Set<String> settings = new HashSet<>();
101-
Path pluginsConfig = null;
10294

10395
if (commandLine.hasOption("c")) {
10496
config = load(Paths.get(commandLine.getOptionValue("c")), commandLine, settings);
@@ -144,10 +136,6 @@ public void setPort(int port) {
144136
this.port = port;
145137
}
146138

147-
public String getIdBase() {
148-
return idBase;
149-
}
150-
151139
/**
152140
* Whether the pipes/fetch endpoints ({@code pipes}, {@code async}) may be
153141
* enabled. Off by default; selecting one of those endpoints without this set
@@ -210,15 +198,19 @@ public void setHost(String host) {
210198
this.host = host;
211199
}
212200

213-
public String getLogLevel() {
214-
return logLevel;
201+
/**
202+
* Severity at which each request URI is logged. Empty (the default) disables
203+
* request logging entirely; this does not change the log level of anything else.
204+
*/
205+
public String getRequestLogLevel() {
206+
return requestLogLevel;
215207
}
216208

217-
public void setLogLevel(String level) throws TikaConfigException {
209+
public void setRequestLogLevel(String level) throws TikaConfigException {
218210
if (level.equals("debug") || level.equals("info")) {
219-
this.logLevel = level;
211+
this.requestLogLevel = level;
220212
} else {
221-
throw new TikaConfigException("log level must be one of: 'debug' or 'info'");
213+
throw new TikaConfigException("requestLogLevel must be one of: 'debug' or 'info'");
222214
}
223215
}
224216

@@ -237,37 +229,17 @@ public boolean hasConfigFile() {
237229
return configPath != null;
238230
}
239231

232+
@com.fasterxml.jackson.annotation.JsonIgnore
240233
public Path getConfigPath() {
241234
return configPath;
242235
}
243236

237+
/** Set from the -c argument at load time; not a user-settable config key. */
238+
@com.fasterxml.jackson.annotation.JsonIgnore
244239
public void setConfigPath(String path) {
245240
this.configPath = Paths.get(path);
246241
}
247242

248-
public int getDigestMarkLimit() {
249-
return digestMarkLimit;
250-
}
251-
252-
public void setDigestMarkLimit(int digestMarkLimit) {
253-
this.digestMarkLimit = digestMarkLimit;
254-
}
255-
256-
/**
257-
* digest configuration string, e.g. md5 or sha256, alternately w 16 or 32 encoding,
258-
* e.g. md5:32,sha256:16 would result in two digests per file
259-
*
260-
* @return
261-
*/
262-
public String getDigest() {
263-
return digest;
264-
}
265-
266-
public void setDigest(String digest) {
267-
LOG.info("As of Tika 2.5.0, you can set the digester via the AutoDetectParserConfig in " + "tika-config.xml. We plan to remove this commandline option in 2.8.0");
268-
this.digest = digest;
269-
}
270-
271243
public boolean isReturnStackTrace() {
272244
return returnStackTrace;
273245
}
@@ -292,13 +264,15 @@ public void setEndpoints(ArrayList<String> endpoints) {
292264
this.endpoints = endpoints;
293265
}
294266

267+
/**
268+
* Identifier for this server, surfaced in the startup log. Defaults to a random UUID.
269+
*/
295270
public String getId() {
296-
//TODO fix this
297-
return idBase;
271+
return id;
298272
}
299273

300274
public void setId(String id) {
301-
this.idBase = id;
275+
this.id = id;
302276
}
303277

304278
private void addEndPoints(List<String> endPoints) {

tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/TikaServerProcess.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@
2222
import java.nio.file.Path;
2323
import java.security.GeneralSecurityException;
2424
import java.util.ArrayList;
25-
import java.util.Arrays;
2625
import java.util.Collection;
2726
import java.util.Collections;
2827
import java.util.HashMap;
29-
import java.util.HashSet;
3028
import java.util.List;
3129
import java.util.Map;
32-
import java.util.Set;
3330

3431
import org.apache.commons.cli.CommandLine;
3532
import org.apache.commons.cli.CommandLineParser;
@@ -100,7 +97,6 @@
10097
public class TikaServerProcess {
10198

10299

103-
public static final Set<String> LOG_LEVELS = new HashSet<>(Arrays.asList("debug", "info"));
104100
public static final int BIND_EXCEPTION = 42;
105101
private static final Logger LOG = LoggerFactory.getLogger(TikaServerProcess.class);
106102
public static int DO_NOT_RESTART_EXIT_VALUE = -100;
@@ -110,7 +106,6 @@ private static Options getOptions() {
110106
options.addOption("h", "host", true, "host name, use * for all)");
111107
options.addOption("p", "port", true, "listen port");
112108
options.addOption("c", "config", true, "Tika Configuration xml file to override default config with.");
113-
options.addOption("a", "pluginsConfig", true, "Tika Configuration json for pluginscomponents");
114109
options.addOption("i", "id", true, "id to use for server in server status endpoint");
115110
options.addOption("?", "help", false, "this help message");
116111
return options;
@@ -232,6 +227,7 @@ private static ServerDetails initServer(TikaServerConfig tikaServerConfig) throw
232227
ServerDetails details = new ServerDetails();
233228
details.sf = sf;
234229
details.url = url;
230+
details.serverId = tikaServerConfig.getId();
235231
details.serverStatus = serverStatus;
236232
return details;
237233
}
@@ -315,16 +311,12 @@ private static void loadAllProviders(TikaServerConfig tikaServerConfig, ServerSt
315311
// Add ConfigEndpointSecurityFilter to gate /config endpoints
316312
writers.add(new ConfigEndpointSecurityFilter(tikaServerConfig.isAllowPerRequestConfig()));
317313

314+
// setRequestLogLevel rejects anything but debug/info, so no validation needed here.
318315
TikaLoggingFilter logFilter = null;
319-
if (!StringUtils.isBlank(tikaServerConfig.getLogLevel())) {
320-
String logLevel = tikaServerConfig.getLogLevel();
321-
if (LOG_LEVELS.contains(logLevel)) {
322-
boolean isInfoLevel = "info".equals(logLevel);
323-
logFilter = new TikaLoggingFilter(isInfoLevel);
324-
writers.add(logFilter);
325-
} else {
326-
LOG.warn("Unsupported request URI log level: {}", logLevel);
327-
}
316+
String requestLogLevel = tikaServerConfig.getRequestLogLevel();
317+
if (!StringUtils.isBlank(requestLogLevel)) {
318+
logFilter = new TikaLoggingFilter("info".equals(requestLogLevel));
319+
writers.add(logFilter);
328320
}
329321

330322
CrossOriginResourceSharingFilter corsFilter = null;

tika-server/tika-server-core/src/main/resources/tika-server-config-default.xml

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)