diff --git a/src/main/java/it/unibz/inf/isoga/web/StartupListener.java b/src/main/java/it/unibz/inf/isoga/web/StartupListener.java index 80cc5a31a6a275d0ef812a458e422ed19c73b97e..57f04724e3085867c5034fbe287b414a4f90657a 100644 --- a/src/main/java/it/unibz/inf/isoga/web/StartupListener.java +++ b/src/main/java/it/unibz/inf/isoga/web/StartupListener.java @@ -13,6 +13,8 @@ import org.slf4j.LoggerFactory; public class StartupListener implements ServletContextListener { private static final Logger LOGGER = LoggerFactory.getLogger(StartupListener.class.getName()); + // Public methods + @Override public void contextInitialized(final ServletContextEvent sce) { LOGGER.info("Initializing context"); @@ -24,15 +26,33 @@ public class StartupListener implements ServletContextListener { // 4) Is the geoserver reachable? // 5) Can we connect to the geoserver with given username/password? - final ConfigWeb config = ConfigurationContainer.getGlobalConfig(); - final GeoserverHelper gh = new GeoserverHelper(config); - gh.waitForGeoserver(); - gh.ensureEnvironment(); - gh.performCleanup(); + startGeoserverThread(); } @Override public void contextDestroyed(final ServletContextEvent sce) { } + // Private methods + + /** + * Waits for geoserver and perform a cleanup. + * We do this in a separat thread so we do not get any problems if this webapp is hosted + * on the same servlet container as the geoserver (we have to do this, since there is no + * possibility to define an application startup order) + */ + private void startGeoserverThread() { + final Thread t = new Thread() { + @Override + public void run() { + final ConfigWeb config = ConfigurationContainer.getGlobalConfig(); + final GeoserverHelper gh = new GeoserverHelper(config); + gh.waitForGeoserver(); + gh.ensureEnvironment(); + gh.performCleanup(); + } + }; + + t.start(); + } }