More work on commands, statemgmt, EL references
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / pz2utils4jsf / pazpar2 / sp / ServiceProxyClient.java
index 16eea35..c4b77d8 100644 (file)
@@ -2,18 +2,15 @@ package com.indexdata.pz2utils4jsf.pazpar2.sp;
 \r
 import static com.indexdata.pz2utils4jsf.utils.Utils.nl;\r
 \r
-import java.io.BufferedWriter;\r
+import java.io.BufferedReader;\r
 import java.io.ByteArrayOutputStream;\r
 import java.io.File;\r
-import java.io.FileWriter;\r
+import java.io.FileReader;\r
 import java.io.IOException;\r
-import java.nio.file.Path;\r
-import java.nio.file.Paths;\r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
-import java.util.Scanner;\r
 \r
 import javax.enterprise.context.SessionScoped;\r
 import javax.inject.Named;\r
@@ -42,10 +39,10 @@ import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;
 import com.indexdata.pz2utils4jsf.config.Configuration;\r
 import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
 import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
-import com.indexdata.pz2utils4jsf.pazpar2.CommandParameter;\r
 import com.indexdata.pz2utils4jsf.pazpar2.CommandResponse;\r
-import com.indexdata.pz2utils4jsf.pazpar2.Pazpar2Command;\r
 import com.indexdata.pz2utils4jsf.pazpar2.SearchClient;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter;\r
+import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Command;\r
 import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.AuthenticationEntity;\r
 import com.indexdata.pz2utils4jsf.pazpar2.sp.auth.ServiceProxyUser;\r
 import com.indexdata.pz2utils4jsf.utils.Utils;\r
@@ -99,7 +96,7 @@ public class ServiceProxyClient implements SearchClient {
     try {      \r
       logger.info("Authenticating [" + user.getProperty("name") + "]");\r
       this.user = (ServiceProxyUser) user;\r
-      Pazpar2Command auth = new Pazpar2Command("auth");\r
+      Pazpar2Command auth = new Pazpar2Command("auth",null);\r
       auth.setParameter(new CommandParameter("action","=","login"));\r
       auth.setParameter(new CommandParameter("username","=",user.getProperty("name")));\r
       auth.setParameter(new CommandParameter("password","=",user.getProperty("password")));\r
@@ -124,7 +121,7 @@ public class ServiceProxyClient implements SearchClient {
   \r
   public boolean checkAuthentication () {\r
     try {\r
-      Pazpar2Command check = new Pazpar2Command("auth");\r
+      Pazpar2Command check = new Pazpar2Command("auth",null);\r
       check.setParameter(new CommandParameter("action","=","check"));\r
       byte[] response = send(check);\r
       logger.info(new String(response,"UTF-8"));\r
@@ -240,23 +237,23 @@ public class ServiceProxyClient implements SearchClient {
     HttpPost post = new HttpPost(serviceUrl+"?command=init&includeDebug=yes");\r
     File initDoc = new File(filePath);\r
     logger.info("Posting to SP: ");\r
-    Path path = Paths.get(filePath);\r
     if (logger.isDebugEnabled()) {\r
-      try (Scanner scanner =  new Scanner(path, "UTF-8")){\r
-        while (scanner.hasNextLine()){\r
-          System.out.println(scanner.nextLine());\r
-        }      \r
-      }     \r
+      BufferedReader reader = new BufferedReader(new FileReader(initDoc));\r
+      String line;\r
+      while ( (line = reader.readLine()) != null) {\r
+        System.out.println(line);\r
+      }\r
+      reader.close();\r
     }\r
     post.setEntity(new FileEntity(initDoc));\r
     byte[] response = client.execute(post, handler);\r
-    logger.info("Response on POST was: " + new String(response,"UTF-8"));    \r
+    logger.debug("Response on POST was: " + new String(response,"UTF-8"));    \r
     return response;\r
   }\r
   \r
   public String[] getInitDocPaths () {\r
-    logger.info("Get init doc paths ");\r
-    logger.info("length: " + initDocPaths.length);\r
+    logger.debug("Get init doc paths ");\r
+    logger.debug("length: " + initDocPaths.length);\r
     return initDocPaths;\r
   }\r
   \r
@@ -264,7 +261,7 @@ public class ServiceProxyClient implements SearchClient {
     HttpPost post = new HttpPost(serviceUrl+"?command=init&includeDebug=yes");\r
     post.setEntity(new ByteArrayEntity(initDoc));\r
     byte[] response = client.execute(post, handler);\r
-    logger.info("Response on POST was: " + new String(response,"UTF-8"));    \r
+    logger.debug("Response on POST was: " + new String(response,"UTF-8"));    \r
     return response;\r
   }\r
   \r