From: Niels Erik G. Nielsen Date: Fri, 5 Apr 2013 16:25:34 +0000 (-0400) Subject: Adds support for supplying SP init doc as byte array X-Git-Tag: v0.0.7~187 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=f0a5fe08c40f0271e6dbce2367b330dbf7afbc9a;p=mkjsf-moved-to-github.git Adds support for supplying SP init doc as byte array --- 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) {