\r
import com.indexdata.masterkey.config.MasterkeyConfiguration;\r
import com.indexdata.masterkey.config.ModuleConfiguration;\r
+import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
import static com.indexdata.pz2utils4jsf.utils.Utils.nl;\r
\r
}\r
\r
@Override\r
- public Pz2Config getConfig() throws IOException {\r
+ public Pz2Config getConfig() throws ConfigurationException {\r
if (pz2config == null) {\r
createConfig();\r
}\r
return pz2config;\r
}\r
\r
- private void createConfig () throws IOException {\r
+ private void createConfig () throws ConfigurationException {\r
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();\r
ServletContext servletContext = (ServletContext) externalContext.getContext(); \r
- MasterkeyConfiguration mkConfigContext =\r
- MasterkeyConfiguration.getInstance(servletContext,\r
- "pazpar-application-jsf", ((HttpServletRequest) externalContext.getRequest()).getServerName());\r
- configFilePathAndName = mkConfigContext.getConfigFileLocation().getConfigFilePath();\r
- ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client");\r
- pz2config = new Pz2Config(moduleConfig);\r
- logger.info(document());\r
+ MasterkeyConfiguration mkConfigContext;\r
+ try {\r
+ mkConfigContext = MasterkeyConfiguration.getInstance(servletContext,\r
+ "pazpar-application-jsf", ((HttpServletRequest) externalContext.getRequest()).getServerName());\r
+ } catch (IOException e) {\r
+ throw new ConfigurationException("Pz2ConfigureByMk2Config could not configure Pazpar2 client using MasterKey configuration scheme: "+e.getMessage(),e);\r
+ }\r
+ configFilePathAndName = mkConfigContext.getConfigFileLocation().getConfigFilePath(); \r
+ try {\r
+ ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client");\r
+ pz2config = new Pz2Config(moduleConfig);\r
+ logger.info(document());\r
+ } catch (IOException e) {\r
+ throw new ConfigurationException("Pz2ConfigureByMk2Config could not get configuration for module 'pz2client': "+e.getMessage(),e);\r
+ } \r
}\r
\r
\r
public List<String> document() {\r
List<String> doc = new ArrayList<String>();\r
- doc.add("Attempted to configure service using the file " + configFilePathAndName);\r
+ doc.add(":"+nl+"Attempted to configure service using the file " + configFilePathAndName);\r
doc.add(nl+"-- Configured to access Pazpar2 at: " +pz2config.get("PAZPAR2_URL"));\r
if (pz2config.get("PAZPAR2_SERVICE_XML") != null) {\r
doc.add(nl+"-- Configured to use the service definition contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SERVICE_XML"));\r
package com.indexdata.pz2utils4jsf.config;\r
\r
-import java.io.IOException;\r
+import static com.indexdata.pz2utils4jsf.utils.Utils.nl;\r
+\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.List;\r
\r
import org.apache.log4j.Logger;\r
\r
+import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
+\r
\r
@Named @SessionScoped @Alternative\r
public class Pz2ConfigureByWebXml implements Pz2Configurator {\r
private static final long serialVersionUID = 144390224959311772L;\r
private static Logger logger = Logger.getLogger(Pz2ConfigureByWebXml.class);\r
private Pz2Config pz2config = null;\r
+ private Map<String,String> parameters = new HashMap<String,String>(); \r
\r
public Pz2ConfigureByWebXml () {\r
logger.info("Instantiating Pazpar2 service configuration by web.xml parameters");\r
}\r
\r
@Override\r
- public Pz2Config getConfig() throws IOException {\r
+ public Pz2Config getConfig() throws ConfigurationException {\r
if (pz2config == null) {\r
createConfig();\r
}\r
return pz2config;\r
}\r
\r
- private void createConfig () throws IOException {\r
+ private void createConfig () throws ConfigurationException {\r
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();\r
- ServletContext servletContext = (ServletContext) externalContext.getContext();\r
- Map<String,String> parameters = new HashMap<String,String>();\r
+ ServletContext servletContext = (ServletContext) externalContext.getContext(); \r
parameters.put("PAZPAR2_URL", servletContext.getInitParameter("PAZPAR2_URL"));\r
+ if (parameters.get("PAZPAR2_URL")==null || parameters.get("PAZPAR2_URL").length()==0) { \r
+ throw new ConfigurationException("Pz2ConfigureByWebXml could not find mandatory context-param 'PAZPAR2_URL'");\r
+ }\r
parameters.put("PAZPAR2_SERVICE_ID", servletContext.getInitParameter("PAZPAR2_SERVICE_ID"));\r
- pz2config = new Pz2Config(parameters); \r
+ if (parameters.get("PAZPAR2_SERVICE_ID")==null || parameters.get("PAZPAR2_SERVICE_ID").length()==0) { \r
+ throw new ConfigurationException("Pz2ConfigureByWebXml could not find mandatory context-param 'PAZPAR2_SERVICE_ID'");\r
+ }\r
+ pz2config = new Pz2Config(parameters);\r
}\r
\r
public List<String> document() {\r
- List<String> doc = new ArrayList<String>();\r
- doc.add("No documentation written yet for this configurator");\r
- return doc;\r
+ List<String> doc = new ArrayList<String>(); \r
+ doc.add("Attempted to configure service using web.xml context-parameters ");\r
+ doc.add(nl+"-- Configured to access Pazpar2 at [" +parameters.get("PAZPAR2_URL") + "]");\r
+ doc.add(nl+"-- Configured to use the server side service definition identified by service id [" +parameters.get("PAZPAR2_SERVICE_ID") + "]");\r
+ return doc; \r
}\r
}\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.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
\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("Pz2ConfigureByMk2Config") && errmsg.contains("Init parameter") && (errmsg.contains("missing"))) { \r
return ErrorCode.MISSING_MK2_CONFIG_INIT_PARAMETER;\r
+ } else if (appError.getMessage().contains("Pz2ConfigureByWebXml 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 (Pz2ConfigureByMk2Config):" +\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 Pz2ConfigureByWebXml:" +\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
+ 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