NIHVIVO-3995 It is important that the default namespace end in "/individual/". Important enough that it becomes part of the startup smoke tests.

This commit is contained in:
j2blake 2012-10-17 19:09:38 +00:00
parent 52314c4640
commit 7d11a24191
2 changed files with 43 additions and 42 deletions

View file

@ -17,10 +17,11 @@ import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/**
* Test that gets run at servlet context startup to check for the existence and
* validity of properties in the configuration.
* Test that gets run at servlet context startup to check for the existence and
* validity of properties in the configuration.
*/
public class ConfigurationPropertiesSmokeTests implements ServletContextListener {
public class ConfigurationPropertiesSmokeTests implements
ServletContextListener {
private static final String PROPERTY_HOME_DIRECTORY = "vitro.home.directory";
private static final String PROPERTY_DB_URL = "VitroConnection.DataSource.url";
@ -138,27 +139,39 @@ public class ConfigurationPropertiesSmokeTests implements ServletContextListener
+ username + "'", e);
}
}
/**
* Confirm that the default namespace is specified and a syntactically valid URI.
*/
private void checkDefaultNamespace(ServletContext ctx,
ConfigurationProperties props, StartupStatus ss) {
String ns = props.getProperty(PROPERTY_DEFAULT_NAMESPACE);
if (ns == null || ns.isEmpty()) {
ss.fatal(this, "deploy.properties does not contain a value for '"
+ PROPERTY_DEFAULT_NAMESPACE + "'");
} else {
try {
URI uri = new URI(ns);
} catch (URISyntaxException e) {
ss.fatal(this, PROPERTY_DEFAULT_NAMESPACE + " '" + ns +
"' is not a valid URI. " +
(e.getMessage() != null ? e.getMessage() : ""));
}
}
}
* Confirm that the default namespace is specified and a syntactically valid
* URI. It should also end with "/individual/".
*/
private void checkDefaultNamespace(ServletContext ctx,
ConfigurationProperties props, StartupStatus ss) {
String ns = props.getProperty(PROPERTY_DEFAULT_NAMESPACE);
if (ns == null || ns.isEmpty()) {
ss.fatal(this, "deploy.properties does not contain a value for '"
+ PROPERTY_DEFAULT_NAMESPACE + "'");
return;
}
try {
new URI(ns);
} catch (URISyntaxException e) {
ss.fatal(this,
PROPERTY_DEFAULT_NAMESPACE + " '" + ns
+ "' is not a valid URI. "
+ (e.getMessage() != null ? e.getMessage() : ""));
return;
}
String suffix = "/individual/";
if (!ns.endsWith(suffix)) {
ss.warning(this,
"Default namespace does not match the expected form "
+ "(does not end with '" + suffix + "'): '" + ns
+ "'");
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// nothing to do at shutdown

View file

@ -73,14 +73,14 @@ public class FileStorageSetup implements ServletContextListener {
* For use by the constructor in implementations of {@link FileStorage}.
*/
private File figureBaseDir(ServletContextEvent sce) throws IOException {
String homeDirPath = ConfigurationProperties.getBean(sce)
.getProperty(PROPERTY_VITRO_HOME_DIR);
String homeDirPath = ConfigurationProperties.getBean(sce).getProperty(
PROPERTY_VITRO_HOME_DIR);
if (homeDirPath == null) {
throw new IllegalArgumentException(
"Configuration properties must contain a value for '"
+ PROPERTY_VITRO_HOME_DIR + "'");
}
File homeDir = new File(homeDirPath);
if (!homeDir.exists()) {
throw new IllegalStateException("Vitro home directory '"
@ -91,20 +91,16 @@ public class FileStorageSetup implements ServletContextListener {
if (!baseDir.exists()) {
boolean created = baseDir.mkdir();
if (!created) {
throw new IOException(
"Unable to create uploads directory at '"
+ baseDir + "'");
throw new IOException("Unable to create uploads directory at '"
+ baseDir + "'");
}
}
return baseDir;
}
/**
* Get the configuration property for the default namespace, and confirm
* that it is in the proper form. The default namespace is assumed to be in
* this form: <code>http://vivo.mydomain.edu/individual/</code>
*
* For use by the constructor in implementations of {@link FileStorage}.
* Get the configuration property for the default namespace. For use by the
* constructor in implementations of {@link FileStorage}.
*
* @returns a collection containing the default namespace.
*/
@ -117,14 +113,6 @@ public class FileStorageSetup implements ServletContextListener {
+ PROPERTY_DEFAULT_NAMESPACE + "'");
}
String defaultSuffix = "/individual/";
if (!defaultNamespace.endsWith(defaultSuffix)) {
log.warn("Default namespace does not match the expected form "
+ "(does not end with '" + defaultSuffix + "'): '"
+ defaultNamespace + "'");
}
return Collections.singleton(defaultNamespace);
}