KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > init > TomcatWait


1 //
2
//
3
// ____.
4
// __/\ ______| |__/\. _______
5
// __ .____| | \ | +----+ \
6
// _______| /--| | | - \ _ | : - \_________
7
// \\______: :---| : : | : | \________>
8
// |__\---\_____________:______: :____|____:_____\
9
// /_____|
10
//
11
// . . . i n j a h i a w e t r u s t . . .
12
//
13

14 package org.jahia.init;
15
16 import java.io.InputStream JavaDoc;
17 import java.net.URL JavaDoc;
18
19 /**
20  * <p>Title: Tomcat waiting utility</p>
21  * <p>Description: Small standalone utility to wait until the Tomcat web server
22  * has finished initializing before going on with the startup script.</p>
23  * <p>Copyright: Copyright (c) 2002</p>
24  * <p>Company: </p>
25  * @author Serge Huber
26  * @version 1.0
27  */

28
29 public class TomcatWait
30 {
31     private static org.apache.log4j.Logger logger =
32             org.apache.log4j.Logger.getLogger(TomcatWait.class);
33
34     private static final String JavaDoc DEFAULT_TARGET_URL = "http://localhost:8080/jahia/html/startup/startjahia.html";
35
36     public static void main(String JavaDoc args[])
37     {
38         String JavaDoc targetURL = DEFAULT_TARGET_URL;
39         if (args.length == 0) {
40             logger.error("Missing targetURL, defaulting to " + DEFAULT_TARGET_URL);
41         } else {
42             targetURL = args[0];
43         }
44         URL JavaDoc url = null;
45         try
46         {
47             url = new URL JavaDoc(targetURL);
48         }
49         catch(Throwable JavaDoc throwable)
50         {
51             logger.error("Error in URL parameter : " + targetURL, throwable);
52             return;
53         }
54         boolean flag = false;
55         System.out.print("Waiting for Web Server to become available at " + targetURL + ".");
56         try {
57             Thread.sleep(1000); // sleep 1 second before making the connection
58
} catch (InterruptedException JavaDoc ie) {
59             ie.printStackTrace();
60         }
61         while(!flag) {
62             System.out.print(".");
63             try {
64                 Thread.sleep(500); // sleep 500 ms between tries.
65
} catch (InterruptedException JavaDoc ie) {
66                 ie.printStackTrace();
67             }
68
69             try
70             {
71                 InputStream JavaDoc inputstream = url.openStream();
72                 flag = true;
73                 inputstream.close();
74             }
75             catch(Throwable JavaDoc throwable1)
76             {
77                 flag = false;
78             }
79         }
80         System.out.println("");
81         System.out.println("Web Server now available.");
82     }
83 }
84
Popular Tags