Class ChatRequestBody

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

public final class ChatRequestBody extends Object
Parsed view of a chat request body shared by ChatHandler and ChatStreamHandler.

The v2 body shape uses snake_case keys: session_id, message, extra_queries. Label filters are passed as a nested object: "fields": {"label": "value"} (string or array). The legacy dotted-key "fields.label" is also accepted for backward compatibility during transition. Session clearing has been moved to the dedicated DELETE endpoint /api/v2/chat/sessions/{session_id}; the clear flag is no longer accepted here.

Length is enforced inside ChatApiHelper.parseRequestBody(Map, int) so the caller does not need a separate guard. Label and extra_queries validation uses the same allowlist helpers v1 calls — LabelTypeHelper for labels and ViewHelper for facet queries — to prevent query injection, delegated to the chatApiHelper component (obtained via ComponentUtil.getChatApiHelper()).

MJ-29: Filter values that fail validation (fields.label, extra_queries) are dropped silently from the resolved request. Rejected values are tracked in the warnings map (see getWarnings()) for diagnostics only and are not emitted on the wire by ChatHandler or ChatStreamHandler.

MJ-30 i18n note: error.message is developer-facing English. Clients MUST use error.code (the V2ErrorCode token) for user-facing i18n.

  • Constructor Details

    • ChatRequestBody

      public ChatRequestBody(String message, String sessionId, Map<String,String[]> fields, String[] extraQueries, Map<String,List<String>> warnings)
      Creates a parsed chat request body. Instances are normally produced by ChatApiHelper.parseRequestBody(Map, int) after the raw body has been validated, so callers rarely invoke this constructor directly.
      Parameters:
      message - the trimmed message value, or null when omitted or blank
      sessionId - the trimmed session_id value, or null for a fresh session
      fields - the validated label-filter map; never null
      extraQueries - the validated extra_queries array; never null
      warnings - the map of rejected field values tracked for diagnostics; never null
  • Method Details

    • message

      public String message()
      Returns the trimmed message value supplied by the caller.
      Returns:
      the chat message, or null if the caller omitted it or sent only whitespace
    • sessionId

      public String sessionId()
      Returns the trimmed session_id value supplied by the caller.
      Returns:
      the chat session id, or null when the caller is starting a fresh session
    • fields

      public Map<String,String[]> fields()
      Returns the validated label-filter map (fields.label entries).
      Returns:
      map of label field name to allowlisted value arrays; never null
    • extraQueries

      public String[] extraQueries()
      Returns the validated extra_queries array supplied by the caller.
      Returns:
      allowlisted facet queries, or an empty array when none were supplied
    • getWarnings

      public Map<String,List<String>> getWarnings()
      MJ-29: Returns a map of field names to rejected values. The map is empty (never null) when no values were dropped. Keys are the request field names: "fields.label" and "extra_queries".

      Diagnostics-only: handlers (ChatHandler, ChatStreamHandler) do not surface this map on the wire today. Exposing rejected filter values to clients is a planned follow-up.

      Returns:
      unmodifiable map of rejected field→value-list pairs; empty if nothing was dropped