1 package com.indexdata.pz2utils4jsf.pazpar2;
\r
3 import java.util.ArrayList;
\r
4 import java.util.regex.Matcher;
\r
5 import java.util.regex.Pattern;
\r
7 import org.apache.log4j.Logger;
\r
9 import com.indexdata.pz2utils4jsf.config.Pz2Configurator;
\r
10 import com.indexdata.pz2utils4jsf.utils.Utils;
\r
11 import static com.indexdata.pz2utils4jsf.utils.Utils.nl;
\r
13 public class ApplicationTroubleshooter {
\r
15 private static Pattern httpResponsePattern = Pattern.compile("Unexpected HTTP response code \\(([0-9]*)\\).*");
\r
16 private static Logger logger = Logger.getLogger(ApplicationTroubleshooter.class);
\r
18 private Pz2Configurator configurator = null;
\r
20 public ApplicationTroubleshooter(Pz2Configurator configurator) {
\r
21 this.configurator = configurator;
\r
24 public ArrayList<String> getSuggestions(String commandName, String errorMessage) {
\r
25 ArrayList<String> suggestions = new ArrayList<String>();
\r
26 if (errorMessage.startsWith("Unexpected HTTP response")) {
\r
27 Matcher m = httpResponsePattern.matcher(errorMessage);
\r
29 String errorCode = m.group(1);
\r
30 if (errorCode.equals("404")) {
\r
31 suggestions.add("Pazpar2 service not found (response code 404). ");
\r
32 suggestions.add("Please check the PAZPAR2_URL configuration and verify " +
\r
33 "that a pazpar2 service is running at the given address.");
\r
34 suggestions.add("The application was configured using " + Utils.baseObjectName(configurator));
\r
35 suggestions.add("The configurator reports following configuration was used: ");
\r
36 suggestions.addAll(configurator.document());
\r
38 suggestions.add("Response code was " + errorCode + ". " + nl +
\r
39 "Please check the PAZPAR2_URL configuration and verify " +
\r
40 "that a pazpar2 service is running at the given address." + nl);
\r
43 logger.warn("Found message but no pattern match");
\r
46 if (errorMessage == null || errorMessage.length()==0) {
\r
47 logger.debug("No error message found, no suggestions made.");
\r
49 logger.info("No suggestions yet for message " + errorMessage);
\r