diff --git a/src/main/java/org/purl/sword/server/fedora/utils/StartupListener.java b/src/main/java/org/purl/sword/server/fedora/utils/StartupListener.java index 24ac685..640c3ba 100644 --- a/src/main/java/org/purl/sword/server/fedora/utils/StartupListener.java +++ b/src/main/java/org/purl/sword/server/fedora/utils/StartupListener.java @@ -128,41 +128,53 @@ public void contextInitialized(ServletContextEvent sce) { public void contextDestroyed(ServletContextEvent sce) { } - private void initLog4j() { - String logConfigPath = getAbsolutePathToResource( - orDefaultIfNull(getFirstValid( - System.getProperty("log4j.configuration"), - context.getInitParameter("log-config")), - "WEB-INF/log4j.xml")); - log.info("Taking log4j config from: " + logConfigPath); - configure(logConfigPath); + private String getAbsolutePathToResource(String resourcePath) throws Exception { + File file; + if (resourcePath.startsWith("/")) { + file = new File(resourcePath); + } else { + final String realPath = context.getRealPath(resourcePath); + if (realPath == null) { + throw new Exception("Cannot obtain absolute path to file if wrapped in war-archive."); + } + file = new File(realPath); + } + return file.getAbsolutePath(); } - private void initPropertiesLocation() { - propertiesLocation = getAbsolutePathToResource( - orDefaultIfNull(getFirstValid( - System.getProperty("project.properties"), - context.getInitParameter("project.properties")), - "WEB-INF/properties.xml")); - log.info("Loading properties files from: " + propertiesLocation); + private String getFirstValid(String... values) { + for (String s : values) if (s != null) return s; + return null; } - private String getAbsolutePathToResource(String resourcePath) { - if (resourcePath.startsWith("/")) { - File file = new File(resourcePath); - return file.getAbsolutePath(); - } else { - // assume file is in servlet context - return context.getRealPath(resourcePath); + private void initLog4j() { + try { + String logConfigPath = getAbsolutePathToResource( + orDefaultIfNull(getFirstValid( + System.getProperty("log4j.configuration"), + context.getInitParameter("log-config")), + "WEB-INF/log4j.xml")); + log.info("Taking log4j config from: " + logConfigPath); + configure(logConfigPath); + } catch (Exception e) { + log.error("Error initializing logging: " + e.getMessage()); } } - private String orDefaultIfNull(String s, String defaultValue) { - return (s == null) ? defaultValue : s; + private void initPropertiesLocation() { + try { + propertiesLocation = getAbsolutePathToResource( + orDefaultIfNull(getFirstValid( + System.getProperty("project.properties"), + context.getInitParameter("project.properties")), + "WEB-INF/properties.xml")); + log.info("Loading properties files from: " + propertiesLocation); + } catch (Exception e) { + log.fatal("Fatal Error initializing properties: " + e.getMessage()); + } } - private String getFirstValid(String... values) { - for (String s : values) if (s != null) return s; - return null; + private String orDefaultIfNull(String s, String defaultValue) { + return (s == null) ? defaultValue : s; } }