Adds windowid parameter to applicable commands
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / ServiceProxyClient.java
index 2db4558..26e5c9a 100644 (file)
@@ -34,12 +34,20 @@ import org.apache.log4j.Logger;
 import com.indexdata.mkjsf.config.Configuration;\r
 import com.indexdata.mkjsf.config.ConfigurationReader;\r
 import com.indexdata.mkjsf.errors.ConfigurationException;\r
+import com.indexdata.mkjsf.errors.MissingConfigurationContextException;\r
 import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;\r
 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;\r
 import com.indexdata.mkjsf.pazpar2.commands.sp.AuthCommand;\r
+import com.indexdata.mkjsf.pazpar2.commands.sp.ServiceProxyCommand;\r
 import com.indexdata.mkjsf.pazpar2.data.CommandError;\r
 import com.indexdata.mkjsf.utils.Utils;\r
 \r
+/**\r
+ * Search client handling Service Proxy requests. \r
+ *   \r
+ * @author Niels Erik\r
+ *\r
+ */\r
 public class ServiceProxyClient implements SearchClient {\r
     \r
   private static final long serialVersionUID = -4031644009579840277L;\r
@@ -65,20 +73,22 @@ public class ServiceProxyClient implements SearchClient {
   }\r
     \r
   @Override\r
-  public void configure (ConfigurationReader configReader) {\r
+  public void configure (ConfigurationReader configReader) throws MissingConfigurationContextException {\r
     logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));\r
     try {\r
       config = configReader.getConfiguration(this);      \r
       serviceUrl = config.get("SERVICE_PROXY_URL");\r
       this.initDocPaths = config.getMultiProperty(SP_INIT_DOC_PATHS,",");\r
-      checkAuth = new AuthCommand(null);\r
+      checkAuth = new AuthCommand();\r
       checkAuth.setParameterInState(new CommandParameter("action","=","check"));\r
-      ipAuth = new AuthCommand(null);\r
+      ipAuth = new AuthCommand();\r
       ipAuth.setParameterInState(new CommandParameter("action","=","ipauth"));\r
-    } catch (ConfigurationException c) {\r
-      // TODO: \r
-      c.printStackTrace();\r
-    }    \r
+    } catch (MissingConfigurationContextException mcce) {\r
+      throw mcce;\r
+    } catch (ConfigurationException ce) {\r
+      logger.error("Failed to configure Service Proxy client");\r
+      ce.printStackTrace();\r
+    }\r
   }\r
     \r
   public boolean isAuthenticatingClient () {\r
@@ -101,7 +111,7 @@ public class ServiceProxyClient implements SearchClient {
     try {\r
       response = client.execute(httpget, handler);\r
       if (handler.getStatusCode()==200 && (handler.getContentType().contains("xml") || handler.getContentType().contains("octet-stream"))) {\r
-        logger.debug("Creating command response holding content of type " + handler.getContentType());\r
+        logger.trace("Creating command response holding content of type " + handler.getContentType());\r
         commandResponse = new ClientCommandResponse(handler.getStatusCode(),response,handler.getContentType());\r
       } else {\r
         logger.error("Service Proxy status code: " + handler.getStatusCode());\r
@@ -162,6 +172,9 @@ public class ServiceProxyClient implements SearchClient {
     return handler.getReasonPhrase();\r
   }\r
 \r
+  /**\r
+   * Does nothing in Service Proxy context\r
+   */\r
   @Override\r
   public void setSearchCommand(Pazpar2Command command) {\r
     // Do nothing, Service Proxy is handling this    \r
@@ -181,11 +194,17 @@ public class ServiceProxyClient implements SearchClient {
     return clone;\r
   }\r
 \r
+  /**\r
+   * Returns default configuration parameters for the client.\r
+   */\r
   @Override\r
   public Map<String, String> getDefaults() {    \r
     return new HashMap<String,String>();\r
   }\r
 \r
+  /**\r
+   * Returns the configuration name of the client\r
+   */\r
   @Override\r
   public String getModuleName() {\r
     return MODULENAME;\r
@@ -223,8 +242,10 @@ public class ServiceProxyClient implements SearchClient {
     return initDocPaths;\r
   }\r
   \r
-  public HttpResponseWrapper postInitDoc(byte[] initDoc, boolean includeDebug) {\r
-    HttpPost post = new HttpPost(serviceUrl+"?command=init" + (includeDebug? "&includeDebug=yes" : ""));\r
+  public HttpResponseWrapper postInitDoc(byte[] initDoc, Pazpar2Command command) {\r
+    String requestParameters = command.getEncodedQueryString();\r
+    logger.info("Initiating session with init doc and [" + requestParameters +"]");\r
+    HttpPost post = new HttpPost(serviceUrl+"?" + requestParameters);\r
     post.setEntity(new ByteArrayEntity(initDoc));\r
     ClientCommandResponse commandResponse = null;\r
     byte[] response;\r
@@ -248,6 +269,9 @@ public class ServiceProxyClient implements SearchClient {
     return commandResponse;    \r
   }\r
   \r
+  /**\r
+   * Sets the URL of the Service Proxy that should service requests. \r
+   */\r
   public void setServiceUrl (String url) {    \r
     serviceUrl = url;\r
   }\r
@@ -261,6 +285,9 @@ public class ServiceProxyClient implements SearchClient {
     return serviceUrl;\r
   }\r
 \r
+  /**\r
+   * Returns true if a Service Proxy URL was defined yet.\r
+   */\r
   @Override\r
   public boolean hasServiceUrl() {\r
     return serviceUrl != null && serviceUrl.length()>0;\r