Skip to content

Commit 4e04de5

Browse files
committed
TIKA-4766: adapt to post-merge main APIs
TIKA-4794 changed HttpHeaders CONTENT_TYPE/CONTENT_LENGTH from String constants to Property and renamed the X-TIKA: metadata prefix to tk:. Use .getName() where a String key is needed and assert on TikaCoreProperties.TIKA_CONTENT instead of a hardcoded key.
1 parent 6b24523 commit 4e04de5

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

tika-grpc-mapper/src/main/java/org/apache/tika/grpc/mapper/DocumentBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static Document build(Metadata primary, String docId, String pipesStatus,
7777
}
7878

7979
// Keys the envelope maps below are consumed up front so the tagged tail never
80-
// carries them a second time. X-TIKA:content is consumed without a typed home
80+
// carries them a second time. tk:content is consumed without a typed home
8181
// yet: the reply's fields map still carries the flat content, and the structured
8282
// content tree is a planned additive follow-up -- duplicating the whole body
8383
// into `extra` as a string would defeat both.
@@ -87,7 +87,7 @@ public static Document build(Metadata primary, String docId, String pipesStatus,
8787
String contentType = primary.get(Metadata.CONTENT_TYPE);
8888
if (contentType != null && !contentType.isBlank()) {
8989
document.setContentType(contentType.trim());
90-
consumed.add(Metadata.CONTENT_TYPE);
90+
consumed.add(Metadata.CONTENT_TYPE.getName());
9191
}
9292

9393
Instant now = Instant.now();
@@ -106,7 +106,7 @@ public static Document build(Metadata primary, String docId, String pipesStatus,
106106
if (contentLength != null && !contentLength.isBlank()) {
107107
try {
108108
origin.setByteSize(Long.parseLong(contentLength.trim()));
109-
consumed.add(Metadata.CONTENT_LENGTH);
109+
consumed.add(Metadata.CONTENT_LENGTH.getName());
110110
} catch (NumberFormatException ignored) {
111111
// leave unconsumed; falls through to the tagged tail
112112
}

tika-grpc-mapper/src/test/java/org/apache/tika/grpc/mapper/DocumentBuilderTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void buildsTypedMetadataFromRealPdf() throws Exception {
5757
void mapsSourceDigestWhenThePipelineRecordedOne() {
5858
Metadata metadata = new Metadata();
5959
metadata.set(Metadata.CONTENT_TYPE, "text/plain");
60-
// Reserved X-TIKA keys only accept Property writes (TIKA-4769); this mirrors how
60+
// Reserved tk: keys only accept Property writes (TIKA-4769); this mirrors how
6161
// InputStreamDigester records the digest.
6262
metadata.set(Property.internalText(TikaCoreProperties.TIKA_META_PREFIX + "digest"
6363
+ TikaCoreProperties.NAMESPACE_PREFIX_DELIMITER + "SHA256"), "0a1b2c3d");
@@ -107,7 +107,7 @@ void envelopeKeysAndContentAreNotDuplicatedIntoTheTail() {
107107
assertEquals("text/plain", document.getContentType());
108108
assertEquals("sample.txt", document.getOrigin().getFilename());
109109
assertTrue(document.getExtraList().stream()
110-
.noneMatch(f -> f.getKey().equals(Metadata.CONTENT_TYPE)
110+
.noneMatch(f -> f.getKey().equals(Metadata.CONTENT_TYPE.getName())
111111
|| f.getKey().equals(TikaCoreProperties.RESOURCE_NAME_KEY.getName())
112112
|| f.getKey().equals(TikaCoreProperties.TIKA_CONTENT.getName())));
113113
}
@@ -143,7 +143,7 @@ void mapsContentLengthToByteSize() {
143143
Document document = DocumentBuilder.build(metadata, "d", "PARSE_SUCCESS", 1L);
144144
assertEquals(12345L, document.getOrigin().getByteSize());
145145
assertTrue(document.getExtraList().stream()
146-
.noneMatch(f -> f.getKey().equals(Metadata.CONTENT_LENGTH)));
146+
.noneMatch(f -> f.getKey().equals(Metadata.CONTENT_LENGTH.getName())));
147147
}
148148

149149
/**
@@ -159,12 +159,12 @@ void malformedContentLengthFallsThroughToTheTail() {
159159
Document document = DocumentBuilder.build(metadata, "d", "PARSE_SUCCESS", 1L);
160160
assertEquals(0L, document.getOrigin().getByteSize());
161161
assertTrue(document.getExtraList().stream()
162-
.anyMatch(f -> f.getKey().equals(Metadata.CONTENT_LENGTH)));
162+
.anyMatch(f -> f.getKey().equals(Metadata.CONTENT_LENGTH.getName())));
163163
}
164164

165165
/**
166-
* parsers_used prefers the full set (X-TIKA:Parsed-By-Full-Set) but must not come
167-
* back empty just because only X-TIKA:Parsed-By was recorded.
166+
* parsers_used prefers the full set (tk:parsed-by-full-set) but must not come
167+
* back empty just because only tk:parsed-by was recorded.
168168
*/
169169
@Test
170170
void parsersUsedFallsBackWhenFullSetIsAbsent() {

tika-grpc/src/test/java/org/apache/tika/pipes/grpc/TikaGrpcServerTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import org.apache.tika.TikaGrpc;
8080
import org.apache.tika.grpc.v2.Document;
8181
import org.apache.tika.grpc.v2.TikaV2Grpc;
82+
import org.apache.tika.metadata.TikaCoreProperties;
8283
import org.apache.tika.pipes.api.PipesResult;
8384
import org.apache.tika.pipes.fetcher.fs.FileSystemFetcher;
8485
import org.apache.tika.serialization.config.JsonConfigHelper;
@@ -425,7 +426,8 @@ public void testFetchAndParseReturnsTypedDocument(Resources resources) throws Ex
425426
.setFetchKey(fetchKey)
426427
.build());
427428
assertEquals("PARSE_SUCCESS", v1Reply.getStatus());
428-
String legacyContent = v1Reply.getFieldsMap().get("X-TIKA:content");
429+
String legacyContent = v1Reply.getFieldsMap()
430+
.get(TikaCoreProperties.TIKA_CONTENT.getName());
429431
assertNotNull(legacyContent, "v1 fields map must keep working");
430432
assertTrue(legacyContent.contains("hello typed world"));
431433

@@ -463,7 +465,7 @@ public void testFetchAndParseReturnsTypedDocument(Resources resources) throws Ex
463465
assertTrue(document.getExtraCount() > 0,
464466
"unmapped keys should survive in the tagged tail");
465467
assertTrue(document.getExtraList().stream().noneMatch(f ->
466-
f.getKey().equals("X-TIKA:content")
468+
f.getKey().equals(TikaCoreProperties.TIKA_CONTENT.getName())
467469
|| f.getKey().equals("Content-Type")
468470
|| f.getKey().equals("dc:title")),
469471
"typed/envelope keys must not duplicate into the tail");
@@ -653,7 +655,8 @@ public void onCompleted() {
653655
// v1 bi-stream replies keep the legacy fields-map contract
654656
for (FetchAndParseReply success : successes) {
655657
assertEquals("PARSE_SUCCESS", success.getStatus());
656-
assertNotNull(success.getFieldsMap().get("X-TIKA:content"),
658+
assertNotNull(success.getFieldsMap()
659+
.get(TikaCoreProperties.TIKA_CONTENT.getName()),
657660
"v1 reply should carry content in fields for " + success.getFetchKey());
658661
}
659662

0 commit comments

Comments
 (0)