X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2FServiceProxyClient.java;h=e5d7307c08713f33013468f7fc883aec5deae0d1;hb=5211ca6a4525491499ac763373a703e35bdce37f;hp=67cc8eff839536af38a9ef5f155e1ad7e167b8a4;hpb=11ff48b9d37193a89a4b74da75db8c58415c46a6;p=mkjsf-moved-to-github.git
diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java
index 67cc8ef..e5d7307 100644
--- a/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java
+++ b/src/main/java/com/indexdata/mkjsf/pazpar2/ServiceProxyClient.java
@@ -34,12 +34,33 @@ import org.apache.log4j.Logger;
import com.indexdata.mkjsf.config.Configuration;
import com.indexdata.mkjsf.config.ConfigurationReader;
import com.indexdata.mkjsf.errors.ConfigurationException;
+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.data.CommandError;
import com.indexdata.mkjsf.utils.Utils;
+/**
+ * Search client handling Service Proxy requests.
+ *
+ *
Configuration
+ *
+ * Configuration name: proxyclient
+ *
+ * When configuring the client using the Mk2Config scheme, this is the prefix to
+ * use in the .properties file. When using web.xml context parameters for configuration
+ * the configuration name has no effect.
+ *
+ * ServiceProxyClient will acknowledge following configuration parameters:
+ *
+ *
+ * - (proxyclient.)SERVICE_PROXY_URL
+ *
+ *
+ * @author Niels Erik
+ *
+ */
public class ServiceProxyClient implements SearchClient {
private static final long serialVersionUID = -4031644009579840277L;
@@ -65,7 +86,7 @@ public class ServiceProxyClient implements SearchClient {
}
@Override
- public void configure (ConfigurationReader configReader) {
+ public void configure (ConfigurationReader configReader) throws MissingConfigurationContextException {
logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));
try {
config = configReader.getConfiguration(this);
@@ -75,10 +96,12 @@ public class ServiceProxyClient implements SearchClient {
checkAuth.setParameterInState(new CommandParameter("action","=","check"));
ipAuth = new AuthCommand();
ipAuth.setParameterInState(new CommandParameter("action","=","ipauth"));
- } catch (ConfigurationException c) {
- // TODO:
- c.printStackTrace();
- }
+ } catch (MissingConfigurationContextException mcce) {
+ throw mcce;
+ } catch (ConfigurationException ce) {
+ logger.error("Failed to configure Service Proxy client");
+ ce.printStackTrace();
+ }
}
public boolean isAuthenticatingClient () {
@@ -101,7 +124,7 @@ public class ServiceProxyClient implements SearchClient {
try {
response = client.execute(httpget, handler);
if (handler.getStatusCode()==200 && (handler.getContentType().contains("xml") || handler.getContentType().contains("octet-stream"))) {
- logger.debug("Creating command response holding content of type " + handler.getContentType());
+ logger.trace("Creating command response holding content of type " + handler.getContentType());
commandResponse = new ClientCommandResponse(handler.getStatusCode(),response,handler.getContentType());
} else {
logger.error("Service Proxy status code: " + handler.getStatusCode());
@@ -162,6 +185,9 @@ public class ServiceProxyClient implements SearchClient {
return handler.getReasonPhrase();
}
+ /**
+ * Does nothing in Service Proxy context
+ */
@Override
public void setSearchCommand(Pazpar2Command command) {
// Do nothing, Service Proxy is handling this
@@ -181,11 +207,17 @@ public class ServiceProxyClient implements SearchClient {
return clone;
}
+ /**
+ * Returns default configuration parameters for the client.
+ */
@Override
public Map getDefaults() {
return new HashMap();
}
+ /**
+ * Returns the configuration name of the client
+ */
@Override
public String getModuleName() {
return MODULENAME;
@@ -223,8 +255,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;
@@ -248,6 +282,9 @@ public class ServiceProxyClient implements SearchClient {
return commandResponse;
}
+ /**
+ * Sets the URL of the Service Proxy that should service requests.
+ */
public void setServiceUrl (String url) {
serviceUrl = url;
}
@@ -261,6 +298,9 @@ public class ServiceProxyClient implements SearchClient {
return serviceUrl;
}
+ /**
+ * Returns true if a Service Proxy URL was defined yet.
+ */
@Override
public boolean hasServiceUrl() {
return serviceUrl != null && serviceUrl.length()>0;