diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/ApplicationSetup.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/ApplicationSetup.java index 267ec77472..ae67130b41 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/ApplicationSetup.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/ApplicationSetup.java @@ -13,7 +13,7 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; - +import edu.cornell.mannlib.vitro.webapp.application.VitroHomeDirectory.HomeSourceException; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoader; import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException; @@ -57,6 +57,8 @@ public void contextInitialized(ServletContextEvent sce) { ApplicationUtils.setInstance(app); ss.info(this, "Application is configured."); + } catch(HomeSourceException e) { + ss.fatal(this, e.getMessage()); } catch (Exception e) { ss.fatal(this, "Failed to initialize the Application.", e); } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/VitroHomeDirectory.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/VitroHomeDirectory.java index be4a03c13b..3754e0244a 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/VitroHomeDirectory.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/application/VitroHomeDirectory.java @@ -74,6 +74,26 @@ private void setHomeSourcePath(ServletContext context) { if (homeSourcePath == null) { throw new IllegalStateException(String.format("Application home files not found in: %s", location)); } + File homeSource = new File(homeSourcePath); + if (!homeSource.exists()) { + throw new HomeSourceException(context, "doesn't exist."); + } + if (!homeSource.canRead()) { + throw new HomeSourceException(context, "can't be read."); + } + if (!homeSource.isDirectory()) { + throw new HomeSourceException(context, "is not a directory."); + } + } + + public class HomeSourceException extends RuntimeException { + public HomeSourceException(ServletContext context, String cause) { + super(String.format("Home source directory %s " + + cause + + "
" + + "Try to remove deployed Tomcat application directory %s and restart Tomcat.", homeSourcePath, + context.getRealPath("/"))); + } } /** diff --git a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/application/VitroHomeDirectoryTest.java b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/application/VitroHomeDirectoryTest.java index d78071e794..1b3fcbef2f 100644 --- a/api/src/test/java/edu/cornell/mannlib/vitro/webapp/application/VitroHomeDirectoryTest.java +++ b/api/src/test/java/edu/cornell/mannlib/vitro/webapp/application/VitroHomeDirectoryTest.java @@ -26,11 +26,10 @@ public class VitroHomeDirectoryTest { @Test public void testGetHomeSrcPath() { ServletContextStub sc = new ServletContextStub(); - String expectedPath = "/opt/tomcat/webapp/app/WEB-INF/resources/home-files"; - sc.setRealPath("/WEB-INF/resources/home-files", expectedPath); + sc.setRealPath("/WEB-INF/resources/home-files", src.getRoot().getAbsolutePath()); VitroHomeDirectory vhd = new VitroHomeDirectory(sc, dst.getRoot().toPath(), ""); String realPath = vhd.getSourcePath(); - assertEquals(expectedPath, realPath); + assertEquals(src.getRoot().getAbsolutePath(), realPath); } @Test