Friday 15 February 2013

servlets - Dropwizard - override the url for the healthcheck endpoint -



servlets - Dropwizard - override the url for the healthcheck endpoint -

dropwizard uses codahale metrics healthcheck servlet. when using servlet outside of dropwizard can override uri setting init-param "healthcheck-uri".

is there way override in dropwizard?

it looks setting init-param on nonblockingservletholder.

you right nonblockingservletholder beingness constructed. issue dropwizard defaultserverfactory isn't transferring of params set in applicationcontext or admincontext, both part of dropwizard environment.

i believe viable alternative extend abstractserverfactory , set init params in config adminservlet before initialized. defaultserverfactory can extended , set configuration kid class.

class myserverfactory extends defaultserverfactory{ //copied abstractserverfactory protected handler createadminservlet(server server, mutableservletcontexthandler handler, metricregistry metrics, healthcheckregistry healthchecks) { //copied abstractserverfactory.configuresessionsandsecurity because private , can't called here if (handler.issecurityenabled()) { handler.getsecurityhandler().setserver(server); } if (handler.issessionsenabled()) { handler.getsessionhandler().setserver(server); } handler.setserver(server); handler.getservletcontext().setattribute(metricsservlet.metrics_registry, metrics); handler.getservletcontext().setattribute(healthcheckservlet.health_check_registry, healthchecks); //here - set init parameter , add together servlet def holder = new nonblockingservletholder(new adminservlet()) holder.setinitparameter("healthcheck-uri", "/myurl") handler.addservlet(holder, "/*"); //end handler.addfilter(allowedmethodsfilter.class, "/*", enumset.of(dispatchertype.request)) .setinitparameter(allowedmethodsfilter.allowed_methods_param, joiner.on(',').join(allowedmethods)); homecoming handler; } }

configuration kid class:

class myconfiguration extends configuration{ myconfiguration(){ setserverfactory(new myserverfactory()) } }

for worth:

i dove code initializes servlets , realized after while couldn't without overriding serverfactory doing: dropwizard environment has admincontext, applicationcontext , servletenvironment of allow set initialization parameters. adminservlet class place init param of "healthcheck-uri" used, hopeful setting these parameters in admincontext pass them through adminservlet, alas, not because jetty servletcontexthandler sets adminservlet has init params buried in _servlethandler._servletcontext._initparams.

none of these you:

environment.admincontext.setinitparameter("healthcheck-uri","/something") environment.applicationcontext.setinitparameter("healthcheck-uri","/something") environment.servlets().setinitparameter("healthcheck-uri","/something") environment.admin().setinitparameter("healthcheck-uri","/something")

servlets jetty dropwizard

No comments:

Post a Comment