From 6300a68c2452725149ec64bbaac8416dce4b3aa8 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Wed, 13 Mar 2013 07:14:27 -0400 Subject: [PATCH] Catches and reports missing web.xml init parameter --- .../config/Pz2ConfigureByMk2Config.java | 19 +++++++++++-------- .../indexdata/pz2utils4jsf/errors/ErrorHelper.java | 11 +++++++++++ .../indexdata/pz2utils4jsf/pazpar2/Pz2Session.java | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java index a085561..e809486 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java @@ -17,6 +17,7 @@ import org.apache.log4j.Logger; import com.indexdata.masterkey.config.MasterkeyConfiguration; import com.indexdata.masterkey.config.ModuleConfiguration; import com.indexdata.pz2utils4jsf.utils.Utils; +import static com.indexdata.pz2utils4jsf.utils.Utils.nl; @Named @SessionScoped @Alternative public class Pz2ConfigureByMk2Config implements Pz2Configurator { @@ -24,6 +25,7 @@ public class Pz2ConfigureByMk2Config implements Pz2Configurator { private static final long serialVersionUID = 8865086878660568870L; private static Logger logger = Logger.getLogger(Pz2ConfigureByMk2Config.class); private Pz2Config pz2config = null; + private String configFilePathAndName = "none"; public Pz2ConfigureByMk2Config () throws IOException { logger.info(Utils.objectId(this) + " is instantiating Pazpar2 service configuration by MasterKey configuration scheme."); @@ -39,10 +41,11 @@ public class Pz2ConfigureByMk2Config implements Pz2Configurator { private void createConfig () throws IOException { ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); - ServletContext servletContext = (ServletContext) externalContext.getContext(); + ServletContext servletContext = (ServletContext) externalContext.getContext(); MasterkeyConfiguration mkConfigContext = MasterkeyConfiguration.getInstance(servletContext, "pazpar-application-jsf", ((HttpServletRequest) externalContext.getRequest()).getServerName()); + configFilePathAndName = mkConfigContext.getConfigFileLocation().getConfigFilePath(); ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client"); pz2config = new Pz2Config(moduleConfig); logger.info(document()); @@ -51,19 +54,19 @@ public class Pz2ConfigureByMk2Config implements Pz2Configurator { public List document() { List doc = new ArrayList(); - - doc.add("-- App set to access Pazpar2 at: " +pz2config.get("PAZPAR2_URL")); + doc.add("Attempted to configure service using the file " + configFilePathAndName); + doc.add(nl+"-- Configured to access Pazpar2 at: " +pz2config.get("PAZPAR2_URL")); if (pz2config.get("PAZPAR2_SERVICE_XML") != null) { - doc.add("-- App set to use the service definition contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SERVICE_XML")); + doc.add(nl+"-- Configured to use the service definition contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SERVICE_XML")); if (pz2config.get("PAZPAR2_SETTINGS_XML") != null) { - doc.add("-- App set to use the target settings contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SETTINGS_XML")); + doc.add(nl+"-- Configured to use the target settings contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SETTINGS_XML")); } else { - doc.add("-- App set to use the server side target settings as defined in the service definition."); + doc.add(nl+"-- Configured to use the server side target settings as defined in the service definition."); } } else if (pz2config.get("PAZPAR2_SERVICE_ID") != null) { - doc.add("-- App set to use the server side service definition identified by service id \""+pz2config.get("PAZPAR2_SERVICE_ID") + "\""); + doc.add(nl+"-- Configured to use the server side service definition identified by service id \""+pz2config.get("PAZPAR2_SERVICE_ID") + "\""); } else { - doc.add("Error: Did not find service ID nor service definition XML file to set up pazpar2 service."); + doc.add(nl+"Error: Did not find service ID nor service definition XML file for setting up a pazpar2 service."); } return doc; } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java index 4f05b77..0fcc526 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java @@ -24,6 +24,7 @@ public class ErrorHelper implements Serializable { LOCAL_SETTINGS_FILE_NOT_FOUND, MASTERKEY_CONFIG_FILE_NOT_FOUND, MISSING_MANDATORY_PARAMETER, + MISSING_MK2_CONFIG_INIT_PARAMETER, NOT_RESOLVED, SKIP_SUGGESTIONS}; @@ -72,6 +73,10 @@ public class ErrorHelper implements Serializable { return ErrorCode.SKIP_SUGGESTIONS; } else if (appError.getMessage().contains("Missing mandatory parameter")) { return ErrorCode.MISSING_MANDATORY_PARAMETER; + } else if (appError.getMessage().contains("Init parameter") + && appError.getMessage().contains("MASTERKEY") + && appError.getMessage().contains("missing in deployment descriptor")) { + return ErrorCode.MISSING_MK2_CONFIG_INIT_PARAMETER; } return ErrorCode.NOT_RESOLVED; } @@ -113,6 +118,12 @@ public class ErrorHelper implements Serializable { " file used. Please check the property file for the parameter given in the error message "); addConfigurationDocumentation(suggestions); break; + case MISSING_MK2_CONFIG_INIT_PARAMETER: + suggestions.add("A mandatory init parameter was not found in the deployment descriptor (web.xml)." + + " Following init parameters must be present in web.xml when using the Masterkey (MK2) configuration scheme:" + + " MASTERKEY_ROOT_CONFIG_DIR (i.e. '/etc/masterkey'), MASTERKEY_COMPONENT_CONFIG_DIR (i.e. '/myapp'), " + + "MASTERKEY_CONFIG_FILE_NAME (i.e. 'myapp.properties'"); + break; case NOT_RESOLVED: suggestions.add("Unforeseen error situation. No suggestions prepared."); break; diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index 3034a74..1bac38b 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -75,7 +75,7 @@ public class Pz2Session implements Pz2Interface { logger.error("Could not instantiate Pazpar2 client: " + pe.getMessage()); configurationErrors.add(new ConfigurationError("Pz2Client error","ProxyError","Could not create Pazpar2 client: " +pe.getMessage(),errorHelper)); } - logger.info("Got " + configurationErrors.size() + " configuration errors"); + logger.info("Found " + configurationErrors.size() + " configuration errors"); } resetDataObjects(); } else { -- 1.7.10.4