X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fdata%2FResponses.java;h=1397023009a5369d4ac4b33a57af09bc1ba66085;hb=ea49f38ba51c8325879b693536940974b73a01c2;hp=5276eef6b44ee6ff7c76c050b67798265fa60944;hpb=d400a082759c1a58cb79713f04ab2f3d62bca97c;p=mkjsf-moved-to-github.git diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java index 5276eef..1397023 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/data/Responses.java @@ -16,16 +16,18 @@ import org.apache.log4j.Logger; import com.indexdata.mkjsf.errors.ErrorHelper; import com.indexdata.mkjsf.errors.ErrorInterface; -import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse; +import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject; +import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses; import com.indexdata.mkjsf.utils.Utils; -@Named("pzresp") @SessionScoped +@SessionScoped @Named public class Responses implements Serializable { private static final long serialVersionUID = -7543231258346154642L; protected Map dataObjects = new ConcurrentHashMap(); private static Logger logger = Logger.getLogger(Responses.class); private ErrorHelper errorHelper = null; + private SpResponses sp = null; public Responses() { } @@ -43,10 +45,15 @@ public class Responses implements Serializable { logger.info("Error detected in search"); return true; } - for (String name : dataObjects.keySet()) { + for (String name : dataObjects.keySet()) { if (dataObjects.get(name).hasApplicationError()) { - logger.info("Error detected in " + name); - return true; + if (dataObjects.get(name) instanceof SpResponseDataObject && + ((SpResponseDataObject)dataObjects.get(name)).unsupportedCommand()) { + logger.debug("Command [" + name + "] not supported by this service"); + } else { + logger.info("Error detected in " + name); + return true; + } } } return false; @@ -74,25 +81,23 @@ public class Responses implements Serializable { return error; } - public void resetSearchResponses() { + public void resetSearchAndBeyond() { logger.debug("Resetting show,stat,termlist,bytarget,record,search response objects."); dataObjects.put("show", new ShowResponse()); dataObjects.put("stat", new StatResponse()); dataObjects.put("termlist", new TermListsResponse()); dataObjects.put("bytarget", new ByTarget()); dataObjects.put("record", new RecordResponse()); - dataObjects.put("search", new SearchResponse()); + dataObjects.put("search", new SearchResponse()); + getSp().resetSearchAndBeyond(false); } - public void resetAllSessionData () { - logger.debug("Resetting all response objects"); - dataObjects = new ConcurrentHashMap(); - resetSearchResponses(); - dataObjects.put("init", new InitResponse()); - dataObjects.put("auth", new AuthResponse()); - dataObjects.put("categories", new CategoriesResponse()); + public void resetInitAndBeyond () { + dataObjects.put("init", new InitResponse()); + resetSearchAndBeyond(); + getSp().resetInitAndBeyond(false); } - + public InitResponse getInit () { return ((InitResponse) dataObjects.get("init")); } @@ -129,17 +134,6 @@ public class Responses implements Serializable { return ((ByTarget) dataObjects.get("bytarget")); } - // Service Proxy extras - public AuthResponse getAuth () { - return ((AuthResponse) dataObjects.get("auth")); - } - - public CategoriesResponse getCategories() { - return ((CategoriesResponse) dataObjects.get("categories")); - } - // Service Proxy extras - - public ResponseDataObject getResponseObject (String name) { return dataObjects.get(name); } @@ -164,12 +158,25 @@ public class Responses implements Serializable { public void download(String commandName) throws UnsupportedEncodingException, IOException { logger.info(Utils.objectId(this) + " got a download request for " + commandName); + ResponseDataObject object = dataObjects.get(commandName); FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); - externalContext.setResponseHeader("Content-Type","application/xml; charset=\"utf-8\""); - externalContext.setResponseHeader("Content-Length",String.valueOf(dataObjects.get(commandName).getXml().getBytes("UTF-8").length)); - externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + commandName + ".xml\""); - externalContext.getResponseOutputStream().write(dataObjects.get(commandName).getXml().getBytes("UTF-8")); + if (object.getIsBinary()) { + externalContext.setResponseHeader("Content-Type","application/octet-stream"); + externalContext.setResponseHeader("Content-Length",String.valueOf(object.getBinary().length)); + externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + commandName + ".data\""); + externalContext.getResponseOutputStream().write(object.getBinary()); + } else { + externalContext.setResponseHeader("Content-Type","application/xml; charset=\"utf-8\""); + externalContext.setResponseHeader("Content-Length",String.valueOf(dataObjects.get(commandName).getXml().getBytes("UTF-8").length)); + externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + commandName + ".xml\""); + externalContext.getResponseOutputStream().write(dataObjects.get(commandName).getXml().getBytes("UTF-8")); + } facesContext.responseComplete(); } + + public SpResponses getSp() { + return (sp == null ? new SpResponses(this) : sp); + } + } \ No newline at end of file