Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display error in case home source directory is not accessible #488

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
"<br>" +
"Try to remove deployed Tomcat application directory %s and restart Tomcat.", homeSourcePath,
context.getRealPath("/")));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading