From: Niels Erik G. Nielsen Date: Wed, 12 Jun 2013 00:58:09 +0000 (-0400) Subject: Adds windowid parameter to SP init command X-Git-Tag: v0.0.7~42^2~1 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=fc1ac55e0dd989bc3a5a023c5931e8f4e2774668;p=mkjsf-moved-to-github.git Adds windowid parameter to SP init command --- diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java index ace35b1..26e5c9a 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java @@ -38,6 +38,7 @@ import com.indexdata.mkjsf.errors.MissingConfigurationContextException; import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand; +import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand; import com.indexdata.mkjsf.pazpar2.data.CommandError; import com.indexdata.mkjsf.utils.Utils; @@ -241,8 +242,10 @@ public class ServiceProxyClient implements SearchClient { return initDocPaths; } - public HttpResponseWrapper postInitDoc(byte[] initDoc, boolean includeDebug) { - HttpPost post = new HttpPost(serviceUrl+"?command=init" + (includeDebug? "&includeDebug=yes" : "")); + public HttpResponseWrapper postInitDoc(byte[] initDoc, Pazpar2Command command) { + String requestParameters = command.getEncodedQueryString(); + logger.info("Initiating session with init doc and [" + requestParameters +"]"); + HttpPost post = new HttpPost(serviceUrl+"?" + requestParameters); post.setEntity(new ByteArrayEntity(initDoc)); ClientCommandResponse commandResponse = null; byte[] response; diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java index ab2e5a1..27958c4 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/InitCommand.java @@ -74,13 +74,14 @@ public class InitCommand extends Pazpar2Command implements ServiceProxyCommand { for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } - newCommand.spCommand = this.spCommand; + newCommand.spCommand = new InitCommandSp(this); + newCommand.spCommand.setUploadedInitDoc(spCommand.getUploadedInitDoc()); return newCommand; } public ServiceProxyCommand getSp() { if (spCommand==null) { - spCommand = new InitCommandSp(this); + spCommand = new InitCommandSp(this); } return spCommand; } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitCommandSp.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitCommandSp.java index 1c7748a..1b0ed84 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitCommandSp.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitCommandSp.java @@ -11,6 +11,7 @@ import com.indexdata.mkjsf.pazpar2.HttpResponseWrapper; import com.indexdata.mkjsf.pazpar2.Pz2Service; import com.indexdata.mkjsf.pazpar2.commands.CommandParameter; import com.indexdata.mkjsf.pazpar2.commands.InitCommand; +import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; import com.indexdata.mkjsf.pazpar2.data.ResponseDataObject; import com.indexdata.mkjsf.pazpar2.data.ResponseParser; import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; @@ -31,7 +32,7 @@ public class InitCommandSp implements Serializable, ServiceProxyCommand { private static Logger logger = Logger.getLogger(InitCommandSp.class); private InitCommand command = null; - private InitDocUpload initDocUpload; + private InitDocUpload initDocUpload = null; public InitCommandSp(InitCommand initCommand) { this.command=initCommand; @@ -66,23 +67,39 @@ public class InitCommandSp implements Serializable, ServiceProxyCommand { public SpResponseDataObject run() { Pz2Service.get().resetSearchAndRecordCommands(); Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true); - try { - byte[] bytes = getUploadedInitDoc().getBytes(); - HttpResponseWrapper response = Pz2Service.get().getSpClient().postInitDoc(bytes,getIncludeDebug().equals("yes")); - ResponseDataObject responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)response); - Pz2Service.get().getPzresp().put("init", responseObject); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (initDocUpload.hasUploadedFile()) { + try { + byte[] bytes = getUploadedInitDoc().getBytes(); + HttpResponseWrapper response = Pz2Service.get().getSpClient().postInitDoc(bytes,command); + ResponseDataObject responseObject = ResponseParser.getParser().getDataObject((ClientCommandResponse)response); + Pz2Service.get().getPzresp().put("init", responseObject); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { + Pz2Service.get().getSpClient().executeCommand(this.command); } return null; } + + /** + * Sets the windowid parameter. See Service Proxy documentation for details. + */ + public void setWindowid (String windowid) { + command.setParameterInState(new CommandParameter("windowid","=",windowid)); + } + + /** + * Returns the windowid parameter value. + */ + public String getWindowid () { + return command.getParameterValue("windowid"); + } @Override public boolean spOnly() { return true; - } - - + } } diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java index 1d3d228..0b164a2 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/InitDocUpload.java @@ -43,5 +43,9 @@ public class InitDocUpload extends FileUpload { e.printStackTrace(); } } + + public boolean hasUploadedFile () { + return uploadedFile != null; + } }