From f0a5fe08c40f0271e6dbce2367b330dbf7afbc9a Mon Sep 17 00:00:00 2001 From: "Niels Erik G. Nielsen" Date: Fri, 5 Apr 2013 12:25:34 -0400 Subject: [PATCH] Adds support for supplying SP init doc as byte array --- .../indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyClient.java | 9 +++++++++ .../pz2utils4jsf/pazpar2/sp/ServiceProxyInterface.java | 1 + .../pz2utils4jsf/pazpar2/sp/ServiceProxySession.java | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyClient.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyClient.java index 0840a36..16eea35 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyClient.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyClient.java @@ -30,6 +30,7 @@ import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.FileEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.PoolingClientConnectionManager; @@ -259,6 +260,14 @@ public class ServiceProxyClient implements SearchClient { return initDocPaths; } + public byte[] postInitDoc(byte[] initDoc) throws IOException { + HttpPost post = new HttpPost(serviceUrl+"?command=init&includeDebug=yes"); + post.setEntity(new ByteArrayEntity(initDoc)); + byte[] response = client.execute(post, handler); + logger.info("Response on POST was: " + new String(response,"UTF-8")); + return response; + } + public void setServiceProxyUrl (String url) { serviceUrl = url; } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyInterface.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyInterface.java index 0147e3f..ef84cea 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyInterface.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxyInterface.java @@ -10,6 +10,7 @@ public interface ServiceProxyInterface extends Pz2Interface { public void setInitFileName (String fileName); public String getInitFileName(); public String postInit() throws UnsupportedEncodingException, IOException; + public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException; public String getInitResponse(); public void setServiceProxyUrl(String url); public String getServiceProxyUrl(); diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java index 2a58af0..c7571ac 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/sp/ServiceProxySession.java @@ -56,6 +56,15 @@ public class ServiceProxySession extends Pz2Session implements ServiceProxyInter initDocResponse = new String(response,"UTF-8"); return initDocResponse; } + + @Override + public String postInit(byte[] initDoc) throws UnsupportedEncodingException, IOException { + this.resetDataObjects(); + byte[] response = client().postInitDoc(initDoc); + initDocResponse = new String(response,"UTF-8"); + return initDocResponse; + } + @Override public void setServiceProxyUrl(String url) { -- 1.7.10.4