From: Niels Erik G. Nielsen Date: Wed, 12 Jun 2013 12:50:46 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/mkjsf X-Git-Tag: v0.0.7~42 X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=commitdiff_plain;h=b45b0c8165fa016246ac1ff0cf2f69a89013d356;hp=52bdbd63806a037bd624c4b13061943f2eb371fe;p=mkjsf-moved-to-github.git Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/mkjsf --- diff --git a/Changes b/Changes new file mode 100644 index 0000000..87ad40b --- /dev/null +++ b/Changes @@ -0,0 +1,7 @@ +- Adds parameter 'windowid' (SP extension) to init command +- Fix for state handling in record command (the SP extensions) +- Adds working web.xml context parameters for SP service + +0.3.3 + +- First release \ No newline at end of file diff --git a/src/main/java/com/indexdata/mkjsf/config/package-info.java b/src/main/java/com/indexdata/mkjsf/config/package-info.java index 6716e66..aec5200 100644 --- a/src/main/java/com/indexdata/mkjsf/config/package-info.java +++ b/src/main/java/com/indexdata/mkjsf/config/package-info.java @@ -31,17 +31,23 @@ * * *

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:

+ * to pre-define the URL of the Pazpar2 to use and choose Pazpar2 as the selected + * service type, 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 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;
+  }
 
 }