I've a servlet and it's init method must do some HTTP calls to itself. This is because I'm using an embedded app, that starts up and it's main interface it's a RESTful API. I can't and don't really want to use the internal classes, because they are not documented and difficult to use. So I prefere to use the REST API through local HTTP.
So, I extended the servlet that comes with the App and I modified the init method, so that it starts a thread and it does some HTTP calls to itself. For the moment I hardwired "http://localhost:port/servlet/mapping/
" as the path, but I'd like to have something dynamic that could at least detect the port number and the mapping too.
Is there any decent way to do this? I found lots of examples that extract that information from the HttpServletRequest
object, but in the init method you don't have it. All you have is the ServletContext
.
Ah, by the way, I use servlet API 3.0.