From: Niels Erik G. Nielsen Date: Wed, 6 Mar 2013 23:12:01 +0000 (-0500) Subject: Debug stmts and fix for double object instantiation X-Git-Tag: v0.0.7~219 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=c7293a0fadc8a364a2f71a2cada38df685fb8720;p=mkjsf-moved-to-github.git Debug stmts and fix for double object instantiation Spurious objects created by CDI due to the way some of the pz2 bean and config constructors where written. --- diff --git a/src/META-INF/faces-config.xml b/src/META-INF/faces-config.xml deleted file mode 100644 index a7b9df0..0000000 --- a/src/META-INF/faces-config.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java index b3a92e1..b182777 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Config.java @@ -5,12 +5,17 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import javax.enterprise.context.SessionScoped; +import javax.inject.Named; + import org.apache.log4j.Logger; import com.indexdata.masterkey.config.MissingMandatoryParameterException; import com.indexdata.masterkey.config.ModuleConfiguration; import com.indexdata.masterkey.config.ModuleConfigurationGetter; +import com.indexdata.pz2utils4jsf.utils.Utils; +@Named @SessionScoped public class Pz2Config implements ModuleConfigurationGetter, Serializable { private static final long serialVersionUID = -6801241975338182197L; @@ -19,10 +24,12 @@ public class Pz2Config implements ModuleConfigurationGetter, Serializable { ModuleConfiguration moduleConfig = null; public Pz2Config () { + logger.debug(Utils.objectId(this) + " being constructed with no argument"); setDefaults(); } public Pz2Config (Map parameters) { + logger.debug(Utils.objectId(this) + " being constructed with parameter map argument"); setDefaults(); for (String key : parameters.keySet()) { properties.put(key, parameters.get(key)); @@ -30,6 +37,7 @@ public class Pz2Config implements ModuleConfigurationGetter, Serializable { } public Pz2Config (ModuleConfiguration moduleConfig) throws IOException { + logger.debug(Utils.objectId(this) + " being constructed with moduleConfig argument."); this.moduleConfig = moduleConfig; for (String key : moduleConfig.getConfigMap().keySet()) { properties.put(key, moduleConfig.getConfigParameter(key)); diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Configurator.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Configurator.java index b778821..88b275d 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Configurator.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2Configurator.java @@ -1,7 +1,8 @@ package com.indexdata.pz2utils4jsf.config; +import java.io.IOException; import java.io.Serializable; public interface Pz2Configurator extends Serializable { - public Pz2Config getConfig(); + public Pz2Config getConfig() throws IOException; } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java index b4859b3..2273b7a 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByMk2Config.java @@ -14,6 +14,7 @@ import org.apache.log4j.Logger; import com.indexdata.masterkey.config.MasterkeyConfiguration; import com.indexdata.masterkey.config.ModuleConfiguration; +import com.indexdata.pz2utils4jsf.utils.Utils; @Named @SessionScoped @Alternative public class Pz2ConfigureByMk2Config implements Pz2Configurator { @@ -23,7 +24,18 @@ public class Pz2ConfigureByMk2Config implements Pz2Configurator { private Pz2Config pz2config = null; public Pz2ConfigureByMk2Config () throws IOException { - logger.debug("Instantiating Pazpar2 service configuration by MasterKey configuration scheme."); + logger.info(Utils.objectId(this) + " is instantiating Pazpar2 service configuration by MasterKey configuration scheme."); + } + + @Override + public Pz2Config getConfig() throws IOException { + if (pz2config == null) { + createConfig(); + } + return pz2config; + } + + private void createConfig () throws IOException { ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); ServletContext servletContext = (ServletContext) externalContext.getContext(); MasterkeyConfiguration mkConfigContext = @@ -31,11 +43,20 @@ public class Pz2ConfigureByMk2Config implements Pz2Configurator { "pazpar-application-jsf", ((HttpServletRequest) externalContext.getRequest()).getServerName()); ModuleConfiguration moduleConfig = mkConfigContext.getModuleConfiguration("pz2client"); pz2config = new Pz2Config(moduleConfig); - } - - @Override - public Pz2Config getConfig() { - return pz2config; + logger.info("Accessing Pazpar2 at: " +pz2config.get("PAZPAR2_URL")); + if (pz2config.get("PAZPAR2_SERVICE_XML") != null) { + logger.info("Using the service definition contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SERVICE_XML")); + if (pz2config.get("PAZPAR2_SETTINGS_XML") != null) { + logger.info("Using the target settings contained in " + pz2config.getConfigFilePath() + "/" + pz2config.get("PAZPAR2_SETTINGS_XML")); + } else { + logger.info("Using the server side target settings as defined in the service definition."); + } + } else if (pz2config.get("PAZPAR2_SERVICE_ID") != null) { + logger.info("Using the server side service definition identified by service id "+pz2config.get("PAZPAR2_SERVICE_ID")); + } else { + logger.error("Did not find service ID nor service definition XML file so set up pazpar2 service."); + } + } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java index 72c5d75..d131e94 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/config/Pz2ConfigureByWebXml.java @@ -1,5 +1,6 @@ package com.indexdata.pz2utils4jsf.config; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -18,20 +19,25 @@ public class Pz2ConfigureByWebXml implements Pz2Configurator { private static final long serialVersionUID = 144390224959311772L; private static Logger logger = Logger.getLogger(Pz2ConfigureByWebXml.class); - private Pz2Config config = null; + private Pz2Config pz2config = null; public Pz2ConfigureByWebXml () { - logger.debug("Instantiating Pazpar2 service configuration by web.xml parameters"); + logger.info("Instantiating Pazpar2 service configuration by web.xml parameters"); + } + + public Pz2Config getConfig() throws IOException { + if (pz2config == null) { + createConfig(); + } + return pz2config; + } + + private void createConfig () throws IOException { ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); ServletContext servletContext = (ServletContext) externalContext.getContext(); Map parameters = new HashMap(); parameters.put("PAZPAR2_URL", servletContext.getInitParameter("PAZPAR2_URL")); parameters.put("PAZPAR2_SERVICE_ID", servletContext.getInitParameter("PAZPAR2_SERVICE_ID")); - config = new Pz2Config(parameters); - } - - @Override - public Pz2Config getConfig() { - return config; + pz2config = new Pz2Config(parameters); } } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index e5cfb1c..41ca130 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -18,9 +18,9 @@ import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.StatResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.TermListsResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse; +import com.indexdata.pz2utils4jsf.utils.Utils; -@Named("pz2") -@SessionScoped +@Named("pz2") @SessionScoped public class Pz2Bean implements Pz2Interface, Serializable { private static final long serialVersionUID = 3440277287081557861L; @@ -30,19 +30,21 @@ public class Pz2Bean implements Pz2Interface, Serializable { @Inject Pz2Configurator pz2conf; public Pz2Bean () { - logger.debug("Instantiating pz2 bean"); - pz2 = new Pz2Session(); + logger.info("Instantiating pz2 bean [" + Utils.objectId(this) + "]"); } @PostConstruct public void initiatePz2Session() { + logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session next."); + pz2 = new Pz2Session(); + logger.debug(Utils.objectId(this) + " will forward configuration to the new Pz2Session [" + Utils.objectId(pz2) + "]"); pz2.init(pz2conf); } /* (non-Javadoc) * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#doSearch(java.lang.String) */ - public void doSearch(String query) { + public void doSearch(String query) { pz2.doSearch(query); } @@ -50,6 +52,7 @@ public class Pz2Bean implements Pz2Interface, Serializable { * @see com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface#doSearch() */ public void doSearch() { + logger.info(Utils.objectId(this) + " doing search for "+this.getQuery()); pz2.doSearch(); } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java index b4323fc..9675696 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Session.java @@ -1,5 +1,6 @@ package com.indexdata.pz2utils4jsf.pazpar2; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -23,9 +24,9 @@ import com.indexdata.pz2utils4jsf.pazpar2.data.StatResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.TermListsResponse; import com.indexdata.pz2utils4jsf.pazpar2.data.TermResponse; import com.indexdata.pz2utils4jsf.pazpar2.state.QueryStates; +import com.indexdata.pz2utils4jsf.utils.Utils; -@Named -@SessionScoped +@Named @SessionScoped public class Pz2Session implements Pz2Interface { private static Logger logger = Logger.getLogger(Pz2Session.class); @@ -40,21 +41,23 @@ public class Pz2Session implements Pz2Interface { private ResultsPager pager = null; public Pz2Session () { - logger.debug("Instantiating pz2 session object"); + logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]"); } public void init(Pz2Configurator pz2conf) { if (client==null) { - logger.debug("Initiating a session holding object "); + logger.info(Utils.objectId(this) + " is configuring itself using the provided " + Utils.objectId(pz2conf)); try { cfg = new com.indexdata.masterkey.pazpar2.client.Pazpar2ClientConfiguration(pz2conf.getConfig()); client = new com.indexdata.masterkey.pazpar2.client.Pazpar2ClientGeneric(cfg); resetDataObjects(); } catch (ProxyErrorException e) { e.printStackTrace(); - } + } catch (IOException ioe) { + ioe.printStackTrace(); + } } else { - logger.error("??? attempt to initiate session but already has a client"); + logger.warn("Attempt to configure session but it already has a configured client"); } } @@ -67,7 +70,7 @@ public class Pz2Session implements Pz2Interface { queryStates.hasPendingStateChange("search",false); resetDataObjects(); setCommandParameter("show",new CommandParameter("start","=",0)); - logger.info("Searching using "+getCommand("search").getParameter("query").getEncodedQueryString()); + logger.debug(Utils.objectId(this) + " is searching using "+getCommand("search").getParameter("query").getEncodedQueryString()); doCommand("search"); } @@ -77,7 +80,7 @@ public class Pz2Session implements Pz2Interface { * @return Number of activeclients at the time of the 'show' command. */ public String update () { - logger.info("Updating show,stat,termlist, and bytarget data from pazpar2"); + logger.debug("Updating show,stat,termlist,bytarget from pazpar2"); return update("show,stat,termlist,bytarget"); } @@ -113,7 +116,7 @@ public class Pz2Session implements Pz2Interface { } return getActiveClients(); } else { - logger.info("Skipped requests for " + commands + " as there's not yet a query."); + logger.debug("Skipped requests for " + commands + " as there's not yet a query."); resetDataObjects(); return "0"; } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/utils/Utils.java b/src/main/java/com/indexdata/pz2utils4jsf/utils/Utils.java new file mode 100644 index 0000000..e17c224 --- /dev/null +++ b/src/main/java/com/indexdata/pz2utils4jsf/utils/Utils.java @@ -0,0 +1,14 @@ +package com.indexdata.pz2utils4jsf.utils; + +public class Utils { + + public static String objectId(Object o) { + int lastdot = o.toString().lastIndexOf('.'); + if (lastdot>-1 && lastdot+1