Class HealthCheckValve
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.LifecycleMBeanBase
org.apache.catalina.valves.ValveBase
io.meeds.platform.server.tomcat.healthcheck.HealthCheckValve
- All Implemented Interfaces:
MBeanRegistration, org.apache.catalina.Contained, org.apache.catalina.JmxEnabled, org.apache.catalina.Lifecycle, org.apache.catalina.Valve
public final class HealthCheckValve
extends org.apache.catalina.valves.ValveBase
A
Valve of the Host answering the health check
of the platform. It runs before any web application: no filter, no
authentication and no HttpSession is involved.
200when every web application is started, the portal container is started and, unlesssetDeep(String)says otherwise, what the platform depends on answers: every JDBC pool declared in the global naming resources of the server gives a valid connection, and the Elasticsearch server of the platform answers and is not red. Each is given a few seconds and the result is kept forsetCacheSeconds(int)503with the reasons otherwise403when the caller is not allowed, seesetAllow(String), or when the request carries a header set by a reverse proxy (X-Forwarded-For,Forwarded,X-Real-IP,X-Forwarded-Proto,X-Forwarded-Host,X-Forwarded-ByorVia): a proxy running on the same machine would otherwise make every caller look local. A reverse proxy that forwards/healthcheckwithout any of them still makes the caller look local: block that path in the proxy, or disable the health check405for any method butGETandHEAD
Host, before the RemoteIpValve
so that the address is the one of the TCP peer.
Set EXO_HEALTHCHECK=false (or the system property
exo.healthcheck) to disable it.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle
org.apache.catalina.Lifecycle.SingleUse -
Field Summary
Fields inherited from class org.apache.catalina.valves.ValveBase
asyncSupported, container, containerLog, next, smFields inherited from interface org.apache.catalina.Lifecycle
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidinvoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response) voidvoidsetCacheSeconds(int seconds) voidvoidvoidsetPortalContainer(String containerName) protected voidprotected voidMethods inherited from class org.apache.catalina.valves.ValveBase
backgroundProcess, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, isAsyncSupported, setAsyncSupported, setContainer, setNext, toStringMethods inherited from class org.apache.catalina.util.LifecycleMBeanBase
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisterMethods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
-
Constructor Details
-
HealthCheckValve
public HealthCheckValve()
-
-
Method Details
-
setPath
- Parameters:
uri- URI answered by the valve,/healthcheckby default
-
setAllow
- Parameters:
callers- comma separated IP addresses or CIDR networks allowed to call the health check, defaults to the propertyexo.healthcheck.allowor the variableEXO_HEALTHCHECK_ALLOW, then to127.0.0.1,::1
-
setPortalContainer
- Parameters:
containerName- name of the portal container that must be started,noneto skip the portal container check (the web applications, and unlesssetDeep(String)says otherwise the database and the search server, are still checked), defaults to the propertyexo.healthcheck.containeror the variableEXO_HEALTHCHECK_CONTAINER, then toportal
-
setDeep
- Parameters:
checks- the dependencies checked once the platform is started:truefor the databases and the search server,falseornonefor none, or a comma separated list ofdatabaseandsearch. Defaults to the propertyexo.healthcheck.deepor the variableEXO_HEALTHCHECK_DEEP, then totrue
-
setCacheSeconds
public void setCacheSeconds(int seconds) - Parameters:
seconds- seconds the result of the dependencies is kept, 10 by default: however often it is called, the health check asks the dependencies once in that time
-
initInternal
protected void initInternal() throws org.apache.catalina.LifecycleException- Overrides:
initInternalin classorg.apache.catalina.valves.ValveBase- Throws:
org.apache.catalina.LifecycleException
-
startInternal
protected void startInternal() throws org.apache.catalina.LifecycleException- Overrides:
startInternalin classorg.apache.catalina.valves.ValveBase- Throws:
org.apache.catalina.LifecycleException
-
stopInternal
protected void stopInternal() throws org.apache.catalina.LifecycleException- Overrides:
stopInternalin classorg.apache.catalina.valves.ValveBase- Throws:
org.apache.catalina.LifecycleException
-
invoke
public void invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response) throws IOException, jakarta.servlet.ServletException - Throws:
IOExceptionjakarta.servlet.ServletException
-