From dfcad4c5faeefc5915130c99f1508dee59820f2e Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Wed, 22 May 2013 12:07:25 -0400 Subject: [PATCH] Creates SP response data object .. for the purpose of detecting unsupported SP commands on execution --- .../mkjsf/pazpar2/ServiceProxyExtensions.java | 20 +++++++++----- .../indexdata/mkjsf/pazpar2/data/Responses.java | 12 ++++++--- .../mkjsf/pazpar2/data/sp/AuthResponse.java | 5 +--- .../mkjsf/pazpar2/data/sp/CategoriesResponse.java | 4 +-- .../pazpar2/data/sp/SpResponseDataObject.java | 28 ++++++++++++++++++++ 5 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponseDataObject.java diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java index d283b29..6aeb6ff 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java @@ -20,6 +20,7 @@ import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; import com.indexdata.mkjsf.pazpar2.data.Responses; import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse; +import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; import com.indexdata.mkjsf.utils.Utils; @Named("pz2x") @SessionScoped @@ -158,17 +159,22 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab public CategoriesResponse getCategories () { if (pz2.isServiceProxyService()) { - ResponseDataObject response = pz2.doCommand("categories"); - if (response.hasApplicationError()) { - logger.debug(response.getXml()); + SpResponseDataObject response = (SpResponseDataObject) pz2.doCommand("categories"); + if (response.unsupportedCommand()) { + logger.warn("Command 'categories' not supported by this Service Proxy"); return new CategoriesResponse(); } else { - try { - return (CategoriesResponse) response; - } catch (Exception e) { - e.printStackTrace(); + if (response.hasApplicationError()) { logger.debug(response.getXml()); return new CategoriesResponse(); + } else { + try { + return (CategoriesResponse) response; + } catch (Exception e) { + e.printStackTrace(); + logger.debug(response.getXml()); + return new CategoriesResponse(); + } } } } else { diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java index e076644..6e99317 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java @@ -16,6 +16,7 @@ import org.apache.log4j.Logger; import com.indexdata.mkjsf.errors.ErrorHelper; import com.indexdata.mkjsf.errors.ErrorInterface; +import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses; import com.indexdata.mkjsf.utils.Utils; @@ -44,10 +45,15 @@ public class Responses implements Serializable { logger.info("Error detected in search"); return true; } - for (String name : dataObjects.keySet()) { + for (String name : dataObjects.keySet()) { if (dataObjects.get(name).hasApplicationError()) { - logger.info("Error detected in " + name); - return true; + if (dataObjects.get(name) instanceof SpResponseDataObject && + ((SpResponseDataObject)dataObjects.get(name)).unsupportedCommand()) { + logger.info("Command [" + name + "] not supported by this service"); + } else { + logger.info("Error detected in " + name); + return true; + } } } return false; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/AuthResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/AuthResponse.java index 751f39f..55a7373 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/AuthResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/AuthResponse.java @@ -1,8 +1,6 @@ package com.indexdata.mkjsf.pazpar2.data.sp; -import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; - -public class AuthResponse extends ResponseDataObject { +public class AuthResponse extends SpResponseDataObject { private static final long serialVersionUID = 8006774126022849936L; @@ -22,6 +20,5 @@ public class AuthResponse extends ResponseDataObject { return getOneElementValue("type"); } - } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/CategoriesResponse.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/CategoriesResponse.java index 52cd3d3..2f7ede9 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/CategoriesResponse.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/CategoriesResponse.java @@ -4,10 +4,11 @@ import java.util.ArrayList; import java.util.List; import javax.enterprise.context.SessionScoped; + import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; @SessionScoped -public class CategoriesResponse extends ResponseDataObject { +public class CategoriesResponse extends SpResponseDataObject { private static final long serialVersionUID = 5502182636437956412L; @@ -20,6 +21,5 @@ public class CategoriesResponse extends ResponseDataObject { } return targetCategories; } - } 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 new file mode 100644 index 0000000..2d18536 --- /dev/null +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponseDataObject.java @@ -0,0 +1,28 @@ +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 { + + private static final long serialVersionUID = -3098556883153269199L; + 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")) { + 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