Class ChatSessionClearHandler

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

public class ChatSessionClearHandler extends Object
Handles DELETE /api/v2/chat/sessions/{session_id} — clears the conversation history for a specific chat session.

This endpoint replaces the clear: true flag that was previously accepted by POST /api/v2/chat. Separating the clear operation into a dedicated DELETE endpoint follows REST conventions and allows the POST handler to be a pure chat-message endpoint without state-mutation side-effects.

Success response shape:


 { "response": { "status": 0, "session_id": "...", "cleared": true } }
 

Error responses follow the standard v2 envelope:

  • 405 — wrong HTTP method
  • 400 — invalid or missing session_id (fails URL pattern validation)
  • 404 — session not found or belongs to a different user
  • 429 — rate limit exceeded
  • 500 — unexpected server error

Authentication posture: the same as ChatHandler — anonymous users are identified by the cookie-bound userCode; the session_id ownership check in ChatSessionManager#clearSession prevents cross-user clearing.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    getRateLimitKey(jakarta.servlet.http.HttpServletRequest req)
    Resolves the chat rate-limit key (server-validated username for authenticated callers, else the proxy-aware client IP).
    protected String
    getUserId(jakarta.servlet.http.HttpServletRequest req)
    Resolves the effective chat user id.
    void
    handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String sessionId)
    Handles a DELETE request for /api/v2/chat/sessions/{session_id}.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ChatSessionClearHandler

      public ChatSessionClearHandler()
      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 sessionId) throws IOException
      Handles a DELETE request for /api/v2/chat/sessions/{session_id}.
      Parameters:
      req - the incoming HTTP request
      res - the HTTP response to write to
      sessionId - the session ID extracted from the URL path by the router
      Throws:
      IOException - if writing the response fails
    • getUserId

      protected String getUserId(jakarta.servlet.http.HttpServletRequest req)
      Resolves the effective chat user id. Exposed as a seam so unit tests can override the user identity directly. SystemHelper/UserInfoHelper are smart-deploy components, so stubbing them via ComponentUtil.register is not reliable once the shared test container has resolved the real ones; overriding this method avoids that fragility.
      Parameters:
      req - the incoming HTTP request
      Returns:
      the user identifier (never null)
    • getRateLimitKey

      protected String getRateLimitKey(jakarta.servlet.http.HttpServletRequest req)
      Resolves the chat rate-limit key (server-validated username for authenticated callers, else the proxy-aware client IP). Exposed as a seam so unit tests can pin the throttle key deterministically; the underlying SystemHelper/RateLimitHelper are smart-deploy components that are unreliable to stub via ComponentUtil.register once the shared test container has resolved the real ones (same rationale as getUserId(jakarta.servlet.http.HttpServletRequest)).
      Parameters:
      req - the incoming HTTP request
      Returns:
      the rate-limit key (never null/blank)