From: Niels Erik G. Nielsen Date: Mon, 15 Apr 2013 19:37:12 +0000 (-0400) Subject: Various fixes, clean-up, logs, documentation X-Git-Tag: v0.0.7~156 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=2fefac9612d3675fc10161272f7beaf1b564e0ea;p=mkjsf-moved-to-github.git Various fixes, clean-up, logs, documentation Reinstates error helper that went missing during refactoring Removes XML declaration from pazpar2 error responses in order to inject the XML itself into an application error XML document. Straightens some log statements Moves WELD-001303 error documentation aside (as it is not relevant with current approach) --- diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index 3d7d79c..5a07794 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -59,26 +59,18 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { searchClient = new Pz2Client(); logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" + Utils.objectId(configurator) + "]" ); - configureClient(searchClient,configurator); - stateMgr.addStateListener(this); + configureClient(searchClient,configurator); + stateMgr.addStateListener(this); } public void configureClient(SearchClient searchClient, ConfigurationReader configReader) { - configurationErrors = new ArrayList(); - errorHelper = new ErrorHelper(configReader); + errorHelper = new ErrorHelper(configurator); + logger.info("pz2 " + Utils.objectId(this) + " sets error helper " + Utils.objectId(errorHelper) + " on pzresp " + Utils.objectId(pzresp)); + pzresp.setErrorHelper(errorHelper); + configurationErrors = new ArrayList(); logger.debug(Utils.objectId(this) + " will configure search client for the session"); try { searchClient.configure(configReader); - // At the time of writing this search client is injected using Weld. - // However, the client is used for asynchronously sending off requests - // to the server AND propagation of context to threads is currently - // not supported. Trying to do so throws a WELD-001303 error. - // To avoid that, a context free client is cloned from the context - // dependent one. - // If propagation to threads gets supported, the cloning can go. - // - // Commented as I'm trying with regular instantiation instead - // this.searchClient = searchClient.cloneMe(); } catch (ConfigurationException e) { configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader))); } @@ -215,6 +207,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { * Returns true if application error found in any response data objects */ public boolean hasErrors () { + logger.debug("Checking for configuration errors or command errors."); return hasConfigurationErrors() || hasCommandErrors(); } @@ -239,11 +232,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { pager = new ResultsPager(pzresp,pageRange,pzreq); return pager; } - - protected ErrorHelper getTroubleshooter() { - return errorHelper; - } - + protected void handleQueryStateChanges (String commands) { if (stateMgr.hasPendingStateChange("search") && hasQuery()) { logger.debug("Found pending search change. Doing search before updating " + commands); diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SearchClient.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SearchClient.java index c7d0cf9..54b1648 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SearchClient.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/SearchClient.java @@ -13,7 +13,14 @@ public interface SearchClient extends Configurable, Serializable { public void setSearchCommand(Pazpar2Command command); public CommandResponse executeCommand(Pazpar2Command command, ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException; + + // Use cloneMe() method if injecting the client with CDI. + // The client is used for asynchronously sending off requests + // to the server AND propagation of context to threads is currently + // not supported. Trying to do so throws a WELD-001303 error. + // If propagation to threads gets supported, the cloning can go. public SearchClient cloneMe(); + public boolean isAuthenticatingClient(); public Configuration getConfiguration(); } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/CommandParameter.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/CommandParameter.java index c8f2201..7630ecd 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/CommandParameter.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/CommandParameter.java @@ -21,12 +21,12 @@ public class CommandParameter implements Serializable { Map expressions = new HashMap(); public CommandParameter (String name) { - logger.debug("Instantiating command parameter (1) " + name); + logger.debug("Instantiating command parameter '" + name + "'"); this.name = name; } public CommandParameter (String name, String operator, String value, Expression... expressions) { - logger.debug("Instantiating command parameter (2) " + name + " with " + expressions); + logger.debug("Instantiating command parameter " + name + " with expressions: [" + expressions + "]"); this.name = name; this.operator = operator; this.value = value; @@ -36,14 +36,14 @@ public class CommandParameter implements Serializable { } public CommandParameter (String name, String operator, String value) { - logger.debug("Instantiating command parameter (3) " + name + " ("+this+") with " + value); + logger.debug("Instantiating command parameter '" + name + "' with String: [" + value + "]"); this.name = name; this.operator = operator; this.value = value; } public CommandParameter (String name, String operator, int value) { - logger.debug("Instantiating command parameter (4) " + name + " ("+this+") with " + value); + logger.debug("Instantiating command parameter '" + name + "' with int: [" + value + "]"); this.name = name; this.operator = operator; this.value = value+""; @@ -59,7 +59,7 @@ public class CommandParameter implements Serializable { } public void addExpression(Expression expression) { - logger.debug("Adding expression [" + expression + "] to " + this.getName() + " ("+this+")"); + logger.debug("Adding expression [" + expression + "] to '" + name + "'"); this.expressions.put(expression.toString(),expression); } @@ -111,6 +111,7 @@ public class CommandParameter implements Serializable { } public CommandParameter copy() { + logger.debug("Copying parameter '"+ name + "' for modification"); CommandParameter newParam = new CommandParameter(name); newParam.value = this.value; newParam.operator = this.operator; diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java index b4f67e9..7ef96bd 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/commands/Pazpar2Command.java @@ -20,7 +20,7 @@ public class Pazpar2Command implements Serializable { public Pazpar2Command (String name, StateManager stateMgr) { this.name = name; if (stateMgr == null) { - // Set one-off dummy state mgr + // Sets throw-away state this.stateMgr = new StateManager(); } else { this.stateMgr = stateMgr; @@ -40,30 +40,30 @@ public class Pazpar2Command implements Serializable { } public void setParameter (CommandParameter parameter) { - Pazpar2Command thisCommand = this.copy(); - logger.debug(name + " setting parameter " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName()); - thisCommand.parameters.put(parameter.getName(),parameter); - stateMgr.checkIn(thisCommand); + Pazpar2Command copy = this.copy(); + logger.debug(name + " command: setting parameter [" + parameter.getName() + "=" + parameter.getValueWithExpressions() + "]"); + copy.parameters.put(parameter.getName(),parameter); + stateMgr.checkIn(copy); } public void setParameters (CommandParameter... params) { - Pazpar2Command thisCommand = this.copy(); + Pazpar2Command copy = this.copy(); for (CommandParameter param : params) { - logger.debug(name + " setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName()); - thisCommand.parameters.put(param.getName(),param); + logger.debug(name + " command: setting parameter [" + param.getName() + "=" + param.getValueWithExpressions() + "]"); + copy.parameters.put(param.getName(),param); } - stateMgr.checkIn(thisCommand); + stateMgr.checkIn(copy); } public void setParametersInState (CommandParameter... params) { for (CommandParameter param : params) { - logger.debug(name + " setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName()); + logger.debug(name + " command: setting parameter [" + param.getName() + "=" + param.getValueWithExpressions() + "] silently"); parameters.put(param.getName(),param); } } public void setParameterInState (CommandParameter parameter) { - logger.debug(name + " setting parameter silently " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName()); + logger.debug(name + " command: setting parameter [" + parameter.getName() + "=" + parameter.getValueWithExpressions() + "] silently"); parameters.put(parameter.getName(),parameter); } @@ -73,15 +73,15 @@ public class Pazpar2Command implements Serializable { } public void removeParameter (String name) { - Pazpar2Command thisCommand = this.copy(); - thisCommand.parameters.remove(name); - stateMgr.checkIn(thisCommand); + Pazpar2Command copy = this.copy(); + copy.parameters.remove(name); + stateMgr.checkIn(copy); } public void removeParameters() { - Pazpar2Command thisCommand = this.copy(); - thisCommand.parameters = new HashMap(); - stateMgr.checkIn(thisCommand); + Pazpar2Command copy = this.copy(); + copy.parameters = new HashMap(); + stateMgr.checkIn(copy); } public void removeParametersInState() { diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/CommandError.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/CommandError.java index 05cd506..64080e3 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/CommandError.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/CommandError.java @@ -4,6 +4,7 @@ import static com.indexdata.pz2utils4jsf.utils.Utils.nl; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import com.indexdata.pz2utils4jsf.errors.ErrorInterface; import com.indexdata.pz2utils4jsf.errors.ErrorHelper; @@ -27,6 +28,7 @@ import com.indexdata.utils.XmlUtils; public class CommandError extends Pazpar2ResponseData implements ErrorInterface { private static final long serialVersionUID = 8878776025779714122L; + private static Pattern xmlDeclaration = Pattern.compile("<\\?xml.*\\?>"); private ErrorCode applicationErrorCode; private ErrorHelper errorHelper = null; @@ -98,7 +100,7 @@ public class CommandError extends Pazpar2ResponseData implements ErrorInterface errorXml.append(" "+nl); errorXml.append(" " + commandName + ""+nl); errorXml.append(" " + XmlUtils.escape(exceptionName) + ""+nl); - errorXml.append(pazpar2ErrorXml+nl); + errorXml.append(xmlDeclaration.matcher(pazpar2ErrorXml).replaceAll("")+nl); errorXml.append(" "+nl); errorXml.append(""+nl); return errorXml.toString(); diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java index 4f0daa1..b9da841 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java @@ -10,14 +10,17 @@ import javax.inject.Named; import org.apache.log4j.Logger; +import com.indexdata.pz2utils4jsf.errors.ErrorHelper; import com.indexdata.pz2utils4jsf.errors.ErrorInterface; +import com.indexdata.pz2utils4jsf.utils.Utils; @Named("pzresp") @SessionScoped public class Pazpar2Responses implements Serializable { - + private static final long serialVersionUID = -7543231258346154642L; protected Map dataObjects = new ConcurrentHashMap(); private static Logger logger = Logger.getLogger(Pazpar2Responses.class); + private ErrorHelper errorHelper = null; public Pazpar2Responses() { } @@ -26,6 +29,10 @@ public class Pazpar2Responses implements Serializable { dataObjects.put(name, responseData); } + public void setErrorHelper(ErrorHelper helper) { + this.errorHelper = helper; + } + public boolean hasApplicationError () { if (getSearch().hasApplicationError()) { logger.info("Error detected in search"); @@ -46,18 +53,19 @@ public class Pazpar2Responses implements Serializable { * an empty dummy error. */ public ErrorInterface getCommandError() { - CommandError error = new CommandError(); + CommandError error = new CommandError(); if (dataObjects.get("search").hasApplicationError()) { - error = dataObjects.get("search").getApplicationError(); + error = dataObjects.get("search").getApplicationError(); + error.setErrorHelper(errorHelper); } else { for (String name : dataObjects.keySet()) { if (dataObjects.get(name).hasApplicationError()) { - error = dataObjects.get(name).getApplicationError(); + error = dataObjects.get(name).getApplicationError(); + error.setErrorHelper(errorHelper); break; } } } - // TODO error.setErrorHelper(errorHelper); return error; }