NIHVIVO-3940 If no NamespaceMapper is found in the ServletContext, log a warning message and return an empty string, instead of throwing an exception.

This commit is contained in:
j2blake 2012-10-08 20:20:20 +00:00
parent f491a7c95c
commit e3db0778cb

View file

@ -6,6 +6,9 @@ import java.util.List;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration; import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@ -21,6 +24,10 @@ import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
*/ */
public class IndividualRequestAnalysisContextImpl implements public class IndividualRequestAnalysisContextImpl implements
IndividualRequestAnalysisContext { IndividualRequestAnalysisContext {
private static final Log log = LogFactory
.getLog(IndividualRequestAnalysisContextImpl.class);
private final VitroRequest vreq; private final VitroRequest vreq;
private final ServletContext ctx; private final ServletContext ctx;
private final WebappDaoFactory wadf; private final WebappDaoFactory wadf;
@ -46,6 +53,12 @@ public class IndividualRequestAnalysisContextImpl implements
NamespaceMapper namespaceMapper = NamespaceMapperFactory NamespaceMapper namespaceMapper = NamespaceMapperFactory
.getNamespaceMapper(ctx); .getNamespaceMapper(ctx);
if (namespaceMapper == null) {
log.warn("No NamespaceMapper in ServletContext. Request URL was '"
+ vreq.getRequestURL() + "'");
return "";
}
String ns = namespaceMapper.getNamespaceForPrefix(prefix); String ns = namespaceMapper.getNamespaceForPrefix(prefix);
return (ns == null) ? "" : ns; return (ns == null) ? "" : ns;