Skip to content

Commit 658aa5b

Browse files
committed
TIKA-4753 -- doc style clean up
1 parent d42acbe commit 658aa5b

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ JSON body whose shape matches the `PipesResult` status:
164164

165165
[source,json]
166166
----
167-
{"status": "TIMEOUT", "message": "Task timed out after 60000ms"}
167+
{"status": "TIMEOUT"}
168168
----
169169

170-
The `status` field is the `PipesResult.RESULT_STATUS` enum name. The `message` field is
171-
present when Tika provided one, absent otherwise.
170+
The `status` field is the `PipesResult.RESULT_STATUS` enum name. By default the body
171+
carries only the `status`. When the server is configured with `returnStackTrace=true`,
172+
a `message` field is also included (it often contains a server-side stack trace), e.g.
173+
`{"status": "TIMEOUT", "message": "Task timed out after 60000ms"}`.
172174

173175
[cols="1,1,3"]
174176
|===
@@ -190,8 +192,8 @@ document on the same server is unlikely to succeed without a configuration fix.
190192

191193
NOTE: A successful parse that encountered internal parser errors (e.g. a truncated
192194
embedded document) still returns `200 OK`. The partial-parse exception is surfaced
193-
in the `X-TIKA:CONTAINER_EXCEPTION` metadata field of the response, not as an HTTP
194-
error code.
195+
in the `X-TIKA:EXCEPTION:container_exception` metadata field of the response, not as an
196+
HTTP error code.
195197

196198
== Configuration
197199

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ private static PipesParsingHelper initPipesParsingHelper(TikaServerConfig tikaSe
510510

511511
// Create and return the helper
512512
PipesParsingHelper helper = new PipesParsingHelper(pipesParser, pipesConfig,
513-
inputTempDirectory, unpackTempDirectory);
513+
inputTempDirectory, unpackTempDirectory, tikaServerConfig.isReturnStackTrace());
514514

515515
// Register shutdown hook to clean up PipesParser and temp directories
516516
final Path inputDirToClean = inputTempDirectory;

tika-server/tika-server-core/src/main/java/org/apache/tika/server/core/resource/PipesParsingHelper.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class PipesParsingHelper {
7070
private final PipesConfig pipesConfig;
7171
private final Path inputTempDirectory;
7272
private final Path unpackEmitterBasePath;
73+
private final boolean returnStackTrace;
7374

7475
/**
7576
* Creates a PipesParsingHelper.
@@ -81,13 +82,19 @@ public class PipesParsingHelper {
8182
* @param unpackEmitterBasePath the basePath where the unpack-emitter writes files.
8283
* This is where the server will find the zip files created
8384
* by UNPACK mode. May be null if UNPACK mode won't be used.
85+
* @param returnStackTrace whether failure responses may include the (potentially
86+
* stack-trace-bearing) {@code PipesResult} message. When false
87+
* (the default), error bodies carry only the status. Mirrors
88+
* {@code TikaServerConfig.isReturnStackTrace()}.
8489
*/
8590
public PipesParsingHelper(PipesParser pipesParser, PipesConfig pipesConfig,
86-
Path inputTempDirectory, Path unpackEmitterBasePath) {
91+
Path inputTempDirectory, Path unpackEmitterBasePath,
92+
boolean returnStackTrace) {
8793
this.pipesParser = pipesParser;
8894
this.pipesConfig = pipesConfig;
8995
this.inputTempDirectory = inputTempDirectory;
9096
this.unpackEmitterBasePath = unpackEmitterBasePath;
97+
this.returnStackTrace = returnStackTrace;
9198

9299
if (inputTempDirectory == null || !Files.isDirectory(inputTempDirectory)) {
93100
throw new IllegalArgumentException(
@@ -189,18 +196,21 @@ private String getSuffix(Metadata metadata) {
189196

190197
/**
191198
* Builds a JSON error response carrying a subset of the {@code PipesResult}
192-
* serialization — the {@code status} and, when present, a non-blank {@code message}:
193-
* {@code {"status": "TIMEOUT", "message": "..."}}. Successful-parse fields such as
194-
* {@code emitData} are never part of an error body.
199+
* serialization. By default the body is just {@code {"status": "TIMEOUT"}}. The
200+
* {@code PipesResult} message frequently contains a server-side stack trace
201+
* (e.g. for {@code *_EXCEPTION} statuses), so the {@code message} field is included
202+
* only when {@code returnStackTrace} is enabled — matching the legacy
203+
* {@code TikaServerParseExceptionMapper}, which gates stack traces the same way.
204+
* Successful-parse fields such as {@code emitData} are never part of an error body.
195205
* <p>
196206
* This allows clients to distinguish failure modes (TIMEOUT, OOM, UNSPECIFIED_CRASH, …)
197207
* without parsing plain-text bodies or inspecting custom headers.
198208
*/
199-
private static Response buildProcessFailureResponse(PipesResult result) {
209+
private Response buildProcessFailureResponse(PipesResult result) {
200210
ObjectMapper mapper = new ObjectMapper();
201211
ObjectNode node = mapper.createObjectNode();
202212
node.put("status", result.status().name());
203-
if (result.message() != null && !result.message().isBlank()) {
213+
if (returnStackTrace && result.message() != null && !result.message().isBlank()) {
204214
node.put("message", result.message());
205215
}
206216
String json;

tika-server/tika-server-core/src/test/java/org/apache/tika/server/core/CXFTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public void setUp() throws Exception {
214214
pipesConfig.setEmitStrategy(new EmitStrategyConfig(EmitStrategy.PASSBACK_ALL));
215215
this.pipesParser = PipesParser.load(tikaJsonConfig, pipesConfig, this.pipesConfigPath);
216216
PipesParsingHelper pipesParsingHelper = new PipesParsingHelper(this.pipesParser, pipesConfig,
217-
inputTempDirectory, getUnpackEmitterBasePath());
217+
inputTempDirectory, getUnpackEmitterBasePath(), false);
218218

219219
TikaResource.init(tika, new ServerStatus(), pipesParsingHelper, isEnableUnsecureFeatures());
220220
} finally {

0 commit comments

Comments
 (0)