Adds check for SP only commands.
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / Pz2Client.java
index 2e6ca31..3b33000 100644 (file)
@@ -9,6 +9,9 @@ import java.util.HashMap;
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import javax.faces.context.ExternalContext;\r
+import javax.faces.context.FacesContext;\r
+\r
 import org.apache.log4j.Logger;\r
 \r
 import com.indexdata.masterkey.config.MissingMandatoryParameterException;\r
@@ -59,7 +62,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 +102,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
@@ -198,8 +204,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