[J2eeunit-dev] Ant integration - don't start server if already running.
Brought to you by:
vmassol
From: Philip A. <pa...@be...> - 2001-03-27 12:59:51
|
Vincent, First of all, cheers for J2EEUnit - its very useful. I'm using the Ant integration to start and stop WLS. I've altered the StartServer task so that it does an initial ping of the server, and does nothing if its already started. I've also done the analogous change to StopServer (don't stop if its not pingable). Patches attached. I toyed with the idea of making these changes optional, butI think they are generally The Right Thing. Please consider them applying them. Regards, - Phil ------------------------------------------- Philip Aston - Senior Consultant BEA Professional Services (Northern Europe) diff -u ../../../../../orig/src/ant/j2eeunit/ant/StartServerHelper.java ./StartServerHelper.java --- ../../../../../orig/src/ant/j2eeunit/ant/StartServerHelper.java Tue Mar 20 17:43:14 2001 +++ ./StartServerHelper.java Tue Mar 27 13:18:54 2001 @@ -75,6 +75,17 @@ throw new BuildException("A startTarget Ant target name must be specified"); } + // Try connecting in case the server is already running. + try { + HttpURLConnection connection = (HttpURLConnection)m_TestURL.openConnection(); + connection.connect(); + connection.disconnect(); + + // Server is already running. Make this task a no-op. + return; + } catch (IOException e) { + } + // Call the target that starts the server, in another thread. The called // target must be blocking. Thread thread = new Thread(this); @@ -160,4 +171,4 @@ m_StartTarget = theStartTarget; } -} \ No newline at end of file +} diff -u ../../../../../orig/src/ant/j2eeunit/ant/StopServerHelper.java ./StopServerHelper.java --- ../../../../../orig/src/ant/j2eeunit/ant/StopServerHelper.java Tue Mar 20 17:49:02 2001 +++ ./StopServerHelper.java Tue Mar 27 13:20:08 2001 @@ -71,6 +71,18 @@ throw new BuildException("A stopTarget Ant target name must be specified"); } + // Try connecting in case the server is already stopped. + try { + HttpURLConnection connection = (HttpURLConnection)m_TestURL.openConnection(); + connection.connect(); + connection.disconnect(); + } catch (IOException e) { + + // Server is already running. Make this task a no-op. + return; + } + + // Call the target that stops the server, in another thread. Thread thread = new Thread(this); thread.start(); @@ -152,4 +164,4 @@ m_StopTarget = theStopTarget; } -} \ No newline at end of file +} |