|
32 | 32 | import java.util.Iterator; |
33 | 33 | import java.util.Map; |
34 | 34 | import java.util.Set; |
| 35 | +import java.util.TreeSet; |
35 | 36 |
|
36 | 37 | import com.fasterxml.jackson.core.JacksonException; |
37 | 38 | import com.fasterxml.jackson.core.JsonParser; |
|
49 | 50 |
|
50 | 51 | public class FetchEmitTupleDeserializer extends JsonDeserializer<FetchEmitTuple> { |
51 | 52 |
|
| 53 | + /** The parse-context name InlineBytes was registered under in 4.0.0. */ |
| 54 | + static final String LEGACY_INLINE_BYTES_ENTRY = "inline-bytes"; |
| 55 | + |
52 | 56 | private static final Set<String> KNOWN_KEYS = Set.of( |
53 | 57 | ID, FETCHER, FETCH_KEY, EMITTER, EMIT_KEY, FETCH_RANGE_START, FETCH_RANGE_END, |
54 | 58 | METADATA_KEY, PARSE_CONTEXT, ON_PARSE_EXCEPTION); |
@@ -80,6 +84,20 @@ public static FetchEmitTupleDeserializer internal() { |
80 | 84 | @Override |
81 | 85 | public FetchEmitTuple deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException { |
82 | 86 | JsonNode root = jsonParser.readValueAsTree(); |
| 87 | + // Both checked before rejectUnknownKeys so they get tailored messages. |
| 88 | + if (root.has(PipesRequest.INLINE_BYTES)) { |
| 89 | + throw new IOException("'" + PipesRequest.INLINE_BYTES |
| 90 | + + "' is not a FetchEmitTuple field; content travels outside the tuple, and" |
| 91 | + + " only on the host's internal IPC. For tika-server, PUT content you" |
| 92 | + + " already hold to /tika or /rmeta, which inline it for you."); |
| 93 | + } |
| 94 | + if (root.path(PARSE_CONTEXT).has(LEGACY_INLINE_BYTES_ENTRY)) { |
| 95 | + // 4.0.0 serialized this entry; the generic "check for a typo" would mislead upgraders. |
| 96 | + throw new IOException("'" + LEGACY_INLINE_BYTES_ENTRY + "' is no longer a serializable" |
| 97 | + + " parse-context entry (4.0.0 wrote it as base64): content travels outside" |
| 98 | + + " the tuple, and only on the host's internal IPC. For tika-server, PUT" |
| 99 | + + " content you already hold to /tika or /rmeta, which inline it for you."); |
| 100 | + } |
83 | 101 | rejectUnknownKeys(root); |
84 | 102 |
|
85 | 103 | String id = readVal(ID, root, null, true); |
@@ -124,7 +142,7 @@ private static void rejectUnknownKeys(JsonNode root) throws IOException { |
124 | 142 | String name = it.next(); |
125 | 143 | if (!KNOWN_KEYS.contains(name)) { |
126 | 144 | throw new IOException("Unrecognized FetchEmitTuple field '" + name |
127 | | - + "'. Check for a typo; known fields are " + KNOWN_KEYS + "."); |
| 145 | + + "'. Check for a typo; known fields are " + new TreeSet<>(KNOWN_KEYS) + "."); |
128 | 146 | } |
129 | 147 | } |
130 | 148 | } |
|
0 commit comments