Adds checks for unsupported commands
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Wed, 22 May 2013 17:56:56 +0000 (13:56 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Wed, 22 May 2013 17:56:56 +0000 (13:56 -0400)
Avoids running unsupported 'categories' repeatedly.
Warns in log about unsupported 'auth' command.

src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyExtensions.java
src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java
src/main/java/com/indexdata/mkjsf/pazpar2/data/sp/SpResponseDataObject.java

index 6aeb6ff..c10c55e 100644 (file)
@@ -3,6 +3,8 @@ package com.indexdata.mkjsf.pazpar2;
 import java.io.IOException;\r
 import java.io.Serializable;\r
 import java.io.UnsupportedEncodingException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
 \r
 import javax.enterprise.context.SessionScoped;\r
 import javax.inject.Inject;\r
@@ -36,25 +38,31 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab
   @Inject Pz2Bean pz2;\r
   @Inject Pazpar2Commands pzreq;\r
   @Inject Responses pzresp;\r
-\r
-  \r
+    \r
   public ServiceProxyExtensions() {\r
     this.initDocUpload = new InitDocUpload(this);\r
     // TODO: \r
     //stateMgr.addStateListener(this);\r
   }\r
-   \r
+     \r
   public void authenticate() {\r
+    String command = "auth";\r
+    if (pzresp.getSp().getAuth().unsupportedCommand()) {\r
+      logger.warn("Running seemingly unsupported command [auth] against SP.");\r
+    }\r
     pz2.resetSearchAndRecordCommands();\r
     pzresp.getSp().resetAuthAndBeyond(true);\r
     AuthCommand auth = pzreq.getSp().getAuth();     \r
     ClientCommandResponse commandResponse = pz2.getSpClient().send(auth);      \r
-    String renamedResponse = renameResponseElement(commandResponse.getResponseString(), "auth");\r
+    String renamedResponse = renameResponseElement(commandResponse.getResponseString(), "auth");    \r
     commandResponse.setResponseToParse(renamedResponse);\r
-    ResponseDataObject responseObject = ResponseParser.getParser().getDataObject(commandResponse);\r
+    SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(commandResponse);    \r
     if (ResponseParser.docTypes.contains(responseObject.getType())) {\r
       pzresp.put(auth.getCommandName(), responseObject);\r
     }\r
+    if (responseObject.unsupportedCommand()) {\r
+      logger.error("auth command does not seem to be supported by this Service Proxy");\r
+    }\r
     String responseStr = commandResponse.getResponseString();\r
     logger.info(responseStr);          \r
   }\r
@@ -157,24 +165,25 @@ public class ServiceProxyExtensions implements ServiceProxyInterface, Serializab
     return initDocUpload;\r
   }\r
   \r
-  public CategoriesResponse getCategories () {\r
+  public CategoriesResponse getCategories () {       \r
+    String command="categories";\r
     if (pz2.isServiceProxyService()) {\r
-      SpResponseDataObject response = (SpResponseDataObject) pz2.doCommand("categories");\r
-      if (response.unsupportedCommand()) {\r
-        logger.warn("Command 'categories' not supported by this Service Proxy");        \r
+      if (pzresp.getSp().getCategories().unsupportedCommand()) {\r
+        logger.info("Skipping seemingly unsupported command: " + command);  \r
         return new CategoriesResponse();\r
       } else {\r
-        if (response.hasApplicationError()) {\r
-          logger.debug(response.getXml());\r
-          return new CategoriesResponse();\r
-        } else {\r
-          try {\r
+        SpResponseDataObject response = (SpResponseDataObject) pz2.doCommand(command);\r
+        if (response.unsupportedCommand()) {\r
+          logger.warn("Command 'categories' not supported by this Service Proxy");          \r
+        } else if (response.hasApplicationError()) {\r
+          logger.error(response.getXml());            \r
+        }  \r
+        try {\r
             return (CategoriesResponse) response;\r
-          } catch (Exception e) {\r
+        } catch (Exception e) {\r
             e.printStackTrace();\r
             logger.debug(response.getXml());\r
             return new CategoriesResponse();\r
-          }\r
         }\r
       }\r
     } else {\r
index 6e99317..ef6526b 100644 (file)
@@ -49,7 +49,7 @@ public class Responses implements Serializable {
       if (dataObjects.get(name).hasApplicationError()) {\r
         if (dataObjects.get(name) instanceof SpResponseDataObject &&\r
            ((SpResponseDataObject)dataObjects.get(name)).unsupportedCommand()) {\r
-            logger.info("Command  [" + name + "] not supported by this service");                    \r
+            logger.debug("Command  [" + name + "] not supported by this service");                    \r
         } else {\r
           logger.info("Error detected in " + name);\r
           return true;\r
index 81b1c18..2620723 100644 (file)
@@ -1,17 +1,15 @@
 package com.indexdata.mkjsf.pazpar2.data.sp;\r
 \r
-import org.apache.log4j.Logger;\r
-\r
 import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject;\r
 \r
 public class SpResponseDataObject extends ResponseDataObject {\r
 \r
-  private static final long serialVersionUID = -3098556883153269199L;\r
-  private static Logger logger = Logger.getLogger(SpResponseDataObject.class);\r
+  private static final long serialVersionUID = -3098556883153269199L;  \r
 \r
   public boolean unsupportedCommand() {\r
-    if (hasServiceError() && getServiceError().getCode().equalsIgnoreCase("3")) {\r
-        logger.warn("The " + getType() + " command not supported by this Service Proxy (request fell through SP to Pazpar2).");\r
+    if (hasServiceError() \r
+        && getServiceError().getCode().equals("3")\r
+        && getServiceError().getValue().equals("command")) {        \r
         return true;\r
     }\r
     return false;\r