Adds support for supplying SP init doc as byte array
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Fri, 5 Apr 2013 16:25:34 +0000 (12:25 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Fri, 5 Apr 2013 16:25:34 +0000 (12:25 -0400)
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyClient.java
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyInterface.java
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java

index 0840a36..16eea35 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.scheme.PlainSocketFactory;\r
 import org.apache.http.conn.scheme.Scheme;\r
 import org.apache.http.conn.scheme.SchemeRegistry;\r
+import org.apache.http.entity.ByteArrayEntity;\r
 import org.apache.http.entity.FileEntity;\r
 import org.apache.http.impl.client.DefaultHttpClient;\r
 import org.apache.http.impl.conn.PoolingClientConnectionManager;\r
@@ -259,6 +260,14 @@ public class ServiceProxyClient implements SearchClient {
     return initDocPaths;\r
   }\r
   \r
+  public byte[] postInitDoc(byte[] initDoc) throws IOException {\r
+    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
+    return response;\r
+  }\r
+  \r
   public void setServiceProxyUrl (String url) {\r
     serviceUrl = url;\r
   }\r
index 0147e3f..ef84cea 100644 (file)
@@ -10,6 +10,7 @@ public interface ServiceProxyInterface extends Pz2Interface {
   public void setInitFileName (String fileName);  \r
   public String getInitFileName();\r
   public String postInit() throws UnsupportedEncodingException, IOException;\r
+  public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException;\r
   public String getInitResponse();\r
   public void setServiceProxyUrl(String url);\r
   public String getServiceProxyUrl();\r
index 2a58af0..c7571ac 100644 (file)
@@ -56,6 +56,15 @@ public class ServiceProxySession extends Pz2Session implements ServiceProxyInter
     initDocResponse = new String(response,"UTF-8");\r
     return initDocResponse;\r
   }\r
+  \r
+  @Override\r
+  public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException {    \r
+    this.resetDataObjects();\r
+    byte[] response = client().postInitDoc(initDoc);\r
+    initDocResponse = new String(response,"UTF-8");\r
+    return initDocResponse;\r
+  }\r
+\r
 \r
   @Override\r
   public void setServiceProxyUrl(String url) {\r