}\r
\r
@PostConstruct\r
- public void initiatePz2Session() {\r
+ public void instantiatePz2SessionObject() {\r
logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session next.");\r
pz2 = new Pz2Session();\r
searchClient = new Pz2Client();\r
logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
+ Utils.objectId(configurator) + "] on session [" \r
+ Utils.objectId(pz2) + "]" ); \r
- pz2.init(searchClient,configurator);\r
+ pz2.configureClient(searchClient,configurator);\r
}\r
\r
\r
* @return pazpar2 'show' response object\r
*/\r
public ShowResponse getShow();\r
- \r
+ \r
/**\r
* Returns the 'stat' data as retrieved from pazpar2 by the most \r
* recent update request\r
package com.indexdata.pz2utils4jsf.pazpar2;\r
\r
+import java.io.IOException;\r
+import java.io.UnsupportedEncodingException;\r
+\r
import javax.annotation.PostConstruct;\r
import javax.enterprise.context.SessionScoped;\r
import javax.enterprise.inject.Alternative;\r
public class Pz2ProxyBean extends Pz2Bean implements ServiceProxyInterface {\r
\r
private static final long serialVersionUID = 4221824985678758225L;\r
- private static Logger logger = Logger.getLogger(Pz2ProxyBean.class);\r
+ private static Logger logger = Logger.getLogger(Pz2ProxyBean.class); \r
\r
@Inject ConfigurationReader configurator;\r
@Inject ServiceProxyUser user;\r
}\r
\r
@PostConstruct\r
- public void initiatePz2Session() {\r
- logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session next.");\r
+ public void instantiatePz2SessionObject() {\r
+ logger.debug(Utils.objectId(this) + " will instantiate a Pz2Session object next.");\r
pz2 = new ServiceProxySession();\r
searchClient = new ServiceProxyClient();\r
logger.info("Using [" + Utils.objectId(searchClient) + "] configured by [" \r
+ Utils.objectId(configurator) + "] on session [" \r
+ Utils.objectId(pz2) + "]" ); \r
- pz2.init(searchClient,configurator);\r
+ pz2.configureClient(searchClient,configurator);\r
}\r
\r
-\r
+ @Override\r
public String login(String navigateTo) {\r
logger.info("doing login");\r
((ServiceProxySession) pz2).setUser(user);\r
- return ((ServiceProxySession)pz2).login(navigateTo);\r
+ return session().login(navigateTo);\r
+ }\r
+\r
+ @Override\r
+ public void setInitFileName(String fileName) {\r
+ session().setInitFileName(fileName); \r
+ }\r
+\r
+ @Override\r
+ public String getInitFileName() {\r
+ return session().getInitFileName();\r
+ }\r
+\r
+ @Override\r
+ public String postInit() throws UnsupportedEncodingException, IOException {\r
+ return session().postInit();\r
+ }\r
+\r
+ @Override\r
+ public void setServiceProxyUrl(String url) {\r
+ session().setServiceProxyUrl(url); \r
+ }\r
+\r
+ @Override\r
+ public String getServiceProxyUrl() {\r
+ return session().getServiceProxyUrl(); \r
+ }\r
+ \r
+ public ServiceProxySession session() {\r
+ return (ServiceProxySession)pz2;\r
+ }\r
+\r
+ @Override\r
+ public String getInitResponse() {\r
+ return session().getInitResponse();\r
}\r
\r
}\r
logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]"); \r
}\r
\r
- public void init(SearchClient searchClient, ConfigurationReader configReader) {\r
+ public void configureClient(SearchClient searchClient, ConfigurationReader configReader) {\r
configurationErrors = new ArrayList<ErrorInterface>();\r
errorHelper = new ErrorHelper(configReader); \r
logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
HashMap<String,List<Pazpar2ResponseData>> elements = new HashMap<String,List<Pazpar2ResponseData>>();\r
String textContent = "";\r
CommandError error = null;\r
+ String xml = null;\r
\r
public void setType (String type) {\r
this.type = type;\r
public boolean hasPazpar2Error() {\r
return hasApplicationError() && getApplicationError().hasPazpar2Error();\r
}\r
+ \r
+ public void setXml(String xml) {\r
+ this.xml = xml; \r
+ }\r
+ \r
+ public String getXml() {\r
+ return xml;\r
+ }\r
\r
}\r
private Pazpar2ResponseData currentElement = null;\r
private Stack<Pazpar2ResponseData> dataElements = new Stack<Pazpar2ResponseData>();\r
private Pazpar2ResponseData result = null;\r
+ private String xml = null;\r
\r
private static final List<String> docTypes = \r
Arrays.asList("bytarget","termlist","show","stat","record","search");\r
* @return Response data object\r
*/\r
public Pazpar2ResponseData getDataObject (String response) {\r
+ this.xml = response;\r
try { \r
xmlReader.parse(new InputSource(new ByteArrayInputStream(response.getBytes("UTF-8"))));\r
} catch (UnsupportedEncodingException e) {\r
@Override\r
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {\r
if (localName.equals("show")) {\r
- currentElement = new ShowResponse();\r
+ currentElement = new ShowResponse(); \r
} else if (localName.equals("hit")) {\r
currentElement = new Hit();\r
} else if (localName.equals("location")) {\r
currentElement = new Location();\r
} else if (localName.equals("bytarget")) {\r
- currentElement = new ByTarget();\r
+ currentElement = new ByTarget(); \r
} else if (localName.equals("target")) {\r
currentElement = new Target();\r
} else if (localName.equals("stat")) {\r
- currentElement = new StatResponse();\r
+ currentElement = new StatResponse(); \r
} else if (localName.equals("termlist")) {\r
- currentElement = new TermListsResponse();\r
+ currentElement = new TermListsResponse(); \r
} else if (localName.equals("list")) {\r
currentElement = new TermListResponse();\r
((TermListResponse)currentElement).setName(atts.getValue("name"));\r
}\r
((TermListResponse)dataElements.peek()).addTerm((TermResponse)currentElement);\r
} else if (localName.equals("record")) {\r
- currentElement = new RecordResponse();\r
+ currentElement = new RecordResponse(); \r
} else if (localName.equals("search")) {\r
currentElement = new SearchResponse();\r
} else if (localName.equals("applicationerror")) {\r
if (!docTypes.contains(localName)) {\r
dataElements.peek().addElement(localName, currentElement);\r
}\r
+ if (this.xml != null) { // Store XML for doc level elements\r
+ currentElement.setXml(xml);\r
+ xml = null;\r
+ }\r
dataElements.push(currentElement); \r
}\r
\r
import static com.indexdata.pz2utils4jsf.utils.Utils.nl;\r
\r
import java.io.ByteArrayOutputStream;\r
+import java.io.File;\r
import java.io.IOException;\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import org.apache.http.client.HttpClient;\r
import org.apache.http.client.ResponseHandler;\r
import org.apache.http.client.methods.HttpGet;\r
+import org.apache.http.client.methods.HttpPost;\r
import org.apache.http.conn.ClientConnectionManager;\r
import org.apache.http.conn.scheme.PlainSocketFactory;\r
import org.apache.http.conn.scheme.Scheme;\r
import org.apache.http.conn.scheme.SchemeRegistry;\r
+import org.apache.http.entity.FileEntity;\r
import org.apache.http.impl.client.DefaultHttpClient;\r
import org.apache.http.impl.conn.PoolingClientConnectionManager;\r
import org.apache.http.util.EntityUtils;\r
private static final long serialVersionUID = -4031644009579840277L;\r
private static Logger logger = Logger.getLogger(ServiceProxyClient.class);\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
\r
ProxyPz2ResponseHandler handler = new ProxyPz2ResponseHandler();\r
private HttpClient client;\r
logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));\r
try {\r
Configuration config = configReader.getConfiguration(this); \r
- serviceUrl = config.getMandatory("SERVICE_PROXY_URL"); \r
+ serviceUrl = config.getMandatory(SERVICE_PROXY_URL); \r
+ this.initDocPaths = getMultiProperty(config.get(SP_INIT_DOC_PATHS)); \r
} catch (ConfigurationException c) {\r
c.printStackTrace();\r
} catch (MissingMandatoryParameterException mmp) {\r
} \r
}\r
\r
+ private String[] getMultiProperty(String prop) { \r
+ if (prop != null) {\r
+ return prop.split(",");\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+ \r
public boolean authenticate (AuthenticationEntity user) {\r
try { \r
logger.info("Authenticating [" + user.getProperty("name") + "]");\r
ServiceProxyClient clone = new ServiceProxyClient();\r
clone.client = this.client;\r
clone.serviceUrl = this.serviceUrl;\r
+ clone.initDocPaths = this.initDocPaths;\r
return clone;\r
}\r
\r
doc.add(nl+ MODULENAME + " was configured to access the Pazpar2 service proxy at: " + serviceUrl);\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
+ File initDoc = new File(filePath);\r
+ post.setEntity(new FileEntity(initDoc));\r
+ byte[] response = client.execute(post, handler);\r
+ logger.info("Response on POST was: " + new String(response,"UTF-8"));\r
+ return response;\r
+ }\r
+ \r
+ public String[] getInitDocPaths () {\r
+ logger.info("Get init doc paths ");\r
+ logger.info("length: " + initDocPaths.length);\r
+ return initDocPaths;\r
+ }\r
+ \r
+ public void setServiceProxyUrl (String url) {\r
+ serviceUrl = url;\r
+ }\r
+ \r
+ public String getServiceProxyUrl () {\r
+ return serviceUrl;\r
+ }\r
\r
}\r
package com.indexdata.pz2utils4jsf.pazpar2.sp;\r
\r
-import com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface;\r
+import java.io.IOException;\r
+import java.io.UnsupportedEncodingException;\r
\r
-public interface ServiceProxyInterface extends Pz2Interface {\r
+import com.indexdata.pz2utils4jsf.pazpar2.Pz2Interface;\r
\r
- public String login(String navigateTo);\r
+public interface ServiceProxyInterface extends Pz2Interface { \r
+ public String login(String navigateTo); \r
+ public void setInitFileName (String fileName); \r
+ public String getInitFileName();\r
+ public String postInit() throws UnsupportedEncodingException, IOException;\r
+ public String getInitResponse();\r
+ public void setServiceProxyUrl(String url);\r
+ public String getServiceProxyUrl();\r
}\r
package com.indexdata.pz2utils4jsf.pazpar2.sp;\r
\r
+import java.io.IOException;\r
+import java.io.UnsupportedEncodingException;\r
+\r
import org.apache.log4j.Logger;\r
\r
import com.indexdata.pz2utils4jsf.pazpar2.Pz2Session;\r
private ServiceProxyUser user; \r
private static final long serialVersionUID = -5770410029361522854L;\r
private static Logger logger = Logger.getLogger(ServiceProxySession.class);\r
+ private String initDocFileName = "";\r
+ private String initDocResponse = "";\r
\r
public ServiceProxySession() {\r
logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]");\r
\r
@Override\r
public String login(String navigateTo) {\r
- if (((ServiceProxyClient)searchClient).authenticate(user)) {\r
+ if (client().authenticate(user)) {\r
return navigateTo;\r
} else {\r
return null;\r
} \r
}\r
+\r
+ @Override\r
+ public void setInitFileName(String fileName) {\r
+ this.initDocFileName = fileName;\r
+ \r
+ }\r
+\r
+ @Override\r
+ public String getInitFileName() {\r
+ return initDocFileName;\r
+ }\r
+\r
+ @Override\r
+ public String postInit() throws UnsupportedEncodingException, IOException {\r
+ String initDocPath = client().getInitDocPaths()[0];\r
+ logger.info("Paths: " + client().getInitDocPaths());\r
+ logger.info("Path: " + initDocPath);\r
+ byte[] response = client().postInitDoc(initDocPath + getInitFileName());\r
+ initDocResponse = new String(response,"UTF-8");\r
+ return initDocResponse;\r
+ }\r
+\r
+ @Override\r
+ public void setServiceProxyUrl(String url) {\r
+ client().setServiceProxyUrl(url);\r
+ \r
+ }\r
+\r
+ @Override\r
+ public String getServiceProxyUrl() {\r
+ return client().getServiceProxyUrl();\r
+ }\r
+ \r
+ private ServiceProxyClient client () {\r
+ return (ServiceProxyClient)searchClient;\r
+ }\r
+\r
+ @Override\r
+ public String getInitResponse() {\r
+ return initDocResponse;\r
+ }\r
+ \r
\r
\r
}\r