\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Error;\r
+import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
public class ErrorHelper implements Serializable {\r
\r
public enum ErrorCode {PAZPAR2_404, \r
PAZPAR2_UNEXPECTED_RESPONSE,\r
- PAZPAR2_12,\r
PAZPAR2_ERRORS,\r
LOCAL_SERVICE_DEF_FILE_NOT_FOUND,\r
REMOTE_SERVICE_DEF_NOT_FOUND,\r
LOCAL_SETTINGS_FILE_NOT_FOUND,\r
MASTERKEY_CONFIG_FILE_NOT_FOUND,\r
- MISSING_MANDATORY_PARAMETER,\r
+ MISSING_MANDATORY_PROPERTY,\r
MISSING_MK2_CONFIG_INIT_PARAMETER,\r
+ MISSING_CONTEXT_PARAMETER,\r
NOT_RESOLVED,\r
SKIP_SUGGESTIONS};\r
\r
\r
private static Logger logger = Logger.getLogger(ErrorHelper.class);\r
\r
- private Pz2Configurator configurator = null;\r
+ private ConfigurationReader configurator = null;\r
\r
- public ErrorHelper(Pz2Configurator configurator) {\r
+ public ErrorHelper(ConfigurationReader configurator) {\r
this.configurator = configurator;\r
}\r
\r
public ErrorHelper.ErrorCode getErrorCode(ErrorInterface appError) {\r
+ String errmsg = appError.getMessage();\r
if (appError.hasPazpar2Error()) {\r
- Pazpar2Error pz2err = appError.getPazpar2Error();\r
- String pz2errcode = pz2err.getCode();\r
- switch (pz2errcode) {\r
- case "12": \r
- return ErrorCode.PAZPAR2_12;\r
- case "0": \r
- if (pz2err.getMsg().contains("target settings from file")) {\r
- return ErrorCode.LOCAL_SETTINGS_FILE_NOT_FOUND;\r
- } else {\r
- return ErrorCode.PAZPAR2_ERRORS;\r
- }\r
- default: \r
+ if (appError.getPazpar2Error().getMsg().contains("target settings from file")) {\r
+ return ErrorCode.LOCAL_SETTINGS_FILE_NOT_FOUND;\r
+ } else {\r
return ErrorCode.PAZPAR2_ERRORS;\r
}\r
- } else if (appError.getMessage().startsWith("Unexpected HTTP response")) {\r
+ } else if (errmsg.startsWith("Unexpected HTTP response")) {\r
Matcher m = httpResponsePattern.matcher(appError.getMessage());\r
if (m.matches()) {\r
String errorCode = m.group(1);\r
return ErrorCode.PAZPAR2_UNEXPECTED_RESPONSE;\r
}\r
} \r
- } else if (appError.getMessage().contains("Configuration file") & appError.getMessage().contains("properties")) {\r
+ } else if (errmsg.contains("Configuration file") & appError.getMessage().contains("properties")) {\r
return ErrorCode.MASTERKEY_CONFIG_FILE_NOT_FOUND; \r
- } else if (appError.getMessage().contains("Error reading service definition XML")) {\r
+ } else if (errmsg.contains("Error reading service definition XML")) {\r
return ErrorCode.LOCAL_SERVICE_DEF_FILE_NOT_FOUND; \r
- } else if (appError.getMessage().contains("Cannot query Pazpar2 while there are configuration errors")) {\r
+ } else if (errmsg.contains("Cannot query Pazpar2 while there are configuration errors")) {\r
return ErrorCode.SKIP_SUGGESTIONS;\r
- } else if (appError.getMessage().contains("Missing mandatory parameter")) {\r
- return ErrorCode.MISSING_MANDATORY_PARAMETER;\r
- } else if (appError.getMessage().contains("Init parameter")\r
- && appError.getMessage().contains("MASTERKEY")\r
- && appError.getMessage().contains("missing in deployment descriptor")) {\r
+ } else if (errmsg.contains("Missing mandatory parameter")) {\r
+ return ErrorCode.MISSING_MANDATORY_PROPERTY;\r
+ } else if (errmsg.contains("ConfigureByMk2Config") && errmsg.contains("Init parameter") && (errmsg.contains("missing"))) { \r
return ErrorCode.MISSING_MK2_CONFIG_INIT_PARAMETER;\r
+ } else if (appError.getMessage().contains("WebXmlConfigReader could not find mandatory context-param")) {\r
+ return ErrorCode.MISSING_CONTEXT_PARAMETER;\r
}\r
return ErrorCode.NOT_RESOLVED;\r
}\r
ArrayList<String> suggestions = new ArrayList<String>();\r
ErrorCode code = getErrorCode(error);\r
switch (code) {\r
- case PAZPAR2_404:\r
- suggestions.add("Pazpar2 service not found (404). ");\r
- suggestions.add("Please check the PAZPAR2_URL configuration and verify "\r
- + "that a pazpar2 service is running at the given address.");\r
- addConfigurationDocumentation(suggestions); \r
- break;\r
- case PAZPAR2_UNEXPECTED_RESPONSE:\r
- suggestions.add("Unexpected response code from Pazpar2. " + nl\r
- + "Please check the PAZPAR2_URL configuration and verify "\r
- + "that a pazpar2 service is running at the given address." + nl);\r
- break; \r
- case MASTERKEY_CONFIG_FILE_NOT_FOUND: \r
- suggestions.add("The main configuration file that is looked up using parameters" +\r
- " in web.xml (MASTERKEY_ROOT_CONFIG_DIR,MASTERKEY_COMPONENT_CONFIG_DIR,MASTERKEY_CONFIG_FILE_NAME)" +\r
- " could not be found. Please check the web.xml parameters and the expected file system location. "); \r
- break;\r
- case LOCAL_SERVICE_DEF_FILE_NOT_FOUND:\r
- suggestions.add("The service definition file could not be loaded.");\r
- suggestions.add("Please check the configuration and verify that the file exists");\r
- addConfigurationDocumentation(suggestions); \r
- break;\r
- case REMOTE_SERVICE_DEF_NOT_FOUND:\r
- break;\r
- case LOCAL_SETTINGS_FILE_NOT_FOUND:\r
- suggestions.add("A configuration using local target settings file was found, but " +\r
- " the file itself could not be found. Please check the configuration.");\r
- addConfigurationDocumentation(suggestions);\r
- break;\r
- case MISSING_MANDATORY_PARAMETER:\r
- suggestions.add("A mandatory configuration parameter was not found in the MK2 config properties" +\r
- " file used. Please check the property file for the parameter given in the error message ");\r
- addConfigurationDocumentation(suggestions);\r
- break;\r
- case MISSING_MK2_CONFIG_INIT_PARAMETER:\r
- suggestions.add("A mandatory init parameter was not found in the deployment descriptor (web.xml)." +\r
- " Following init parameters must be present in web.xml when using the Masterkey (MK2) configuration scheme:" +\r
- " MASTERKEY_ROOT_CONFIG_DIR (i.e. '/etc/masterkey'), MASTERKEY_COMPONENT_CONFIG_DIR (i.e. '/myapp'), " +\r
- "MASTERKEY_CONFIG_FILE_NAME (i.e. 'myapp.properties'"); \r
- break;\r
- case NOT_RESOLVED:\r
- suggestions.add("Unforeseen error situation. No suggestions prepared.");\r
- break;\r
- case SKIP_SUGGESTIONS:\r
- break;\r
- case PAZPAR2_12: \r
- suggestions.add("The Pazpar2 service does not have a service definition with the requested ID ");\r
- suggestions.add("Please check the service ID set in the configuration and compare it with the " +\r
- " pazpar2 (server side) configuration.");\r
- addConfigurationDocumentation(suggestions); \r
- break;\r
- case PAZPAR2_ERRORS:\r
- if (error.hasPazpar2Error()) {\r
- if (error.getPazpar2Error().getCode().equals("0")) {\r
- \r
+ case MISSING_MK2_CONFIG_INIT_PARAMETER:\r
+ suggestions.add("A mandatory init parameter (context-param) was not found in the deployment descriptor (web.xml)." +\r
+ " Following init parameters must be present when using the MasterKey configuration scheme (ConfigureByMk2Config):" +\r
+ " MASTERKEY_ROOT_CONFIG_DIR (i.e. '/etc/masterkey'), MASTERKEY_COMPONENT_CONFIG_DIR (i.e. '/myapp'), " +\r
+ " MASTERKEY_CONFIG_FILE_NAME (i.e. 'myapp.properties'"); \r
+ break;\r
+ case MISSING_CONTEXT_PARAMETER:\r
+ suggestions.add("A mandatory init parameter (context-param) was not found in the deployment descriptor (web.xml)." +\r
+ " Following init parameters must be present when using WebXmlConfigReader:" +\r
+ " PAZPAR2_URL, PAZPAR2_SERVICE_ID"); \r
+ break;\r
+ case MISSING_MANDATORY_PROPERTY:\r
+ suggestions.add("A mandatory configuration parameter was not found in the MK2 config properties" +\r
+ " file used. Please check the property file for the parameter given in the error message ");\r
+ addConfigurationDocumentation(suggestions);\r
+ break; \r
+ case MASTERKEY_CONFIG_FILE_NOT_FOUND: \r
+ suggestions.add("The main configuration file that is looked up using parameters" +\r
+ " in web.xml (MASTERKEY_ROOT_CONFIG_DIR,MASTERKEY_COMPONENT_CONFIG_DIR,MASTERKEY_CONFIG_FILE_NAME)" +\r
+ " could not be found. Please check the web.xml parameters and the expected file system location. "); \r
+ break;\r
+ case LOCAL_SERVICE_DEF_FILE_NOT_FOUND:\r
+ suggestions.add("The service definition file could not be loaded.");\r
+ suggestions.add("Please check the configuration and verify that the file exists");\r
+ addConfigurationDocumentation(suggestions); \r
+ break;\r
+ case REMOTE_SERVICE_DEF_NOT_FOUND:\r
+ break;\r
+ case LOCAL_SETTINGS_FILE_NOT_FOUND:\r
+ suggestions.add("A configuration using local target settings file was found, but " +\r
+ " the file itself could not be found. Please check the configuration.");\r
+ addConfigurationDocumentation(suggestions);\r
+ break;\r
+ case PAZPAR2_404:\r
+ suggestions.add("Pazpar2 service not found (404). ");\r
+ suggestions.add("Please check the PAZPAR2_URL configuration and verify "\r
+ + "that a pazpar2 service is running at the given address.");\r
+ addConfigurationDocumentation(suggestions); \r
+ break;\r
+ case PAZPAR2_UNEXPECTED_RESPONSE:\r
+ suggestions.add("Unexpected response code from Pazpar2. " + nl\r
+ + "Please check the PAZPAR2_URL configuration and verify "\r
+ + "that a pazpar2 service is running at the given address." + nl);\r
+ break; \r
+ case PAZPAR2_ERRORS:\r
+ if (error.hasPazpar2Error()) {\r
+ String pz2code = error.getPazpar2Error().getCode();\r
+ switch (pz2code) {\r
+ case "3":\r
+ suggestions.add("Query terms not supported.");\r
+ break;\r
+ case "12":\r
+ suggestions.add("The Pazpar2 server does not have a service defined by the requested ID ");\r
+ suggestions.add("Please check the service ID set in the configuration and compare it with the " +\r
+ " configuration on the Pazpar2 server-side.");\r
+ addConfigurationDocumentation(suggestions); \r
+ break;\r
+ case "100":\r
+ suggestions.add("Pazpar2 Service Proxy error");\r
+ suggestions.add("A request was made to the Pazpar2 Service Proxy, but the Service Proxy reports ");\r
+ suggestions.add(" that authentication is lacking. Could be no successful authentication request was made or");\r
+ suggestions.add(" that the Service Proxy session timed out.");\r
+ break;\r
+ default:\r
+ suggestions.add("Pazpar2 error: " + error.getPazpar2Error().getMsg() + " (Pazpar2 # "+error.getPazpar2Error().getCode()+")");\r
+ }\r
+ break;\r
+ } else {\r
+ logger.error("Programming problem. An application error was categorized as a Papzar2 error yet does not have Pazpar2 error information as expected.");\r
}\r
- suggestions.add("Encountered Pazpar2 error: " + error.getPazpar2Error().getMsg() + " ("+error.getPazpar2Error().getCode()+")");\r
- } else {\r
- logger.error("Programming problem. An application error was categorized as a Papzar2 error yet does not have Pazpar2 error information as expected.");\r
- }\r
- break;\r
+ break;\r
+ case SKIP_SUGGESTIONS:\r
+ break; \r
+ case NOT_RESOLVED:\r
+ suggestions.add("Sorry, no troubleshooting suggestions were written for this error scenario just yet.");\r
+ break;\r
}\r
return suggestions;\r
}\r