Class ChatSessionClearHandler
java.lang.Object
org.codelibs.fess.api.v2.handlers.ChatSessionClearHandler
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 method400— invalid or missing session_id (fails URL pattern validation)404— session not found or belongs to a different user429— rate limit exceeded500— 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected StringgetRateLimitKey(jakarta.servlet.http.HttpServletRequest req) Resolves the chat rate-limit key (server-validated username for authenticated callers, else the proxy-aware client IP).protected StringgetUserId(jakarta.servlet.http.HttpServletRequest req) Resolves the effective chat user id.voidhandle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, String sessionId) Handles a DELETE request for/api/v2/chat/sessions/{session_id}.
-
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 requestres- the HTTP response to write tosessionId- the session ID extracted from the URL path by the router- Throws:
IOException- if writing the response fails
-
getUserId
Resolves the effective chat user id. Exposed as a seam so unit tests can override the user identity directly.SystemHelper/UserInfoHelperare smart-deploy components, so stubbing them viaComponentUtil.registeris 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
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 underlyingSystemHelper/RateLimitHelperare smart-deploy components that are unreliable to stub viaComponentUtil.registeronce the shared test container has resolved the real ones (same rationale asgetUserId(jakarta.servlet.http.HttpServletRequest)).- Parameters:
req- the incoming HTTP request- Returns:
- the rate-limit key (never null/blank)
-