Generalizes file upload function and moves it into core
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / sp / ServiceProxyClient.java
index 12cc734..e52e797 100644 (file)
@@ -73,11 +73,11 @@ public class ServiceProxyClient implements SearchClient {
     logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));\r
     try {\r
       config = configReader.getConfiguration(this);      \r
-      serviceUrls = getMultiProperty(config.get(SERVICE_PROXY_URL));\r
+      serviceUrls = getMultiProperty(config.get(SERVICE_PROXY_URL),",");\r
       if (serviceUrls.size()==1) {\r
         selectedServiceUrl = serviceUrls.get(0);\r
       }\r
-      this.initDocPaths = getMultiProperty(config.get(SP_INIT_DOC_PATHS));\r
+      this.initDocPaths = getMultiProperty(config.get(SP_INIT_DOC_PATHS),",");\r
       checkAuth = new AuthCommand(null);\r
       checkAuth.setParameterInState(new CommandParameter("action","=","check"));\r
       ipAuth = new AuthCommand(null);\r
@@ -88,10 +88,10 @@ public class ServiceProxyClient implements SearchClient {
     }    \r
   }\r
   \r
-  private List<String> getMultiProperty(String prop) {\r
+  private List<String> getMultiProperty(String prop, String separator) {\r
     List<String> props = new ArrayList<String>();\r
     if (prop != null) {      \r
-      StringTokenizer tokenizer = new StringTokenizer(prop,",");\r
+      StringTokenizer tokenizer = new StringTokenizer(prop,separator);\r
       while (tokenizer.hasMoreElements()) {\r
         props.add(tokenizer.nextToken());\r
       }     \r
@@ -252,7 +252,7 @@ public class ServiceProxyClient implements SearchClient {
     return null;\r
   }\r
   \r
-  public byte[] postInitDoc (String filePath) throws IOException {\r
+  public ServiceProxyCommandResponse postInitDoc (String filePath) throws IOException {\r
     logger.info("Looking to post the file in : [" + filePath +"]");\r
     HttpPost post = new HttpPost(selectedServiceUrl+"?command=init&includeDebug=yes");\r
     File initDoc = new File(filePath);\r
@@ -268,7 +268,7 @@ public class ServiceProxyClient implements SearchClient {
     post.setEntity(new FileEntity(initDoc));\r
     byte[] response = client.execute(post, handler);\r
     logger.debug("Response on POST was: " + new String(response,"UTF-8"));    \r
-    return response;\r
+    return new ServiceProxyCommandResponse(handler.getStatusCode(),response,handler.getContentType());    \r
   }\r
   \r
   public List<String> getInitDocPaths () {\r
@@ -277,12 +277,12 @@ public class ServiceProxyClient implements SearchClient {
     return initDocPaths;\r
   }\r
   \r
-  public byte[] postInitDoc(byte[] initDoc, boolean includeDebug) throws IOException {\r
+  public ServiceProxyCommandResponse postInitDoc(byte[] initDoc, boolean includeDebug) throws IOException {\r
     HttpPost post = new HttpPost(selectedServiceUrl+"?command=init" + (includeDebug? "&includeDebug=yes" : ""));\r
     post.setEntity(new ByteArrayEntity(initDoc));\r
     byte[] response = client.execute(post, handler);\r
     logger.debug("Response on POST was: " + new String(response,"UTF-8"));    \r
-    return response;\r
+    return new ServiceProxyCommandResponse(handler.getStatusCode(),response,handler.getContentType());    \r
   }\r
   \r
   public void setServiceProxyUrl (String url) {\r