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)
searchClient = new Pz2Client();\r
logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
+ Utils.objectId(configurator) + "]" ); \r
searchClient = new Pz2Client();\r
logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
+ Utils.objectId(configurator) + "]" ); \r
- configureClient(searchClient,configurator);\r
- stateMgr.addStateListener(this);\r
+ configureClient(searchClient,configurator); \r
+ stateMgr.addStateListener(this); \r
} \r
\r
public void configureClient(SearchClient searchClient, ConfigurationReader configReader) {\r
} \r
\r
public void configureClient(SearchClient searchClient, ConfigurationReader configReader) {\r
- configurationErrors = new ArrayList<ErrorInterface>();\r
- errorHelper = new ErrorHelper(configReader); \r
+ errorHelper = new ErrorHelper(configurator);\r
+ logger.info("pz2 " + Utils.objectId(this) + " sets error helper " + Utils.objectId(errorHelper) + " on pzresp " + Utils.objectId(pzresp));\r
+ pzresp.setErrorHelper(errorHelper);\r
+ configurationErrors = new ArrayList<ErrorInterface>(); \r
logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
try {\r
searchClient.configure(configReader); \r
logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
try {\r
searchClient.configure(configReader); \r
- // At the time of writing this search client is injected using Weld. \r
- // However, the client is used for asynchronously sending off requests\r
- // to the server AND propagation of context to threads is currently \r
- // not supported. Trying to do so throws a WELD-001303 error. \r
- // To avoid that, a context free client is cloned from the context \r
- // dependent one. \r
- // If propagation to threads gets supported, the cloning can go.\r
- //\r
- // Commented as I'm trying with regular instantiation instead\r
- // this.searchClient = searchClient.cloneMe(); \r
} catch (ConfigurationException e) {\r
configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader))); \r
} \r
} catch (ConfigurationException e) {\r
configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader))); \r
} \r
* Returns true if application error found in any response data objects \r
*/\r
public boolean hasErrors () {\r
* Returns true if application error found in any response data objects \r
*/\r
public boolean hasErrors () {\r
+ logger.debug("Checking for configuration errors or command errors.");\r
return hasConfigurationErrors() || hasCommandErrors();\r
}\r
\r
return hasConfigurationErrors() || hasCommandErrors();\r
}\r
\r
pager = new ResultsPager(pzresp,pageRange,pzreq);\r
return pager;\r
}\r
pager = new ResultsPager(pzresp,pageRange,pzreq);\r
return pager;\r
}\r
- \r
- protected ErrorHelper getTroubleshooter() {\r
- return errorHelper;\r
- }\r
- \r
protected void handleQueryStateChanges (String commands) {\r
if (stateMgr.hasPendingStateChange("search") && hasQuery()) { \r
logger.debug("Found pending search change. Doing search before updating " + commands); \r
protected void handleQueryStateChanges (String commands) {\r
if (stateMgr.hasPendingStateChange("search") && hasQuery()) { \r
logger.debug("Found pending search change. Doing search before updating " + commands); \r
\r
public void setSearchCommand(Pazpar2Command command);\r
public CommandResponse executeCommand(Pazpar2Command command, ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException;\r
\r
public void setSearchCommand(Pazpar2Command command);\r
public CommandResponse executeCommand(Pazpar2Command command, ByteArrayOutputStream baos) throws Pazpar2ErrorException, IOException;\r
+ \r
+ // Use cloneMe() method if injecting the client with CDI.\r
+ // The client is used for asynchronously sending off requests\r
+ // to the server AND propagation of context to threads is currently \r
+ // not supported. Trying to do so throws a WELD-001303 error. \r
+ // If propagation to threads gets supported, the cloning can go.\r
public SearchClient cloneMe();\r
public SearchClient cloneMe();\r
public boolean isAuthenticatingClient(); \r
public Configuration getConfiguration();\r
}\r
public boolean isAuthenticatingClient(); \r
public Configuration getConfiguration();\r
}\r
Map<String,Expression> expressions = new HashMap<String,Expression>();\r
\r
public CommandParameter (String name) {\r
Map<String,Expression> expressions = new HashMap<String,Expression>();\r
\r
public CommandParameter (String name) {\r
- logger.debug("Instantiating command parameter (1) " + name);\r
+ logger.debug("Instantiating command parameter '" + name + "'");\r
this.name = name;\r
}\r
\r
public CommandParameter (String name, String operator, String value, Expression... expressions) {\r
this.name = name;\r
}\r
\r
public CommandParameter (String name, String operator, String value, Expression... expressions) {\r
- logger.debug("Instantiating command parameter (2) " + name + " with " + expressions);\r
+ logger.debug("Instantiating command parameter " + name + " with expressions: [" + expressions + "]");\r
this.name = name;\r
this.operator = operator;\r
this.value = value;\r
this.name = name;\r
this.operator = operator;\r
this.value = value;\r
}\r
\r
public CommandParameter (String name, String operator, String value) {\r
}\r
\r
public CommandParameter (String name, String operator, String value) {\r
- logger.debug("Instantiating command parameter (3) " + name + " ("+this+") with " + value);\r
+ logger.debug("Instantiating command parameter '" + name + "' with String: [" + value + "]");\r
this.name = name;\r
this.operator = operator;\r
this.value = value; \r
}\r
\r
public CommandParameter (String name, String operator, int value) {\r
this.name = name;\r
this.operator = operator;\r
this.value = value; \r
}\r
\r
public CommandParameter (String name, String operator, int value) {\r
- logger.debug("Instantiating command parameter (4) " + name + " ("+this+") with " + value);\r
+ logger.debug("Instantiating command parameter '" + name + "' with int: [" + value + "]");\r
this.name = name;\r
this.operator = operator;\r
this.value = value+""; \r
this.name = name;\r
this.operator = operator;\r
this.value = value+""; \r
}\r
\r
public void addExpression(Expression expression) {\r
}\r
\r
public void addExpression(Expression expression) {\r
- logger.debug("Adding expression [" + expression + "] to " + this.getName() + " ("+this+")");\r
+ logger.debug("Adding expression [" + expression + "] to '" + name + "'");\r
this.expressions.put(expression.toString(),expression);\r
}\r
\r
this.expressions.put(expression.toString(),expression);\r
}\r
\r
}\r
\r
public CommandParameter copy() {\r
}\r
\r
public CommandParameter copy() {\r
+ logger.debug("Copying parameter '"+ name + "' for modification");\r
CommandParameter newParam = new CommandParameter(name);\r
newParam.value = this.value;\r
newParam.operator = this.operator;\r
CommandParameter newParam = new CommandParameter(name);\r
newParam.value = this.value;\r
newParam.operator = this.operator;\r
public Pazpar2Command (String name, StateManager stateMgr) {\r
this.name = name;\r
if (stateMgr == null) {\r
public Pazpar2Command (String name, StateManager stateMgr) {\r
this.name = name;\r
if (stateMgr == null) {\r
- // Set one-off dummy state mgr\r
+ // Sets throw-away state\r
this.stateMgr = new StateManager();\r
} else {\r
this.stateMgr = stateMgr;\r
this.stateMgr = new StateManager();\r
} else {\r
this.stateMgr = stateMgr;\r
}\r
\r
public void setParameter (CommandParameter parameter) {\r
}\r
\r
public void setParameter (CommandParameter parameter) {\r
- Pazpar2Command thisCommand = this.copy();\r
- logger.debug(name + " setting parameter " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName());\r
- thisCommand.parameters.put(parameter.getName(),parameter);\r
- stateMgr.checkIn(thisCommand);\r
+ Pazpar2Command copy = this.copy();\r
+ logger.debug(name + " command: setting parameter [" + parameter.getName() + "=" + parameter.getValueWithExpressions() + "]");\r
+ copy.parameters.put(parameter.getName(),parameter);\r
+ stateMgr.checkIn(copy);\r
}\r
\r
public void setParameters (CommandParameter... params) {\r
}\r
\r
public void setParameters (CommandParameter... params) {\r
- Pazpar2Command thisCommand = this.copy();\r
+ Pazpar2Command copy = this.copy();\r
for (CommandParameter param : params) {\r
for (CommandParameter param : params) {\r
- logger.debug(name + " setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName());\r
- thisCommand.parameters.put(param.getName(),param);\r
+ logger.debug(name + " command: setting parameter [" + param.getName() + "=" + param.getValueWithExpressions() + "]");\r
+ copy.parameters.put(param.getName(),param);\r
- stateMgr.checkIn(thisCommand);\r
+ stateMgr.checkIn(copy);\r
}\r
\r
public void setParametersInState (CommandParameter... params) { \r
for (CommandParameter param : params) {\r
}\r
\r
public void setParametersInState (CommandParameter... params) { \r
for (CommandParameter param : params) {\r
- logger.debug(name + " setting parameter " + param.getName() + "=" + param.getValueWithExpressions() + " to " + this.getName());\r
+ logger.debug(name + " command: setting parameter [" + param.getName() + "=" + param.getValueWithExpressions() + "] silently");\r
parameters.put(param.getName(),param);\r
} \r
}\r
\r
public void setParameterInState (CommandParameter parameter) {\r
parameters.put(param.getName(),param);\r
} \r
}\r
\r
public void setParameterInState (CommandParameter parameter) {\r
- logger.debug(name + " setting parameter silently " + parameter.getName() + "=" + parameter.getValueWithExpressions() + " to " + this.getName());\r
+ logger.debug(name + " command: setting parameter [" + parameter.getName() + "=" + parameter.getValueWithExpressions() + "] silently");\r
parameters.put(parameter.getName(),parameter); \r
}\r
\r
parameters.put(parameter.getName(),parameter); \r
}\r
\r
}\r
\r
public void removeParameter (String name) {\r
}\r
\r
public void removeParameter (String name) {\r
- Pazpar2Command thisCommand = this.copy();\r
- thisCommand.parameters.remove(name);\r
- stateMgr.checkIn(thisCommand);\r
+ Pazpar2Command copy = this.copy();\r
+ copy.parameters.remove(name);\r
+ stateMgr.checkIn(copy);\r
}\r
\r
public void removeParameters() {\r
}\r
\r
public void removeParameters() {\r
- Pazpar2Command thisCommand = this.copy();\r
- thisCommand.parameters = new HashMap<String,CommandParameter>();\r
- stateMgr.checkIn(thisCommand);\r
+ Pazpar2Command copy = this.copy();\r
+ copy.parameters = new HashMap<String,CommandParameter>();\r
+ stateMgr.checkIn(copy);\r
}\r
\r
public void removeParametersInState() {\r
}\r
\r
public void removeParametersInState() {\r
\r
import java.util.ArrayList;\r
import java.util.List;\r
\r
import java.util.ArrayList;\r
import java.util.List;\r
+import java.util.regex.Pattern;\r
\r
import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
\r
import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
public class CommandError extends Pazpar2ResponseData implements ErrorInterface {\r
\r
private static final long serialVersionUID = 8878776025779714122L;\r
public class CommandError extends Pazpar2ResponseData implements ErrorInterface {\r
\r
private static final long serialVersionUID = 8878776025779714122L;\r
+ private static Pattern xmlDeclaration = Pattern.compile("<\\?xml.*\\?>");\r
private ErrorCode applicationErrorCode;\r
private ErrorHelper errorHelper = null;\r
\r
private ErrorCode applicationErrorCode;\r
private ErrorHelper errorHelper = null;\r
\r
errorXml.append(" <applicationerror>"+nl);\r
errorXml.append(" <commandname>" + commandName + "</commandname>"+nl);\r
errorXml.append(" <exception>" + XmlUtils.escape(exceptionName) + "</exception>"+nl); \r
errorXml.append(" <applicationerror>"+nl);\r
errorXml.append(" <commandname>" + commandName + "</commandname>"+nl);\r
errorXml.append(" <exception>" + XmlUtils.escape(exceptionName) + "</exception>"+nl); \r
- errorXml.append(pazpar2ErrorXml+nl); \r
+ errorXml.append(xmlDeclaration.matcher(pazpar2ErrorXml).replaceAll("")+nl); \r
errorXml.append(" </applicationerror>"+nl);\r
errorXml.append("</" + commandName + ">"+nl);\r
return errorXml.toString(); \r
errorXml.append(" </applicationerror>"+nl);\r
errorXml.append("</" + commandName + ">"+nl);\r
return errorXml.toString(); \r
\r
import org.apache.log4j.Logger;\r
\r
\r
import org.apache.log4j.Logger;\r
\r
+import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
+import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
@Named("pzresp") @SessionScoped\r
public class Pazpar2Responses implements Serializable {\r
\r
@Named("pzresp") @SessionScoped\r
public class Pazpar2Responses implements Serializable {\r
private static final long serialVersionUID = -7543231258346154642L;\r
protected Map<String,Pazpar2ResponseData> dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
private static Logger logger = Logger.getLogger(Pazpar2Responses.class);\r
private static final long serialVersionUID = -7543231258346154642L;\r
protected Map<String,Pazpar2ResponseData> dataObjects = new ConcurrentHashMap<String,Pazpar2ResponseData>();\r
private static Logger logger = Logger.getLogger(Pazpar2Responses.class);\r
+ private ErrorHelper errorHelper = null;\r
\r
public Pazpar2Responses() { \r
}\r
\r
public Pazpar2Responses() { \r
}\r
dataObjects.put(name, responseData);\r
}\r
\r
dataObjects.put(name, responseData);\r
}\r
\r
+ public void setErrorHelper(ErrorHelper helper) { \r
+ this.errorHelper = helper;\r
+ }\r
+ \r
public boolean hasApplicationError () {\r
if (getSearch().hasApplicationError()) {\r
logger.info("Error detected in search");\r
public boolean hasApplicationError () {\r
if (getSearch().hasApplicationError()) {\r
logger.info("Error detected in search");\r
* an empty dummy error. \r
*/ \r
public ErrorInterface getCommandError() {\r
* an empty dummy error. \r
*/ \r
public ErrorInterface getCommandError() {\r
- CommandError error = new CommandError(); \r
+ CommandError error = new CommandError();\r
if (dataObjects.get("search").hasApplicationError()) {\r
if (dataObjects.get("search").hasApplicationError()) {\r
- error = dataObjects.get("search").getApplicationError(); \r
+ error = dataObjects.get("search").getApplicationError();\r
+ error.setErrorHelper(errorHelper);\r
} else {\r
for (String name : dataObjects.keySet()) { \r
if (dataObjects.get(name).hasApplicationError()) { \r
} else {\r
for (String name : dataObjects.keySet()) { \r
if (dataObjects.get(name).hasApplicationError()) { \r
- error = dataObjects.get(name).getApplicationError(); \r
+ error = dataObjects.get(name).getApplicationError();\r
+ error.setErrorHelper(errorHelper);\r
- // TODO error.setErrorHelper(errorHelper);\r