From: Niels Erik G. Nielsen For the web.xml configuration scheme (choosing WebXmlConfigReader in beans.xml)
- * to pre-define the URL of the Pazpar2 to use, the configuration could be:
* <context-param> * <param-name>PAZPAR2_URL</param-name> * <param-value>http://localhost:8004/</param-value> * </context-param> + * <context-param> + * <description>Service type. Possible values: SP, PZ2, TBD</description> + * <param-name>TYPE</param-name> + * <param-value>PZ2</param-value> + * </context-param> ** *
For the Mk2ConfigReader scheme to work, the web.xml must then contain pointers to the configuration directory - * and properties file. + * and properties file. The specific configuration itself would be in those files then. * In this example the configuration directory is in the web application itself (war://testconfig). A more regular * example would put it in a separate directory to not have it overwritten by each deployment of the war.
*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/RecordCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java index 8cc039d..8991dde 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/RecordCommand.java @@ -177,7 +177,7 @@ public class RecordCommand extends Pazpar2Command implements ServiceProxyCommand for (String parameterName : parameters.keySet()) { newCommand.setParameterInState(parameters.get(parameterName).copy()); } - newCommand.spCommand = this.spCommand; + newCommand.spCommand = new RecordCommandSp(newCommand); return newCommand; } 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 thewindowid
parameter. See Service Proxy documentation for details. + */ + public void setWindowid (String windowid) { + command.setParameterInState(new CommandParameter("windowid","=",windowid)); + } + + /** + * Returns thewindowid
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; + } }