Class FavoriteGetHandler

java.lang.Object
org.codelibs.fess.api.v2.handlers.FavoriteGetHandler

public class FavoriteGetHandler extends Object
Handles GET /api/v2/documents/{docId}/favorite.

Returns whether the calling user has favorited the document plus the document's current favorite count. The docId is extracted from the path by the manager; this handler validates it against a conservative [A-Za-z0-9_-]+ regex so a malformed value (path traversal attempt, empty segment, …) surfaces as a structured V2ErrorCode.INVALID_REQUEST envelope rather than reaching the search backend.

The response payload is:


 { "doc_id": "<id>", "favorite": <bool>, "count": <long> }
 

The count field is always present (defaults to 0) so client SDKs can rely on a stable shape rather than branching on its presence. POST/DELETE handling lives in Plan 3 — this handler only services GET.

  • Constructor Details

    • FavoriteGetHandler

      public FavoriteGetHandler()
      Default constructor. The handler is stateless and intended to be instantiated once by the API manager and shared across concurrent requests.
  • Method Details

    • handle

      public void handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String docId) throws IOException
      Processes one /api/v2/documents/{docId}/favorite GET request.

      Order of checks:

      1. HTTP method must be GET.
      2. docId must be non-blank and match the safety regex.
      3. user.favorite feature flag must be enabled.
      4. Document must exist (or 404).

      When the user code is blank (anonymous caller) the favorite flag is reported as false but the count still reflects the stored value, matching v1's read-only semantics for unauthenticated favorite queries.

      Parameters:
      req - the incoming HTTP request
      res - the HTTP response to write to
      docId - the document id extracted from the URL path (already trimmed of surrounding path segments)
      Throws:
      IOException - if writing the envelope fails