Suppose I host a JavaEE WebApp on Payara/Glassfish (or any other WebContainer for that matter).
I would reach the Servlets under the address https://a.b/appname/myservleturlpattern
or as https://a.b/myservleturlpattern
if the VirtualServer-Config points to the app as default.
Usually I can get that address easily inside any HttpServlet (ServletContext).
But now, when I'm running a Background task (@Schedule) in a non-servlet class, how would I get that address?
What I want: get the app's base address https://a.b/appname/
or as https://a.b/
from any class, especially from non-Servlet classes. (Cant get and don't need the myservleturlpattern
because I'm not in a servlet.)
So far, my only idea is to listen to all my Servlets (extending the same custom HttpServlet anyway) and on the first call set a static variable, but thats really really unclean and hack-isch.
Any better ideas?