Check if a url is up

T

Trace

Hi in the past i was using the followng code below to check if a
server was up and if it was to call a jsp...
However the jsp now resides to my server so there is no point really
of chekcing if it is up to call it ..
So how can i check that the specific page

e.g http://server.com:8100my.jsp is up??

try {

InetAddress address =
InetAddress.getByName("servername.com");

System.out.println("Name: " + address.getHostName());



System.out.println("Addr: " + address.getHostAddress());

System.out.println("Reach: " + address.isReachable(3000));


call url ....
}

} catch (UnknownHostException e) {

System.err.println("Unable to lookup the sic app");



mySession.getVariableField(IProjectVariables.TEMP)

.setValue("error");

} catch (IOException e) {

System.err.println("Unable to reach the sic app");

mySession.getVariableField(IProjectVariables.TEMP)

.setValue("error");



}
 
M

Mark Space

Trace said:
call url ....

Just open a socket to the specified server and port. (ignore the path
info). If it opens, you're ok.

If you know it's always going to be HTTP, you can just send the word
"GET" and look for some return input.


Here's a hint: from the command line of your OS, type:

telnet server.com 8100

And then type "GET" (upper case, no quotes) when the prompt comes back
and press enter. Obviously, use the correct name for the server and the
correct port. It its the default port, make sure to specify port 80.
 
A

Arne Vajhøj

Trace said:
Hi in the past i was using the followng code below to check if a
server was up and if it was to call a jsp...
However the jsp now resides to my server so there is no point really
of chekcing if it is up to call it ..
So how can i check that the specific page

e.g http://server.com:8100my.jsp is up??

Try something like:

public static boolean test(String urlstr) {
boolean retval = false;
try {
URL url = new URL(urlstr);
HttpURLConnection con = (HttpURLConnection)
url.openConnection();
con.connect();
int status = con.getResponseCode();
if (status == HttpURLConnection.HTTP_OK) {
retval = true;
} else {
retval = false;
}
con.disconnect();
} catch (Exception e) {
retval = false;
}
return retval;
}

Arne
 
A

Arne Vajhøj

Mark said:
Here's a hint: from the command line of your OS, type:

telnet server.com 8100

And then type "GET" (upper case, no quotes) when the prompt comes back
and press enter. Obviously, use the correct name for the server and the
correct port. It its the default port, make sure to specify port 80.

I would use:

GET / HTTP/1.0<return>
<return>

but ...

Arne
 
A

Arne Vajhøj

Sherman said:
I would use:

HEAD / HTTP/1.0<return>
<return>

If you don't want the contents of the page, why ask for them?

Good point.

I thought that HEAD would only check the existence of the JSP
page and not whether it will actually run.

But at least Tomcat actually runs it.

So HEAD is definitely better than GET.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top