@@ -407,65 +407,18 @@ public static void logRequest(Logger logger, String endpoint, Metadata metadata)
407407 }
408408 }
409409
410- public static boolean getThrowOnWriteLimitReached (MultivaluedMap <String , String > httpHeaders ) {
411- if (httpHeaders .containsKey ("throwOnWriteLimitReached" )) {
412- String val = httpHeaders .getFirst ("throwOnWriteLimitReached" );
413- if ("true" .equalsIgnoreCase (val )) {
414- return true ;
415- } else if ("false" .equalsIgnoreCase (val )) {
416- return false ;
417- } else {
418- throw new IllegalArgumentException ("'throwOnWriteLimitReached' must be either 'true' or 'false'" );
419- }
420- }
421- // Default: throw on write limit reached
422- return true ;
423- }
424-
425- /**
426- * Parses the writeLimit header value from HTTP headers.
427- *
428- * @param httpHeaders the HTTP headers
429- * @return the write limit value, or -1 if not specified
430- */
431- public static int getWriteLimit (MultivaluedMap <String , String > httpHeaders ) {
432- if (httpHeaders .containsKey ("writeLimit" )) {
433- return Integer .parseInt (httpHeaders .getFirst ("writeLimit" ));
434- }
435- return -1 ;
436- }
437-
438410 /**
439- * Sets up the ContentHandlerFactory in the ParseContext based on handler type and HTTP headers.
440- * This is a shared utility method used by both / tika and /rmeta endpoints .
411+ * Sets up the ContentHandlerFactory in the ParseContext, taking the write limits from
412+ * {@link org.apache. tika.config.OutputLimits} in the context .
441413 *
442414 * @param context the ParseContext to configure
443415 * @param handlerTypeName the handler type name (text, html, xml, ignore), may be null for default
444- * @param httpHeaders the HTTP headers containing writeLimit and throwOnWriteLimitReached
445416 */
446- public static void setupContentHandlerFactory (ParseContext context , String handlerTypeName ,
447- MultivaluedMap <String , String > httpHeaders ) {
448- int writeLimit = getWriteLimit (httpHeaders );
449- boolean throwOnWriteLimitReached = getThrowOnWriteLimitReached (httpHeaders );
450- setupContentHandlerFactory (context , handlerTypeName , writeLimit , throwOnWriteLimitReached );
451- }
452-
453- /**
454- * Sets up the ContentHandlerFactory in the ParseContext based on explicit parameters.
455- * This overload is used when the values have already been parsed (e.g., from ServerHandlerConfig).
456- *
457- * @param context the ParseContext to configure
458- * @param handlerTypeName the handler type name (text, html, xml, ignore), may be null for default
459- * @param writeLimit the write limit, or -1 for unlimited
460- * @param throwOnWriteLimitReached whether to throw when write limit is reached
461- */
462- public static void setupContentHandlerFactory (ParseContext context , String handlerTypeName ,
463- int writeLimit , boolean throwOnWriteLimitReached ) {
417+ public static void setupContentHandlerFactory (ParseContext context , String handlerTypeName ) {
464418 BasicContentHandlerFactory .HANDLER_TYPE type = BasicContentHandlerFactory .parseHandlerType (
465419 handlerTypeName , DEFAULT_HANDLER_TYPE );
466- ContentHandlerFactory factory = new BasicContentHandlerFactory (type , writeLimit ,
467- throwOnWriteLimitReached , context );
468- context .set (ContentHandlerFactory .class , factory );
420+ context .set (ContentHandlerFactory .class ,
421+ BasicContentHandlerFactory .newInstance (type , context ));
469422 }
470423
471424 /**
@@ -474,28 +427,10 @@ public static void setupContentHandlerFactory(ParseContext context, String handl
474427 *
475428 * @param context the ParseContext to configure
476429 * @param handlerTypeName the handler type name
477- * @param httpHeaders the HTTP headers
478- */
479- public static void setupContentHandlerFactoryIfNeeded (ParseContext context , String handlerTypeName ,
480- MultivaluedMap <String , String > httpHeaders ) {
481- if (context .get (ContentHandlerFactory .class ) == null ) {
482- setupContentHandlerFactory (context , handlerTypeName , httpHeaders );
483- }
484- }
485-
486- /**
487- * Sets up the ContentHandlerFactory in the ParseContext if not already set.
488- * This overload is used when the values have already been parsed.
489- *
490- * @param context the ParseContext to configure
491- * @param handlerTypeName the handler type name
492- * @param writeLimit the write limit, or -1 for unlimited
493- * @param throwOnWriteLimitReached whether to throw when write limit is reached
494430 */
495- public static void setupContentHandlerFactoryIfNeeded (ParseContext context , String handlerTypeName ,
496- int writeLimit , boolean throwOnWriteLimitReached ) {
431+ public static void setupContentHandlerFactoryIfNeeded (ParseContext context , String handlerTypeName ) {
497432 if (context .get (ContentHandlerFactory .class ) == null ) {
498- setupContentHandlerFactory (context , handlerTypeName , writeLimit , throwOnWriteLimitReached );
433+ setupContentHandlerFactory (context , handlerTypeName );
499434 }
500435 }
501436
@@ -765,7 +700,7 @@ private Response produceRawOutput(TikaInputStream tis, Metadata metadata,
765700 String handlerTypeName ) throws IOException {
766701 fillMetadata (null , metadata , httpHeaders );
767702 ParseContext context = createParseContext ();
768- setupContentHandlerFactory (context , handlerTypeName , httpHeaders );
703+ setupContentHandlerFactory (context , handlerTypeName );
769704 return produceRawOutputWithContext (tis , metadata , context , handlerTypeName );
770705 }
771706
@@ -781,7 +716,7 @@ private Response produceRawOutputWithContext(TikaInputStream tis, Metadata metad
781716 logRequest (LOG , "/tika" , metadata );
782717
783718 // Ensure content handler factory is set (config may have set it)
784- setupContentHandlerFactoryIfNeeded (context , handlerTypeName , - 1 , true );
719+ setupContentHandlerFactoryIfNeeded (context , handlerTypeName );
785720
786721 LOG .debug ("produceRawOutput: handlerType={}, contentHandlerFactory={}" ,
787722 handlerTypeName , context .get (ContentHandlerFactory .class ));
@@ -849,7 +784,7 @@ private Metadata produceJson(TikaInputStream tis, Metadata metadata,
849784 String handlerTypeName ) throws IOException {
850785 fillMetadata (null , metadata , headers );
851786 ParseContext context = createParseContext ();
852- setupContentHandlerFactory (context , handlerTypeName , headers );
787+ setupContentHandlerFactory (context , handlerTypeName );
853788 return produceJsonWithContext (tis , metadata , context , handlerTypeName );
854789 }
855790
@@ -871,7 +806,7 @@ private Metadata produceJsonWithContext(TikaInputStream tis, Metadata metadata,
871806 logRequest (LOG , "/tika" , metadata );
872807
873808 // Ensure content handler factory is set (config may have set it)
874- setupContentHandlerFactoryIfNeeded (context , handlerTypeName , - 1 , true );
809+ setupContentHandlerFactoryIfNeeded (context , handlerTypeName );
875810
876811 List <Metadata > metadataList ;
877812 try {
0 commit comments