From: Niels Erik G. Nielsen Date: Sat, 9 Mar 2013 04:56:33 +0000 (-0500) Subject: Avoids npe in case of main config file missing X-Git-Tag: v0.0.7~214 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=c3af1f841ac7d7cd350b5b9f18088e3081ef9a85;p=mkjsf-moved-to-github.git Avoids npe in case of main config file missing .. and diagnose the scenario for troubleshooting --- diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java index ac05c0a..a085561 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java @@ -52,7 +52,7 @@ public class Pz2ConfigureByMk2Config implements Pz2Configurator { public List document() { List doc = new ArrayList(); - doc.add("-- Set to access Pazpar2 at: " +pz2config.get("PAZPAR2_URL")); + doc.add("-- App set 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")); if (pz2config.get("PAZPAR2_SETTINGS_XML") != null) { diff --git a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java index f74407d..0abad05 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java @@ -10,6 +10,7 @@ import java.util.regex.Pattern; import org.apache.log4j.Logger; import com.indexdata.pz2utils4jsf.config.Pz2Configurator; +import com.indexdata.pz2utils4jsf.config.Pz2ConfigureByMk2Config; import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Error; import com.indexdata.pz2utils4jsf.utils.Utils; @@ -22,6 +23,7 @@ public class ErrorHelper implements Serializable { LOCAL_SERVICE_DEF_FILE_NOT_FOUND, REMOTE_SERVICE_DEF_NOT_FOUND, LOCAL_SETTINGS_FILE_NOT_FOUND, + MASTERKEY_CONFIG_FILE_NOT_FOUND, NOT_RESOLVED, SKIP_SUGGESTIONS}; @@ -62,6 +64,8 @@ public class ErrorHelper implements Serializable { return ErrorCode.PAZPAR2_UNEXPECTED_RESPONSE; } } + } else if (appError.getMessage().contains("Configuration file") & appError.getMessage().contains("properties")) { + return ErrorCode.MASTERKEY_CONFIG_FILE_NOT_FOUND; } else if (appError.getMessage().contains("Error reading service definition XML")) { return ErrorCode.LOCAL_SERVICE_DEF_FILE_NOT_FOUND; } else if (appError.getMessage().contains("Cannot query Pazpar2 while there are configuration errors")) { @@ -84,6 +88,11 @@ public class ErrorHelper implements Serializable { suggestions.add("Unexpected response code from Pazpar2. " + nl + "Please check the PAZPAR2_URL configuration and verify " + "that a pazpar2 service is running at the given address." + nl); + break; + case MASTERKEY_CONFIG_FILE_NOT_FOUND: + suggestions.add("The main configuration file that is looked up using parameters" + + " in web.xml (MASTERKEY_ROOT_CONFIG_DIR,MASTERKEY_COMPONENT_CONFIG_DIR,MASTERKEY_CONFIG_FILE_NAME)" + + " could not be found. Please check the web.xml parameters and the expected file system location. "); break; case LOCAL_SERVICE_DEF_FILE_NOT_FOUND: suggestions.add("The service definition file could not be loaded."); diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index 2940307..886a0b8 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -68,13 +68,15 @@ public class Pz2Session implements Pz2Interface { logger.error("Could not configure Pazpar2 client: " + io.getMessage()); configurationErrors.add(new ConfigurationError("Pz2Client Config","ProxyError","Could not configure Pazpar2 client: " + io.getMessage(),errorHelper)); } - try { - client = new Pazpar2ClientGeneric(cfg); - } catch (ProxyErrorException pe) { - 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"); + if (cfg != null) { + try { + client = new Pazpar2ClientGeneric(cfg); + } catch (ProxyErrorException pe) { + 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"); + } resetDataObjects(); } else { logger.warn("Attempt to configure session but it already has a configured client"); @@ -293,8 +295,7 @@ public class Pz2Session implements Pz2Interface { return queryStates.getCurrentStateKey(); } - public void setCurrentStateKey(String key) { - logger.debug("************** request to set state key to: [" + key + "]"); + public void setCurrentStateKey(String key) { queryStates.setCurrentStateKey(key); } @@ -323,8 +324,7 @@ public class Pz2Session implements Pz2Interface { return hasConfigurationErrors() || hasCommandErrors(); } - public List getConfigurationErrors() { - logger.info("Returning " + configurationErrors.size() + " configuration errors"); + public List getConfigurationErrors() { return configurationErrors; } @@ -475,5 +475,4 @@ public class Pz2Session implements Pz2Interface { dataObjects.put("search", new SearchResponse()); } - }