Adds distinction between pz2 and sp errors
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / Pz2Client.java
index 2e6ca31..6dfe77f 100644 (file)
@@ -59,7 +59,7 @@ public class Pz2Client implements SearchClient {
     } \r
     if (cfg != null) {\r
       try {\r
-        client = new Pazpar2ClientGeneric(cfg);  \r
+        client = new Pazpar2ClientGeneric(cfg);        \r
       } catch (ProxyErrorException pe) {\r
         logger.error("Could not configure Pazpar2 client: " + pe.getMessage());\r
         throw new ConfigurationException("Could not configure Pz2Client:  "+ pe.getMessage(),pe);\r
@@ -99,6 +99,9 @@ public class Pz2Client implements SearchClient {
       pz2HttpResponse = client.executeCommand(clientCommand, baos);\r
       if (pz2HttpResponse.getStatusCode()==200 && pz2HttpResponse.getContentType().contains("xml")) {\r
         commandResponse = new ClientCommandResponse(pz2HttpResponse,baos);\r
+      } else if (pz2HttpResponse.getStatusCode()==200 && pz2HttpResponse.getContentType().contains("octet-stream")) {\r
+        commandResponse = new ClientCommandResponse(pz2HttpResponse,baos);\r
+        logger.info("Content type: " + commandResponse.getContentType() + ". isBinary?: " + commandResponse.isBinary());\r
       } else if (pz2HttpResponse.getStatusCode()==417) {\r
         logger.error("Pazpar2 status code 417: " + baos.toString("UTF-8"));\r
         commandResponse = new ClientCommandResponse(pz2HttpResponse.getStatusCode(),CommandError.insertErrorXml(command.getCommandName(), String.valueOf(pz2HttpResponse.getStatusCode()) ,"Pazpar2: Expectation failed (417)", baos.toString("UTF-8")),"text/xml");                       \r
@@ -126,7 +129,7 @@ public class Pz2Client implements SearchClient {
       logger.error(e.getMessage());\r
       e.printStackTrace();\r
       logger.error("Creating error XML");\r
-      commandResponse = new ClientCommandResponse(0,CommandError.createErrorXml(command.getCommandName(), "", "Pazpar2Error", e.getMessage(),""),"text/xml");\r
+      commandResponse = new ClientCommandResponse(0,CommandError.createErrorXml(command.getCommandName(), "", "ServiceError", e.getMessage(),""),"text/xml");\r
     }\r
     long end = System.currentTimeMillis();      \r
     logger.debug("Executed " + command.getCommandName() + " in " + (end-start) + " ms." );\r
@@ -198,8 +201,20 @@ public class Pz2Client implements SearchClient {
   \r
   @Override \r
   public void setServiceUrl (String serviceUrl) {    \r
-    cfg.PAZPAR2_URL = serviceUrl;\r
-    \r
+    cfg.PAZPAR2_URL = serviceUrl;    \r
+  }\r
+  \r
+  public String getServiceId () {\r
+    return cfg.PAZPAR2_SERVICE_ID;\r
+  }\r
+  \r
+  public void setServiceId(String serviceId) {\r
+    cfg.PAZPAR2_SERVICE_ID = serviceId;\r
+    try {\r
+      client = new Pazpar2ClientGeneric(cfg);  \r
+    } catch (ProxyErrorException pe) {\r
+      logger.error("Could not configure Pazpar2 client: " + pe.getMessage());      \r
+    }\r
   }\r
 \r
 }\r