• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking the application Status using java  RSS feed

 
Santosh Raveendran
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team

can any one advice me on the below requirement,

I need to check wheather an application hosted in a tomcat is up or down

is there any function in java to which i can pass a url of the application

and which will return some distinct values for a application up and down

status.

Thanks
santhosh
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Santosh,

Access the application, hit the URL that tells you whether the server is up
and running or not.
OR

See the server log. If server goes shut down or something wrong happens, it
leaves footprint on that.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Chandra states you can use the standard Java libraries to connect to a URL and get the response code back, you can report on that.
 
Santosh Raveendran
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn

I have implemented the requirement as below

try{
String requestUrl="http://domainname:8080/appname"
URL url = new URL(requestUrl.toString());
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
}

catch(Exception e){

//Server is down
shootEmail()


}

thanks
santhosh
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Santosh,

In case you may use HttpURLCOnnection hat gives you getResponseCode()
from the server.

code:


URL url = new URL("http://localhost:8085/jj");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
System.out.println(conn.getResponseCode());




In case its unable to connect to the server, it will throw exception.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done to both Santosh and Chandra!

Santosh, I would be inclined to go with Chandra's modification, it also allows you to deal with a wider array of responses (some you might want to email on, some not) but all in all you've got a good solution
 
Santosh Raveendran
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chandra and Martijn,i have implemented chandras solution as it

give me access to status code which is really the best one for my requirement


Thanks
santhosh
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!