Class RestResource
- Direct Known Subclasses:
AdminResource,BasicRestResource,FaviconResource,StaticFilesResource,VersionResource,ViewResource
RestServlet but doesn't extend from HttpServlet.
This is particularly useful in Spring Boot environments that auto-detect servlets to deploy in servlet containers, but you want this resource to be deployed as a child instead.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRestResource.Builder<R extends RestResource,SELF extends RestResource.Builder<R, SELF>> Fluent builder for programmatically configuring aRestResourcesubclass.static final classRestResource.DefaultBuilder<R extends RestResource>Concrete default leaf builder returned bybuilder(Class)for the common (non-subclassed) case. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor.protectedRestResource(RestBuilder<?> builder) Builder-injection constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic <R extends RestResource>
RestResource.DefaultBuilder<R>Creates a new fluent builder for programmatically configuring an instance of the specified resource type.protected voidMain logger method.protected RestContextReturns the read-only context object that contains all the configuration information about this resource.getPaths()Returns the runtime-overridden top-level mount paths for this resource.Returns the current thread-local HTTP request.Returns the current thread-local HTTP response.RestBuilder<?>Returns the programmatic configuration builder stashed on this resource, ornull if none.voidLog a message.voidLog a message.protected voidsetContext(RestContext context) Sets the context object for this servlet.
-
Constructor Details
-
RestResource
protected RestResource()Default constructor. -
RestResource
Builder-injection constructor.- Parameters:
builder- The programmatic configuration builder. May benull .
-
-
Method Details
-
getRestBuilder
Returns the programmatic configuration builder stashed on this resource, ornull if none.- Returns:
- The stashed builder, or
null if none was injected.
-
builder
Creates a new fluent builder for programmatically configuring an instance of the specified resource type.- Type Parameters:
R- The resource type.- Parameters:
type- The resource type to build. Must not benull .- Returns:
- A new builder.
-
getRequest
Returns the current thread-local HTTP request.- Returns:
- The current thread-local HTTP request, or
null if it wasn't created.
-
getResponse
Returns the current thread-local HTTP response.- Returns:
- The current thread-local HTTP response, or
null if it wasn't created.
-
log
Log a message.Subclasses can intercept the handling of these messages by overriding
doLog(Level, Throwable, Supplier).- Parameters:
level- The log level.msg- The message to log.args- OptionalString.format-style arguments.
-
log
Log a message.Subclasses can intercept the handling of these messages by overriding
doLog(Level, Throwable, Supplier).- Parameters:
level- The log level.cause- The cause.msg- The message to log.args- OptionalString.format-style arguments.
-
doLog
Main logger method.The default behavior logs a message to the Java logger of the class name.
Subclasses can override this method to implement their own logger handling.
- Parameters:
level- The log level.cause- Optional throwable.msg- The message to log.
-
getContext
Returns the read-only context object that contains all the configuration information about this resource.- Returns:
- The context information on this servlet.
-
getPaths
Returns the runtime-overridden top-level mount paths for this resource.Subclasses can override this method to substitute the
@Rest(paths)annotation defaults at construction time. This is the "getter" rung in the runtime-override resolution chain documented onRestContext.getPaths():- Programmatic (
RestContext.Builder.paths(String...)) — highest precedence. - This
getPaths()getter (when non-null). @Rest(paths={...})annotation default (SVL-resolved per element, comma-split) — lowest precedence.
Accepted return shapes:
null— no override; resolution falls through to the@Rest(paths=...)annotation default.String— a single path or a comma-delimited list, e.g."/healthz,/readyz".String[]— each element may itself be a comma-delimited list.Collection,List,Set,Iterable, orStreamof any of the above (nested mixes are recursively flattened).- Primitive arrays (boxed during flattening).
Non-
Stringleaves are coerced viaString.valueOf(Object). Each leaf string then runs through the same per-element pipeline used for@Rest(paths=...)annotation elements: SVL is applied via the bean-store-backedVarResolverSession(so$C{key}consults the liveConfig,$E{NAME,default}and$S{prop,default}resolve through the bootstrap variable catalog), and the post-SVL value is comma-split with each piece trimmed and empty pieces dropped.Notes:
-
Returning
null(the default) means "inherit annotation" — the next rung resolves. -
Returning
new String[0], an empty collection, an empty string, or a blank string means "explicitly clear" — no top-level mounts.
- Returns:
- The runtime-overridden mount paths in any accepted shape, or
nullto inherit the annotation default. - Since:
- 10.0.0
- Programmatic (
-
setContext
Sets the context object for this servlet.- Parameters:
context- Sets the context object on this servlet.- Throws:
jakarta.servlet.ServletException- If error occurred during post-initialiation.
-