\r
import java.io.IOException;\r
import java.io.UnsupportedEncodingException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
\r
import javax.annotation.PostConstruct;\r
import javax.enterprise.context.SessionScoped;\r
public String getServiceProxyUrl() {\r
return ((ServiceProxyClient)searchClient).getServiceProxyUrl();\r
}\r
+ \r
+ public List<String> getServiceProxyUrls() {\r
+ List<String> urls = new ArrayList<String>();\r
+ urls.add("");\r
+ urls.addAll(((ServiceProxyClient)searchClient).getServiceProxyUrls());\r
+ return urls;\r
+ }\r
\r
public String getInitDocPath () {\r
return searchClient.getConfiguration().get("INIT_DOC_PATH");\r
\r
@Override\r
public String postInit() throws UnsupportedEncodingException, IOException { \r
- String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths()[0];\r
+ String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths().get(0);\r
logger.info("Paths: " + ((ServiceProxyClient)searchClient).getInitDocPaths());\r
logger.info("Path: " + initDocPath);\r
pzresp.reset();\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
+import java.util.StringTokenizer;\r
\r
import org.apache.http.HttpEntity;\r
import org.apache.http.HttpResponse;\r
import org.apache.http.util.EntityUtils;\r
import org.apache.log4j.Logger;\r
\r
-import com.indexdata.masterkey.config.MissingMandatoryParameterException;\r
import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
import com.indexdata.mkjsf.config.Configuration;\r
import com.indexdata.mkjsf.config.ConfigurationReader;\r
public static final String MODULENAME = "proxyclient";\r
public static final String SERVICE_PROXY_URL = "SERVICE_PROXY_URL";\r
public static final String SP_INIT_DOC_PATHS = "SP_INIT_DOC_PATHS";\r
- private String serviceUrl = "undefined";\r
- private String[] initDocPaths = null;\r
+ private String selectedServiceUrl = "";\r
+ private List<String> serviceUrls = new ArrayList<String>();\r
+ private List<String> initDocPaths = null;\r
private Configuration config = null;\r
\r
ProxyPz2ResponseHandler handler = new ProxyPz2ResponseHandler();\r
logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));\r
try {\r
config = configReader.getConfiguration(this); \r
- serviceUrl = config.getMandatory(SERVICE_PROXY_URL); \r
+ serviceUrls = getMultiProperty(config.get(SERVICE_PROXY_URL));\r
+ if (serviceUrls.size()==1) {\r
+ selectedServiceUrl = serviceUrls.get(0);\r
+ }\r
this.initDocPaths = getMultiProperty(config.get(SP_INIT_DOC_PATHS));\r
checkAuth = new AuthCommand(null);\r
checkAuth.setParameterInState(new CommandParameter("action","=","check"));\r
ipAuth.setParameterInState(new CommandParameter("action","=","ipauth"));\r
} catch (ConfigurationException c) {\r
c.printStackTrace();\r
- } catch (MissingMandatoryParameterException mmp) {\r
- mmp.printStackTrace();\r
} \r
}\r
\r
- private String[] getMultiProperty(String prop) { \r
- if (prop != null) {\r
- return prop.split(",");\r
- } else {\r
- return null;\r
+ private List<String> getMultiProperty(String prop) {\r
+ List<String> props = new ArrayList<String>();\r
+ if (prop != null) { \r
+ StringTokenizer tokenizer = new StringTokenizer(prop,",");\r
+ while (tokenizer.hasMoreElements()) {\r
+ props.add(tokenizer.nextToken());\r
+ } \r
}\r
+ return props;\r
}\r
\r
public boolean authenticate (ServiceProxyUser user) {\r
* @throws IOException\r
*/\r
private byte[] send(Pazpar2Command command) throws ClientProtocolException, IOException {\r
- String url = serviceUrl + "?" + command.getEncodedQueryString(); \r
+ String url = selectedServiceUrl + "?" + command.getEncodedQueryString(); \r
logger.info("Sending request "+url); \r
HttpGet httpget = new HttpGet(url); \r
byte[] response = client.execute(httpget, handler); \r
logger.debug("Cloning Pz2Client");\r
ServiceProxyClient clone = new ServiceProxyClient();\r
clone.client = this.client;\r
- clone.serviceUrl = this.serviceUrl;\r
+ clone.serviceUrls = this.serviceUrls;\r
+ clone.selectedServiceUrl = this.selectedServiceUrl;\r
clone.initDocPaths = this.initDocPaths;\r
return clone;\r
}\r
@Override\r
public List<String> documentConfiguration () {\r
List<String> doc = new ArrayList<String>();\r
- doc.add(nl+ MODULENAME + " was configured to access the Pazpar2 service proxy at: " + serviceUrl);\r
+ doc.add(nl+ MODULENAME + " was configured to access the Pazpar2 service proxy at: " + (selectedServiceUrl.length()>0 ? selectedServiceUrl : "[not defined yet]"));\r
return null;\r
}\r
\r
public byte[] postInitDoc (String filePath) throws IOException {\r
logger.info("Looking to post the file in : [" + filePath +"]");\r
- HttpPost post = new HttpPost(serviceUrl+"?command=init&includeDebug=yes");\r
+ HttpPost post = new HttpPost(selectedServiceUrl+"?command=init&includeDebug=yes");\r
File initDoc = new File(filePath);\r
logger.info("Posting to SP: ");\r
if (logger.isDebugEnabled()) {\r
return response;\r
}\r
\r
- public String[] getInitDocPaths () {\r
+ public List<String> getInitDocPaths () {\r
logger.debug("Get init doc paths ");\r
- logger.debug("length: " + initDocPaths.length);\r
+ logger.debug("length: " + initDocPaths.size());\r
return initDocPaths;\r
}\r
\r
public byte[] postInitDoc(byte[] initDoc) throws IOException {\r
- HttpPost post = new HttpPost(serviceUrl+"?command=init&includeDebug=yes");\r
+ HttpPost post = new HttpPost(selectedServiceUrl+"?command=init&includeDebug=yes");\r
post.setEntity(new ByteArrayEntity(initDoc));\r
byte[] response = client.execute(post, handler);\r
logger.debug("Response on POST was: " + new String(response,"UTF-8")); \r
}\r
\r
public void setServiceProxyUrl (String url) {\r
- serviceUrl = url;\r
+ selectedServiceUrl = url;\r
}\r
\r
public String getServiceProxyUrl () {\r
- return serviceUrl;\r
+ return selectedServiceUrl;\r
}\r
\r
+ public List<String> getServiceProxyUrls () {\r
+ return serviceUrls;\r
+ }\r
+ \r
public Configuration getConfiguration () {\r
return config;\r
}\r