Class RestSession
Notes:
- This class is not thread safe.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPublic-internal servlet-request attribute key under which the activeRestSessionpublishes itself. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCloses this call'srequestIdLogContextscope, if open.static RestSession.Buildercreate(RestContext ctx) Creates a builder of this object.Identifies that an exception occurred during this call.finish()Called at the end of a call to finish any remaining tasks such as flushing buffers and logging the response.static RestSessionfromRequest(jakarta.servlet.http.HttpServletRequest req) Returns theRestSessionpublished on the given servlet request via theREQUEST_SESSION_ATTRsession-handle seam, ornull if none is present.Returns the bean store of this call.Returns the context that created this call.Returns the opaque debug-resolution snapshot stashed at the async-dispatch handoff.Returns the exception that occurred during this call.Returns the HTTP method name.Returns the operation session of this REST session.Shortcut for callinggetRequest().getPathInfo() .Same asgetPathInfo()but doesn't decode encoded characters.Returns resolved variable values on this call.@Resource (path)Returns the query parameters on the request.jakarta.servlet.http.HttpServletRequestReturns the HTTP servlet request of this REST call.Returns the correlation id resolved for this call (mint-or-honor), cached at build time.Returns the REST object.jakarta.servlet.http.HttpServletResponseReturns the HTTP servlet response of this REST call.Shortcut for callinggetRequest().getServletPath() .intShortcut for callinggetRequest().getStatus() .Returns the request path info as aUrlPathbean.Returns the URL path pattern match on this call.Installs bounded body-caching wrappers on this call's request/response for debug capture.Returns the properties on this bean as a map for debugging.voidrun()Runs this session.voidRecords the finish-time request attributes consumed by the debug formatter (currentlyExecTime).voidstashDebugSnapshot(Object value) Stashes the opaque debug-resolution snapshot on the request thread at the async-dispatch handoff.status(int value) Sets the HTTP status on this call.status(HttpStatusLine value) Sets the HTTP status on this call.urlPathMatch(UrlPathMatch value) Sets the URL path pattern match on this call.Methods inherited from class org.apache.juneau.marshall.ContextSession
addWarning, checkForWarnings, getSessionProperties, getWarnings, isDebug, toString
-
Field Details
-
REQUEST_SESSION_ATTR
Public-internal servlet-request attribute key under which the activeRestSessionpublishes itself.The session-handle seam that lets code in other packages resolve the call's cached correlation id without a live public/custom-key attribute read: the debug formatter's
statusLine(in theloggingpackage) andRequestIdFilter(in thefilterpackage) both read the session viafromRequest(jakarta.servlet.http.HttpServletRequest)and callgetRequestId(). Not part of the public REST contract — the attribute name is an internal detail.- See Also:
-
-
Constructor Details
-
RestSession
Constructor.- Parameters:
builder- The builder for this object.
Cannot benull .
-
-
Method Details
-
create
Creates a builder of this object.- Parameters:
ctx- The context creating this builder.
Cannot benull .- Returns:
- A new builder.
-
fromRequest
Returns theRestSessionpublished on the given servlet request via theREQUEST_SESSION_ATTRsession-handle seam, ornull if none is present.- Parameters:
req- The servlet request. Can benull (returnsnull ).- Returns:
- The active session, or
null .
-
installCapture
Installs bounded body-caching wrappers on this call's request/response for debug capture.Called by the two-phase debug pipeline when the resolved logger is loggable at
FINEST. Idempotent — the wrappers no-op if already installed.The capture cap is snapshotted from
RestContext.getRestDebugFormatter().bodyCap() at install time, so a formatter override actually raises, lowers, or (viabodyCap(0)) disables the number of bytes retained — not just the wrapper's own 8 KB default.- Returns:
- This object.
- Throws:
IOException- Occurs if the request/response streams could not be wrapped.
-
exception
Identifies that an exception occurred during this call.- Parameters:
value- The thrown exception.
Can benull (will clear the exception attribute and remove the exception from the bean store).- Returns:
- This object.
-
finish
Called at the end of a call to finish any remaining tasks such as flushing buffers and logging the response.When the request has been handed off to a real
AsyncContext, the response body/headers are written later on the response-completion thread. In that case this method neither flushes nor emits nor writes formatter-visible finish-time attributes — the completion hook owns all of that after the async body exists. The synchronous and synchronous-fallback (e.g. MockRestClient) paths are unchanged: they set finish-time attributes, flush, and emit here.- Returns:
- This object.
-
closeRequestIdScope
Closes this call'srequestIdLogContextscope, if open.Idempotent: safe to call more than once (and from a build path that never reaches
finish(), such as a throwaway error session). Must run on the request thread that opened the scope so a pooled thread does not carry the scope into the next request. -
setFinishTimeAttributes
Records the finish-time request attributes consumed by the debug formatter (currentlyExecTime).On the synchronous path this is called from
finish(). On the asynchronous path it is called by the completion hook immediately before rendering — never byfinish()after the async handoff — so the record always reflects the true request duration and the completion thread never races the request thread over formatter-visible response state. Idempotent: recomputing the value on repeat calls is harmless. -
stashDebugSnapshot
Stashes the opaque debug-resolution snapshot on the request thread at the async-dispatch handoff.Internal plumbing for the two-thread async debug pipeline; not part of the public REST contract. The value is a package-private
RestDebugSnapshotpassed asObjectso this class does not expose the type.- Parameters:
value- The snapshot, ornull when access logging is off.
-
getDebugSnapshot
Returns the opaque debug-resolution snapshot stashed at the async-dispatch handoff.Internal plumbing for the two-thread async debug pipeline; not part of the public REST contract.
- Returns:
- The stashed snapshot, or
null if none was stashed (synchronous path or access logging off).
-
getRequestId
Returns the correlation id resolved for this call (mint-or-honor), cached at build time.This is the synchronous, session-cached value the debug formatter and
RequestIdFilterread through thesession-handle seam— never a live public/custom-key attribute read.- Returns:
- The resolved request id. Never
null (unless a custom id supplier returnednull ).
-
getBeanStore
Returns the bean store of this call.- Returns:
- The bean store of this call.
-
getContext
Returns the context that created this call.- Overrides:
getContextin classContextSession- Returns:
- The context that created this call.
-
getException
Returns the exception that occurred during this call.- Returns:
- The exception that occurred during this call, or
null if no exception occurred.
-
getMethod
Returns the HTTP method name.The request-line method, unless it is overridden by a
methodquery parameter admitted byallowedMethodParams, or by one of theoverride headersadmitted byallowedMethodHeaders(the query parameter wins, then the headers in that order).Override claims on an enabled channel (an allow-list that admits at least one method) must agree: more than one distinct claim, whether on one channel or across channels, is refused.
- Returns:
- The HTTP method name, always uppercased.
- Throws:
MethodNotAllowed- If the method parameter contains invalid/malformed characters.BadRequest- If the request carries conflicting method overrides.
-
getOpSession
Returns the operation session of this REST session.The operation session is created once the Java method to be invoked has been determined.
- Returns:
- The operation session of this REST session.
- Throws:
InternalServerError- If operation session has not been created yet.
-
getOpSessionOrNull
Returns theRestOpSessioncreated duringrun()if one has been built, ornullotherwise.Unlike
getOpSession(), this method does not throw — it lets callers in lifecycle code paths (such as mixin endCall dual-firing inRestContext.execute(Object, jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)) inspect whether an operation was ever resolved without risking a spurious 500 when 404/405/412 paths bypass operation creation entirely.- Returns:
- The operation session, or
nullif one was never created (e.g. early routing failure). - Since:
- 10.0.0
-
getPathInfo
Shortcut for callinggetRequest().getPathInfo() .- Returns:
- The request servlet path info.
-
getPathInfoUndecoded
Same asgetPathInfo()but doesn't decode encoded characters.- Returns:
- The undecoded request servlet path info, or
null if there is no extra path information.
-
getPathVars
Returns resolved variable values on this call.@Resource (path)- Returns:
- Resolved
variable values on this call.@Resource (path)
-
getQueryParams
Returns the query parameters on the request.Unlike
ServletRequest.getParameterMap(), this doesn't parse the content if it's a POST.- Returns:
- The query parameters on the request.
-
getRequest
Returns the HTTP servlet request of this REST call.- Returns:
- the HTTP servlet request of this REST call.
-
getResource
Returns the REST object.- Returns:
- The rest object, or
null if no resource bean was specified.
-
getResponse
Returns the HTTP servlet response of this REST call.- Returns:
- the HTTP servlet response of this REST call.
-
getServletPath
Shortcut for callinggetRequest().getServletPath() .- Returns:
- The request servlet path.
-
getStatus
Shortcut for callinggetRequest().getStatus() .- Returns:
- The response status code.
-
getUrlPath
Returns the request path info as aUrlPathbean.- Returns:
- The request path info as a
UrlPathbean.
-
getUrlPathMatch
Returns the URL path pattern match on this call.- Returns:
- The URL path pattern match on this call, or
null if not set.
-
run
Runs this session.Does the following:
- Finds the Java method to invoke, refuses a safe request overridden to a method that is not a read (see
RestOp.read()), and creates aRestOpSessionfor it. - Invokes
RestPreCallmethods by callingRestContext.preCall(RestOpSession). - Invokes Java method by calling
RestOpSession.run(). - Invokes
RestPostCallmethods by callingRestContext.postCall(RestOpSession). - If the Java method produced output, finds the response processor for it and runs it by calling
RestContext.processResponse(RestOpSession). - If no Java method matched, generates a 404/405/412 by calling
RestContext.handleNotFound(RestSession).
- Throws:
Exception- Any exception can be thrown.
- Finds the Java method to invoke, refuses a safe request overridden to a method that is not a read (see
-
status
Sets the HTTP status on this call.- Parameters:
value- The status code.- Returns:
- This object.
-
status
Sets the HTTP status on this call.- Parameters:
value- The status code.
Can benull (ignored).- Returns:
- This object.
-
urlPathMatch
Sets the URL path pattern match on this call.- Parameters:
value- The match pattern.
Can benull (stored as an explicitnull binding, distinct from no binding at all).- Returns:
- This object.
-
properties
Description copied from class:ContextSessionReturns the properties on this bean as a map for debugging.- Overrides:
propertiesin classContextSession- Returns:
- The properties on this bean as a map for debugging.
-