X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fpz2utils4jsf%2Ferrors%2FErrorHelper.java;h=0664f20e2a4124c267fc9386418155de04a54728;hb=332204f1699f9b7d5714d7e5c49dbe8edaf94d32;hp=0fcc526b1e18c6df6d22611e0833a32fd693845e;hpb=6300a68c2452725149ec64bbaac8416dce4b3aa8;p=mkjsf-moved-to-github.git diff --git a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java index 0fcc526..0664f20 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java @@ -9,22 +9,21 @@ import java.util.regex.Pattern; import org.apache.log4j.Logger; -import com.indexdata.pz2utils4jsf.config.Pz2Configurator; -import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Error; +import com.indexdata.pz2utils4jsf.config.ConfigurationReader; import com.indexdata.pz2utils4jsf.utils.Utils; public class ErrorHelper implements Serializable { public enum ErrorCode {PAZPAR2_404, PAZPAR2_UNEXPECTED_RESPONSE, - PAZPAR2_12, PAZPAR2_ERRORS, LOCAL_SERVICE_DEF_FILE_NOT_FOUND, REMOTE_SERVICE_DEF_NOT_FOUND, LOCAL_SETTINGS_FILE_NOT_FOUND, MASTERKEY_CONFIG_FILE_NOT_FOUND, - MISSING_MANDATORY_PARAMETER, + MISSING_MANDATORY_PROPERTY, MISSING_MK2_CONFIG_INIT_PARAMETER, + MISSING_CONTEXT_PARAMETER, NOT_RESOLVED, SKIP_SUGGESTIONS}; @@ -33,29 +32,21 @@ public class ErrorHelper implements Serializable { private static Logger logger = Logger.getLogger(ErrorHelper.class); - private Pz2Configurator configurator = null; + private ConfigurationReader configurator = null; - public ErrorHelper(Pz2Configurator configurator) { + public ErrorHelper(ConfigurationReader configurator) { this.configurator = configurator; } public ErrorHelper.ErrorCode getErrorCode(ErrorInterface appError) { + String errmsg = appError.getMessage(); if (appError.hasPazpar2Error()) { - Pazpar2Error pz2err = appError.getPazpar2Error(); - String pz2errcode = pz2err.getCode(); - switch (pz2errcode) { - case "12": - return ErrorCode.PAZPAR2_12; - case "0": - if (pz2err.getMsg().contains("target settings from file")) { - return ErrorCode.LOCAL_SETTINGS_FILE_NOT_FOUND; - } else { - return ErrorCode.PAZPAR2_ERRORS; - } - default: + if (appError.getPazpar2Error().getMsg().contains("target settings from file")) { + return ErrorCode.LOCAL_SETTINGS_FILE_NOT_FOUND; + } else { return ErrorCode.PAZPAR2_ERRORS; } - } else if (appError.getMessage().startsWith("Unexpected HTTP response")) { + } else if (errmsg.startsWith("Unexpected HTTP response")) { Matcher m = httpResponsePattern.matcher(appError.getMessage()); if (m.matches()) { String errorCode = m.group(1); @@ -65,18 +56,18 @@ public class ErrorHelper implements Serializable { return ErrorCode.PAZPAR2_UNEXPECTED_RESPONSE; } } - } else if (appError.getMessage().contains("Configuration file") & appError.getMessage().contains("properties")) { + } else if (errmsg.contains("Configuration file") & appError.getMessage().contains("properties")) { return ErrorCode.MASTERKEY_CONFIG_FILE_NOT_FOUND; - } else if (appError.getMessage().contains("Error reading service definition XML")) { + } else if (errmsg.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")) { + } else if (errmsg.contains("Cannot query Pazpar2 while there are configuration errors")) { 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")) { + } else if (errmsg.contains("Missing mandatory parameter")) { + return ErrorCode.MISSING_MANDATORY_PROPERTY; + } else if (errmsg.contains("ConfigureByMk2Config") && errmsg.contains("Init parameter") && (errmsg.contains("missing"))) { return ErrorCode.MISSING_MK2_CONFIG_INIT_PARAMETER; + } else if (appError.getMessage().contains("WebXmlConfigReader could not find mandatory context-param")) { + return ErrorCode.MISSING_CONTEXT_PARAMETER; } return ErrorCode.NOT_RESOLVED; } @@ -85,66 +76,82 @@ public class ErrorHelper implements Serializable { ArrayList suggestions = new ArrayList(); ErrorCode code = getErrorCode(error); switch (code) { - case PAZPAR2_404: - suggestions.add("Pazpar2 service not found (404). "); - suggestions.add("Please check the PAZPAR2_URL configuration and verify " - + "that a pazpar2 service is running at the given address."); - addConfigurationDocumentation(suggestions); - break; - case PAZPAR2_UNEXPECTED_RESPONSE: - 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."); - suggestions.add("Please check the configuration and verify that the file exists"); - addConfigurationDocumentation(suggestions); - break; - case REMOTE_SERVICE_DEF_NOT_FOUND: - break; - case LOCAL_SETTINGS_FILE_NOT_FOUND: - suggestions.add("A configuration using local target settings file was found, but " + - " the file itself could not be found. Please check the configuration."); - addConfigurationDocumentation(suggestions); - break; - case MISSING_MANDATORY_PARAMETER: - suggestions.add("A mandatory configuration parameter was not found in the MK2 config properties" + - " 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; - case SKIP_SUGGESTIONS: - break; - case PAZPAR2_12: - suggestions.add("The Pazpar2 service does not have a service definition with the requested ID "); - suggestions.add("Please check the service ID set in the configuration and compare it with the " + - " pazpar2 (server side) configuration."); - addConfigurationDocumentation(suggestions); - break; - case PAZPAR2_ERRORS: - if (error.hasPazpar2Error()) { - if (error.getPazpar2Error().getCode().equals("0")) { - + case MISSING_MK2_CONFIG_INIT_PARAMETER: + suggestions.add("A mandatory init parameter (context-param) was not found in the deployment descriptor (web.xml)." + + " Following init parameters must be present when using the MasterKey configuration scheme (ConfigureByMk2Config):" + + " 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 MISSING_CONTEXT_PARAMETER: + suggestions.add("A mandatory init parameter (context-param) was not found in the deployment descriptor (web.xml)." + + " Following init parameters must be present when using WebXmlConfigReader:" + + " PAZPAR2_URL, PAZPAR2_SERVICE_ID"); + break; + case MISSING_MANDATORY_PROPERTY: + suggestions.add("A mandatory configuration parameter was not found in the MK2 config properties" + + " file used. Please check the property file for the parameter given in the error message "); + addConfigurationDocumentation(suggestions); + 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."); + suggestions.add("Please check the configuration and verify that the file exists"); + addConfigurationDocumentation(suggestions); + break; + case REMOTE_SERVICE_DEF_NOT_FOUND: + break; + case LOCAL_SETTINGS_FILE_NOT_FOUND: + suggestions.add("A configuration using local target settings file was found, but " + + " the file itself could not be found. Please check the configuration."); + addConfigurationDocumentation(suggestions); + break; + case PAZPAR2_404: + suggestions.add("Pazpar2 service not found (404). "); + suggestions.add("Please check the PAZPAR2_URL configuration and verify " + + "that a pazpar2 service is running at the given address."); + addConfigurationDocumentation(suggestions); + break; + case PAZPAR2_UNEXPECTED_RESPONSE: + 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 PAZPAR2_ERRORS: + if (error.hasPazpar2Error()) { + int pz2code = Integer.parseInt(error.getPazpar2Error().getCode()); + switch (pz2code) { + case 3: + suggestions.add("Query terms not supported."); + break; + case 12: + suggestions.add("The Pazpar2 server does not have a service defined by the requested ID "); + suggestions.add("Please check the service ID set in the configuration and compare it with the " + + " configuration on the Pazpar2 server-side."); + addConfigurationDocumentation(suggestions); + break; + case 100: + suggestions.add("Pazpar2 Service Proxy error"); + suggestions.add("A request was made to the Pazpar2 Service Proxy, but the Service Proxy reports "); + suggestions.add(" that authentication is lacking. Could be no successful authentication request was made or"); + suggestions.add(" that the Service Proxy session timed out."); + break; + default: + suggestions.add("Pazpar2 error: " + error.getPazpar2Error().getMsg() + " (Pazpar2 # "+error.getPazpar2Error().getCode()+")"); + } + break; + } else { + logger.error("Programming problem. An application error was categorized as a Papzar2 error yet does not have Pazpar2 error information as expected."); } - suggestions.add("Encountered Pazpar2 error: " + error.getPazpar2Error().getMsg() + " ("+error.getPazpar2Error().getCode()+")"); - } else { - logger.error("Programming problem. An application error was categorized as a Papzar2 error yet does not have Pazpar2 error information as expected."); - } - break; + break; + case SKIP_SUGGESTIONS: + break; + case NOT_RESOLVED: + suggestions.add("Sorry, no troubleshooting suggestions were written for this error scenario just yet."); + break; } return suggestions; }