Class BasicRestServletGroup
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,BasicUniversalConfig,DefaultConfig,DefaultHtmlConfig
- Direct Known Subclasses:
BasicActuatorGroup,RootResources,SampleRootResource
BasicRestServlet for showing "group" pages.
Meant as a base class for top-level REST resources in servlet containers.
Provides support for JSON, XML, HTML, URL-Encoding, UON, XML, OpenAPI, and MessagePack. See BasicUniversalConfig
for details.
Adds the group-navigation endpoint (GET /) by composing NavigationMixin via
@Rest(mixins=...) on top of the residual op-mixins inherited from
BasicRestServlet. The navigation op lives on the NavigationMixin sub-context (backed by
RestMixin.getHostContext()) but renders with the host's
@HtmlDocConfig page decoration — mixin
sub-contexts inherit the host's class-level @HtmlDocConfig (and other class-level config), so the
navigation page matches the host's other endpoints.
Children are attached to this resource using the @Rest(children) annotation.
Dynamic children:
Additional child resources can be registered or unregistered at runtime via addChild(Class) /
removeChild(String) (and overloads). This is particularly useful in test fixtures where a single
group servlet is mounted once and individual tests plug in their own @Rest resources without restarting
the servlet container.
See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.rest.server.servlet.RestServlet
RestServlet.Builder<R extends RestServlet,SELF extends RestServlet.Builder<R, SELF>>, RestServlet.DefaultBuilder<R extends RestServlet> -
Field Summary
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDynamically registers a child REST resource by class.Dynamically registers a pre-instantiated child REST resource.Dynamically registers a pre-instantiated child REST resource at an explicit path.Returns theRestChildrenregistry backing this group resource.removeChild(Class<?> resourceClass) Removes the first child whose resource class matches the given type.removeChild(String path) Removes the child registered at the given composed path.Methods inherited from class org.apache.juneau.rest.server.servlet.RestServlet
builder, createAuthenticator, destroy, doLog, getContext, getPath, getPaths, getRequest, getResponse, getRestBuilder, init, log, log, service, setContextMethods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPatch, doPost, doPut, doTrace, getLastModified, isSensitiveHeader, serviceMethods inherited from class jakarta.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
BasicRestServletGroup
public BasicRestServletGroup()
-
-
Method Details
-
getChildResources
Returns theRestChildrenregistry backing this group resource.Use this for full access to the dynamic add/remove API, including the
replaceoverloads and the unmodifiableasMap()snapshot.- Returns:
- The
RestChildrenregistry for this resource'sRestContext.
-
addChild
Dynamically registers a child REST resource by class.Convenience pass-through to
RestChildren.addChild(Class)ongetChildResources().- Parameters:
resourceClass- The@Rest-annotated resource class.- Returns:
- The newly-built child
RestContext. - Throws:
jakarta.servlet.ServletException- If construction or lifecycle initialization of the child fails.
-
addChild
Dynamically registers a pre-instantiated child REST resource.Convenience pass-through to
RestChildren.addChild(Object)ongetChildResources().- Parameters:
resource- The@Rest-annotated resource instance.- Returns:
- The newly-built child
RestContext. - Throws:
jakarta.servlet.ServletException- If construction or lifecycle initialization of the child fails.
-
addChild
Dynamically registers a pre-instantiated child REST resource at an explicit path.Convenience pass-through to
RestChildren.addChild(String, Object)ongetChildResources().- Parameters:
path- The path segment under this group at which to mount the child.resource- The@Rest-annotated resource instance.- Returns:
- The newly-built child
RestContext. - Throws:
jakarta.servlet.ServletException- If construction or lifecycle initialization of the child fails.
-
removeChild
Removes the child registered at the given composed path.Convenience pass-through to
RestChildren.removeChild(String)ongetChildResources().- Parameters:
path- The composed path key (as returned byRestContext.getPath()).- Returns:
- The removed and destroyed
RestContext, ornullif no child was registered there.
-
removeChild
Removes the first child whose resource class matches the given type.Convenience pass-through to
RestChildren.removeChild(Class)ongetChildResources().- Parameters:
resourceClass- The resource class to match.- Returns:
- The removed and destroyed
RestContext, ornullif no matching child was found.
-