Class HealthServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet,jakarta.servlet.ServletConfig,Serializable,BasicUniversalConfig,DefaultConfig,DefaultHtmlConfig
Mounts as a standalone top-level servlet at /healthz, /readyz, and /livez,
delegating to a shared HealthAggregator worker bean. The HealthMixin mixin flavor
delegates to the same bean, so the two forms cannot drift.
See Also:
- Since:
- 10.0.0
-
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 TypeMethodDescriptionprotected Map<String,HealthIndicator> Returns the indicators to evaluate for this request.voidinitReadinessState(WritableBeanStore beanStore) Registers the published readiness state (if any) into this resource's own bean store, soHealthAggregator.aggregate(org.apache.juneau.rest.server.RestContext, java.util.Map<java.lang.String, org.apache.juneau.rest.server.health.HealthIndicator>, org.apache.juneau.rest.server.health.HealthProbe, org.apache.juneau.rest.server.RestResponse)resolves the lifecycle-owned instance instead of falling back toReadinessState.shared().probe(RestRequest req, RestResponse res) Health/readiness/liveness probe endpoint.protected HealthProbeprobeFor(RestRequest req) Resolves which probe this request is for, keyed off the LAST PATH SEGMENT.Publishes the lifecycle-ownedReadinessStatethat this probe should observe.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
-
HealthServlet
public HealthServlet()
-
-
Method Details
-
publishReadinessState
Publishes the lifecycle-ownedReadinessStatethat this probe should observe.Called by the embedded-server lifecycle component (e.g.
JettyServerComponent,TomcatServerComponent) before the server starts, so the per-service instance that component flips on shutdown is registered into this resource's own bean store — seeinitReadinessState(org.apache.juneau.commons.inject.WritableBeanStore)— closing the gap between the microservice's bean store and this servlet's bean store thatHealthAggregatorconsults.- Parameters:
state- The per-service readiness state. Ignored ifnull .- Returns:
- This object.
-
initReadinessState
Registers the published readiness state (if any) into this resource's own bean store, soHealthAggregator.aggregate(org.apache.juneau.rest.server.RestContext, java.util.Map<java.lang.String, org.apache.juneau.rest.server.health.HealthIndicator>, org.apache.juneau.rest.server.health.HealthProbe, org.apache.juneau.rest.server.RestResponse)resolves the lifecycle-owned instance instead of falling back toReadinessState.shared().- Parameters:
beanStore- This resource's bean store.
-
probe
Health/readiness/liveness probe endpoint.Serves all three mount paths (
/healthz,/readyz,/livez) through one/*operation, dispatching on the request's last path segment. A single zero-part,hasRemainder=truematcher is required because this servlet is auto-mounted at three exact-match top-level path-specs: a real container delivers a bareGET /readyzwith a zero-segmentpathInfothat no 1-segment matcher can satisfy, so three separate@RestGet(path="/{probe}")operations all 404. The last-path-segment key (probeFor(org.apache.juneau.rest.server.RestRequest)) is the only thing that differs per mount, so it is the disambiguator.This replaces the former
healthz(...)/readyz(...)/livez(...)entry points; subclasses that overrode any of those must overrideprobeFor(RestRequest)(or this method) instead.- Parameters:
req- The request (its last path segment selects the probe).res- The response.- Returns:
- Aggregated health payload.
-
probeFor
Resolves which probe this request is for, keyed off the LAST PATH SEGMENT.Prefers
HttpServletRequestWrapper.getPathInfo()when it carries a real (non-root) value — this is whatMockRestClientand any remainder-based remount populate (servletPath="", pathInfo="/readyz"). Falls back toRestRequest.getServletPath()for a real container's bare exact-match hit, wherepathInfoisnull(servletPath="/readyz", pathInfo=null).- Parameters:
req- The request.- Returns:
- The resolved probe, or
nullfor/healthz(the overall aggregate).
-
indicators
Returns the indicators to evaluate for this request.Defaults to every
HealthIndicatorbean registered in this resource's bean store. Subclasses may override to supply a fixed indicator set.- Returns:
- Indicator map keyed by bean name.
-