fess icon indicating copy to clipboard operation
fess copied to clipboard

Improve Web API implementation with enhanced security and thread-safety

Open marevol opened this issue 2 months ago • 0 comments

This pull request introduces a set of significant refactoring and improvements to the Fess API implementation, focusing on modularity, maintainability, performance, and code quality. Key changes include the introduction of new utility classes for content type and JSON response handling, centralization of API constants, thread-safety improvements in the API manager factory, and simplification of content type detection logic. These changes are fully backward compatible and lay the groundwork for future enhancements.

API Infrastructure Improvements

  • Introduced ApiConstants.java to centralize all API-related constants (request/response field names, HTTP methods, MIME types, error messages, etc.), eliminating magic strings and improving maintainability across the codebase.
  • Refactored WebApiManagerFactory.java to use a thread-safe CopyOnWriteArrayList for storing API managers, added null validation in the add() method, and implemented a size() method for introspection. This improves performance and safety during concurrent initialization. [1] [2]

Utility and Code Simplification

  • Added ContentTypeUtil.java, a new utility class that centralizes MIME type detection using a map-based approach, replacing long if-else chains for file extension handling. This makes content type management extensible and maintainable.
  • Refactored content type detection in SearchEngineApiManager.java to use ContentTypeUtil, reducing ~30 lines of repetitive if-else code to ~7 lines and improving readability and extensibility.

API Manager Improvements

  • Updated BaseApiManager.java to use the new ApiConstants for attribute keys and replaced the format type detection if-else chain with efficient enum-based detection using FormatType.valueOf(), improving code clarity and performance. [1] [2] [3]

For a detailed overview and rationale behind these changes, see the new documentation in API_IMPROVEMENTS.md.

marevol avatar Nov 16 '25 11:11 marevol