Interface RestDebugFormatter
- All Known Implementing Classes:
BasicRestDebugFormatter,BasicTestRestDebugFormatter
This is the single public extension point for customizing how request/response debug records are rendered. The internal two-phase pipeline invokes the tier methods cumulatively based on the resolved logger level:
formatBasic— always (tierINFO).formatHeaders— added at tierFINE.formatBody— added at tierFINEST.
The two additive tiers default to the empty string so that a bare implementation supplying only
formatBasic is additive-safe. Most implementations instead extend
BasicRestDebugFormatter and override only the tier(s) they wish to change.
Secure by default
BasicRestDebugFormatter is secure by default: request/response bodies are never dumped unless the
operator has deliberately set the JUNEAU_REST_DEBUG_ALLOW_DUMP_BODIES environment variable (and even then only
at FINEST on renderable content). Credential-bearing header values are masked, every client-controlled string
is escaped against log forging, and all output is length-bounded. See
BasicRestDebugFormatter for the full contract.
The cached request/response bytes, the thrown exception, and the request execution time are reachable through the
RestRequest/RestResponse accessors (RestRequest.getCachedContent(),
RestRequest.getCachedContentLength(), RestRequest.getException(), RestRequest.getExecTime(),
RestResponse.getCachedContent(), RestResponse.getCachedContentLength()).
See Also:
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault cap on the rendered URI length in the status line. -
Method Summary
Modifier and TypeMethodDescriptiondefault intbodyCap()Returns the maximum number of request/response body bytes to capture for theFINEST-tier body rendering.formatBasic(RestRequest req, RestResponse res) Renders the basic (INFO-tier) portion of the debug record.default StringformatBody(RestRequest req, RestResponse res) Renders the body (FINEST-tier) portion of the debug record.default StringformatHeaders(RestRequest req, RestResponse res) Renders the headers (FINE-tier) portion of the debug record.default booleanisBodyRenderable(String contentType) Returnstrue if a body with the given content type is worth rendering as text (as opposed to being binary/unknown).default StringstatusLine(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Renders the basic status line ([status] HTTP method uri) directly from servlet objects.
-
Field Details
-
DEFAULT_MAX_URI_LENGTH
Default cap on the rendered URI length in the status line.- See Also:
-
-
Method Details
-
formatBasic
Renders the basic (INFO-tier) portion of the debug record.Always invoked. Typically a single status line such as
[200] HTTP GET /foo.- Parameters:
req- The current REST request. Nevernull .res- The current REST response. Nevernull .- Returns:
- The rendered basic portion. Never
null .
-
formatHeaders
Renders the headers (FINE-tier) portion of the debug record.Appended to
formatBasic(RestRequest,RestResponse)when the resolved logger is atFINE-or-finer. The default returns the empty string.- Parameters:
req- The current REST request. Nevernull .res- The current REST response. Nevernull .- Returns:
- The rendered headers portion. Never
null .
-
formatBody
Renders the body (FINEST-tier) portion of the debug record.Appended when the resolved logger is at
FINEST. Reads the cached request/response bytes. The default returns the empty string.- Parameters:
req- The current REST request. Nevernull .res- The current REST response. Nevernull .- Returns:
- The rendered body portion. Never
null .
-
statusLine
default String statusLine(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Renders the basic status line ([status] HTTP method uri) directly from servlet objects.Used both by
formatBasic(RestRequest,RestResponse)and by the pipeline's no-operation (404/405) path, which has noRestRequest/RestResponseto render through. The method and URI are alwayssanitized(CR/LF and control characters escaped) so a client-controlled URI cannot forge a log line, and the rendered URI is length-capped. This default appliesDEFAULT_MAX_URI_LENGTH;BasicRestDebugFormatteroverrides it to apply its configurablemaxUriLength.The query string is intentionally excluded (matching
HttpServletRequest.getRequestURI()), so plaintext?token=…disclosure is never re-introduced through this path.- Parameters:
req- The servlet request. Nevernull .res- The servlet response. Nevernull .- Returns:
- The rendered, sanitized status line.
-
isBodyRenderable
Returnstrue if a body with the given content type is worth rendering as text (as opposed to being binary/unknown).This is a text-vs-binary renderability predicate, not a redaction allowlist. It parses only the media type (type/subtype, ignoring parameters such as
; charset=utf-8), case-folds, and treats the following as renderable:text/*,application/json,application/xml, any+json/+xmlsuffix, andapplication/x-www-form-urlencoded.multipart/form-datais explicitly non-renderable. An absent or blank content type is conservatively treated as non-renderable.Content-Encodingis not visible to this one-argument predicate; a caller that dumps bodies must separately treat any non-identity encoding (e.g.gzip) as non-renderable.- Parameters:
contentType- The body's content type. Can benull (returnsfalse ).- Returns:
true if the content type is renderable as text.
-
bodyCap
Returns the maximum number of request/response body bytes to capture for theFINEST-tier body rendering.This cap is enforced at capture time by the two-phase pipeline, so memory stays bounded even for large uploads/downloads. Defaults to 8 KB.
- Returns:
- The body capture cap in bytes.
-