I just made a url connection to local host:8080 and checked the http response code between 200-209 using JBOSS server.
public class Welcome extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
URL url = new URL("http://localhost:8080");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int code = connection.getResponseCode();
System.out.println("code=="+code);
if (code>=200 && code <= 209){
pw.println("<h1>Welcome....</h1>");
pw.println("<p>Service is accessable</p>");
}
else
{System.out.println("service is denied");}
}}
If HTTP Response code outside of 200-209 or unable to make connection, then it has to perform the following steps:
1)If Jboss Service is running, then restart.
2)If Jboss Service is not running, then start it.
Now here I want to know how can programmatically know whether Server is running or not in order to perform above 2 steps.. Please help me..Thanks you