@@ -63,6 +63,11 @@ public MetadataResource(TikaResource tikaResource) {
6363 protected MetadataResource () {
6464 }
6565
66+ /** For subclasses in other modules; they need it for request contexts and metadata. */
67+ protected TikaResource getTikaResource () {
68+ return tikaResource ;
69+ }
70+
6671 protected void setTikaResource (TikaResource tikaResource ) {
6772 this .tikaResource = tikaResource ;
6873 }
@@ -72,10 +77,10 @@ protected void setTikaResource(TikaResource tikaResource) {
7277 @ Produces ({"application/json" , "text/csv" })
7378 @ Path ("form" )
7479 public Response getMetadataFromMultipart (Attachment att , @ Context UriInfo info ) throws Exception {
75- ParseContext context = tikaResource .createParseContext ();
80+ ParseContext context = tikaResource .createRequestContext ();
7681 try (TikaInputStream tis = TikaInputStream .get (att .getObject (InputStream .class ))) {
7782 return Response
78- .ok (parseMetadata (tis , Metadata . newInstance ( context ), att .getHeaders (), context ))
83+ .ok (parseMetadata (tis , tikaResource . newRequestMetadata ( ), att .getHeaders (), context ))
7984 .build ();
8085 }
8186 }
@@ -93,8 +98,8 @@ public Response getMetadataWithConfig(
9398 @ Context HttpHeaders httpHeaders ) throws Exception {
9499
95100 // Load default context from config, then overlay with request config
96- ParseContext context = tikaResource .createParseContext ();
97- Metadata metadata = Metadata . newInstance ( context );
101+ ParseContext context = tikaResource .createRequestContext ();
102+ Metadata metadata = tikaResource . newRequestMetadata ( );
98103 try (TikaInputStream tis = tikaResource .setupMultipartConfig (attachments , metadata , context )) {
99104 TikaResource .logRequest (LOG , "/meta/config" , metadata );
100105 // Null headers: multipart request headers describe the envelope and would
@@ -106,8 +111,8 @@ public Response getMetadataWithConfig(
106111 @ PUT
107112 @ Produces ({"application/json" , "text/csv" })
108113 public Response getMetadata (InputStream is , @ Context HttpHeaders httpHeaders , @ Context UriInfo info ) throws Exception {
109- ParseContext context = tikaResource .createParseContext ();
110- Metadata metadata = Metadata . newInstance ( context );
114+ ParseContext context = tikaResource .createRequestContext ();
115+ Metadata metadata = tikaResource . newRequestMetadata ( );
111116 try (TikaInputStream tis = TikaInputStream .get (is )) {
112117 return Response
113118 .ok (parseMetadata (tis , metadata , httpHeaders .getRequestHeaders (), context ))
@@ -140,10 +145,10 @@ public Response getMetadata(InputStream is, @Context HttpHeaders httpHeaders, @C
140145 @ Path ("{field}" )
141146 @ Produces ({"application/json" , "text/csv" , "text/plain" })
142147 public Response getMetadataField (InputStream is , @ Context HttpHeaders httpHeaders , @ Context UriInfo info , @ PathParam ("field" ) String field ) throws Exception {
143- ParseContext context = tikaResource .createParseContext ();
148+ ParseContext context = tikaResource .createRequestContext ();
144149 Metadata metadata ;
145150 try (TikaInputStream tis = TikaInputStream .get (is )) {
146- metadata = parseMetadata (tis , Metadata . newInstance ( context ), httpHeaders .getRequestHeaders (), context );
151+ metadata = parseMetadata (tis , tikaResource . newRequestMetadata ( ), httpHeaders .getRequestHeaders (), context );
147152 }
148153
149154 String containerException = metadata .get (TikaCoreProperties .CONTAINER_EXCEPTION );
@@ -191,7 +196,7 @@ protected Metadata parseMetadata(TikaInputStream tis, Metadata metadata, Multiva
191196 TikaResource .logRequest (LOG , "/meta" , metadata );
192197 List <Metadata > metadataList = tikaResource .parseWithPipes (tis , metadata , context , ParseMode .RMETA );
193198 if (metadataList .isEmpty ()) {
194- return Metadata . newInstance ( context );
199+ return tikaResource . newRequestMetadata ( );
195200 }
196201 return metadataList .get (0 );
197202 }
0 commit comments