From 3cc9707fdd556a222b5d8e6bba61c84a320eb357 Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Wed, 22 May 2013 12:43:16 -0400 Subject: [PATCH] Adds distinction between pz2 and sp errors .. and checks for SP command fall-through to Pazpar2 (unsupported SP commands) --- .../indexdata/mkjsf/errors/ConfigurationError.java | 6 +++--- .../com/indexdata/mkjsf/errors/ErrorHelper.java | 10 ++++----- .../com/indexdata/mkjsf/errors/ErrorInterface.java | 6 +++--- .../com/indexdata/mkjsf/pazpar2/Pz2Client.java | 2 +- .../indexdata/mkjsf/pazpar2/data/CommandError.java | 20 ++++++++++++------ .../indexdata/mkjsf/pazpar2/data/Pazpar2Error.java | 14 ------------- .../mkjsf/pazpar2/data/ResponseDataObject.java | 11 ++++++---- .../mkjsf/pazpar2/data/ResponseParser.java | 2 +- .../indexdata/mkjsf/pazpar2/data/ServiceError.java | 22 ++++++++++++++++++++ .../pazpar2/data/sp/SpResponseDataObject.java | 12 ++--------- 10 files changed, 58 insertions(+), 47 deletions(-) delete mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/data/Pazpar2Error.java create mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/data/ServiceError.java diff --git a/src/main/java/com/indexdata/mkjsf/errors/ConfigurationError.java b/src/main/java/com/indexdata/mkjsf/errors/ConfigurationError.java index 575893b..b844549 100644 --- a/src/main/java/com/indexdata/mkjsf/errors/ConfigurationError.java +++ b/src/main/java/com/indexdata/mkjsf/errors/ConfigurationError.java @@ -3,7 +3,7 @@ package com.indexdata.mkjsf.errors; import java.util.List; import com.indexdata.mkjsf.errors.ErrorHelper.ErrorCode; -import com.indexdata.mkjsf.pazpar2.data.Pazpar2Error; +import com.indexdata.mkjsf.pazpar2.data.ServiceError; public class ConfigurationError implements ErrorInterface { @@ -55,11 +55,11 @@ public class ConfigurationError implements ErrorInterface { return applicationErrorCode; } - public boolean hasPazpar2Error () { + public boolean isServiceError () { return false; } - public Pazpar2Error getPazpar2Error() { + public ServiceError getServiceError() { return null; } diff --git a/src/main/java/com/indexdata/mkjsf/errors/ErrorHelper.java b/src/main/java/com/indexdata/mkjsf/errors/ErrorHelper.java index e75d663..f0da037 100644 --- a/src/main/java/com/indexdata/mkjsf/errors/ErrorHelper.java +++ b/src/main/java/com/indexdata/mkjsf/errors/ErrorHelper.java @@ -40,8 +40,8 @@ public class ErrorHelper implements Serializable { public ErrorHelper.ErrorCode getErrorCode(ErrorInterface appError) { String errmsg = appError.getMessage(); - if (appError.hasPazpar2Error()) { - if (appError.getPazpar2Error().getMsg().contains("target settings from file")) { + if (appError.isServiceError()) { + if (appError.getServiceError().getMsg().contains("target settings from file")) { return ErrorCode.LOCAL_SETTINGS_FILE_NOT_FOUND; } else { return ErrorCode.PAZPAR2_ERRORS; @@ -121,8 +121,8 @@ public class ErrorHelper implements Serializable { + "that a pazpar2 service is running at the given address." + nl); break; case PAZPAR2_ERRORS: - if (error.hasPazpar2Error()) { - int pz2code = Integer.parseInt(error.getPazpar2Error().getCode()); + if (error.isServiceError()) { + int pz2code = Integer.parseInt(error.getServiceError().getCode()); switch (pz2code) { case 3: suggestions.add("The search experienced a problem with the query terms."); @@ -140,7 +140,7 @@ public class ErrorHelper implements Serializable { suggestions.add(" that the Service Proxy session timed out."); break; default: - suggestions.add("Pazpar2 error: " + error.getPazpar2Error().getMsg() + " (Pazpar2 # "+error.getPazpar2Error().getCode()+")"); + suggestions.add("Pazpar2 error: " + error.getServiceError().getMsg() + " (Pazpar2 # "+error.getServiceError().getCode()+")"); } break; } else { diff --git a/src/main/java/com/indexdata/mkjsf/errors/ErrorInterface.java b/src/main/java/com/indexdata/mkjsf/errors/ErrorInterface.java index feb578c..7754c13 100644 --- a/src/main/java/com/indexdata/mkjsf/errors/ErrorInterface.java +++ b/src/main/java/com/indexdata/mkjsf/errors/ErrorInterface.java @@ -4,7 +4,7 @@ import java.io.Serializable; import java.util.List; import com.indexdata.mkjsf.errors.ErrorHelper.ErrorCode; -import com.indexdata.mkjsf.pazpar2.data.Pazpar2Error; +import com.indexdata.mkjsf.pazpar2.data.ServiceError; public interface ErrorInterface extends Serializable { @@ -16,7 +16,7 @@ public interface ErrorInterface extends Serializable { public ErrorCode getApplicationErrorCode(); public List getSuggestions(); public void setErrorHelper(ErrorHelper helper); - public boolean hasPazpar2Error(); - public Pazpar2Error getPazpar2Error(); + public boolean isServiceError(); + public ServiceError getServiceError(); } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java index 9d4ee91..6dfe77f 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/Pz2Client.java @@ -129,7 +129,7 @@ public class Pz2Client implements SearchClient { logger.error(e.getMessage()); e.printStackTrace(); logger.error("Creating error XML"); - commandResponse = new ClientCommandResponse(0,CommandError.createErrorXml(command.getCommandName(), "", "Pazpar2Error", e.getMessage(),""),"text/xml"); + commandResponse = new ClientCommandResponse(0,CommandError.createErrorXml(command.getCommandName(), "", "ServiceError", e.getMessage(),""),"text/xml"); } long end = System.currentTimeMillis(); logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." ); diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/CommandError.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/CommandError.java index ede8767..54aa8f6 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/CommandError.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/CommandError.java @@ -41,8 +41,8 @@ public class CommandError extends ResponseDataObject implements ErrorInterface { } public String getMessage() { - if (hasPazpar2Error()) { - return getPazpar2Error().getMsg(); + if (isServiceError()) { + return getServiceError().getMsg(); } else { return getOneElementValue("errormessage"); } @@ -129,13 +129,21 @@ public class CommandError extends ResponseDataObject implements ErrorInterface { return applicationErrorCode; } - public boolean hasPazpar2Error () { - return ( getOneElement("error") != null); + public boolean isServiceError () { + ServiceError pz2err = (ServiceError) getOneElement("error"); + return (pz2err != null); } - public Pazpar2Error getPazpar2Error() { - return (Pazpar2Error) getOneElement("error"); + public ServiceError getServiceError() { + return (ServiceError) getOneElement("error"); + } + + public boolean isServiceProxyError () { + return (isServiceError() && getServiceError().isServiceProxyError()); } + public boolean isPazpar2Error () { + return (isServiceError() && getServiceError().isPazpar2Error()); + } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Pazpar2Error.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Pazpar2Error.java deleted file mode 100644 index b46cb8b..0000000 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Pazpar2Error.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.indexdata.mkjsf.pazpar2.data; - -public class Pazpar2Error extends ResponseDataObject { - - private static final long serialVersionUID = -7060267782024414318L; - - public String getCode() { - return getAttribute("code"); - } - - public String getMsg() { - return getAttribute("msg"); - } -} diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java index 3fe9803..8ffd810 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseDataObject.java @@ -108,12 +108,15 @@ public class ResponseDataObject implements Serializable { return (CommandError) getOneElement("applicationerror"); } - public boolean hasPazpar2Error() { - return hasApplicationError() && getApplicationError().hasPazpar2Error(); + public boolean hasServiceError() { + return hasApplicationError() + && getApplicationError().isServiceError(); } - - + public ServiceError getServiceError() { + return (hasServiceError()? getApplicationError().getServiceError() : null); + } + public void setXml(String xml) { this.xml = xml; } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseParser.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseParser.java index cf60173..179424d 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseParser.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ResponseParser.java @@ -120,7 +120,7 @@ public class ResponseParser extends DefaultHandler { } else if (localName.equals("applicationerror")) { currentElement = new CommandError(); } else if (localName.equals("error") && dataElements.peek().getType().equals("applicationerror")) { - currentElement = new Pazpar2Error(); + currentElement = new ServiceError(); // Service Proxy extras } else if (localName.equals("auth")) { currentElement = new AuthResponse(); diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/ServiceError.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ServiceError.java new file mode 100644 index 0000000..5969670 --- /dev/null +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/ServiceError.java @@ -0,0 +1,22 @@ +package com.indexdata.mkjsf.pazpar2.data; + +public class ServiceError extends ResponseDataObject { + + private static final long serialVersionUID = -7060267782024414318L; + + public String getCode() { + return getAttribute("code"); + } + + public String getMsg() { + return getAttribute("msg"); + } + + public boolean isPazpar2Error() { + return (getCode() != null && getCode().length()>0 && Integer.parseInt(getCode())<100); + } + + public boolean isServiceProxyError() { + return (getCode() != null && getCode().length()>0 && Integer.parseInt(getCode())>100); + } +} diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponseDataObject.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponseDataObject.java index 2d18536..81b1c18 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponseDataObject.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponseDataObject.java @@ -2,7 +2,6 @@ package com.indexdata.mkjsf.pazpar2.data.sp; import org.apache.log4j.Logger; -import com.indexdata.mkjsf.pazpar2.data.ServiceError; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; public class SpResponseDataObject extends ResponseDataObject { @@ -11,18 +10,11 @@ public class SpResponseDataObject extends ResponseDataObject { private static Logger logger = Logger.getLogger(SpResponseDataObject.class); public boolean unsupportedCommand() { - if (hasServiceError()) { - ServiceError serviceError = getApplicationError().getServiceError(); - if (serviceError.getValue().equals("command") && - serviceError.getCode().equals("3")) { + if (hasServiceError() && getServiceError().getCode().equalsIgnoreCase("3")) { logger.warn("The " + getType() + " command not supported by this Service Proxy (request fell through SP to Pazpar2)."); return true; - } else { - logger.error("Error encountered: " + serviceError.getCode() + ": " + serviceError.getMsg()); - return false; - } } return false; } - + } -- 1.7.10.4