Reputation: 513
I have a Tomcat 7 application that starts a Thread at startup and after doing some things I want to call "something" to initialize/start a servlet thats deployed on the Tomcat.
Any Ideas?
Upvotes: 0
Views: 244
Reputation: 513
Here is the solution:
private boolean startup() throws ClientProtocolException, IOException {
logger.entry();
HttpPost request = new HttpPost("http://.../StartupServlet");
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(30 * 1000)
.setConnectionRequestTimeout(30 * 1000)
.setConnectTimeout(30 * 1000)
.build();
request.setConfig(requestConfig);
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(request);
if (HttpStatus.SC_OK != response.getStatusLine().getStatusCode()) {
return false;
}
logger.exit();
return true;
}
Upvotes: 0
Reputation: 68715
Servlets are initialised by servlet container in one of two ways:
or
If your servlet is not marked to be loaded on startup then simply send an Http request to your servlet from your Thread. You can use HttpURLConnection
or any similar API to do that.
Upvotes: 1