\r
import com.indexdata.mkjsf.errors.ErrorHelper;\r
import com.indexdata.mkjsf.errors.ErrorInterface;\r
-import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse;\r
import com.indexdata.mkjsf.utils.Utils;\r
\r
@Named("pzresp") @SessionScoped\r
dataObjects = new ConcurrentHashMap<String,ResponseDataObject>(); \r
resetSearchResponses();\r
dataObjects.put("init", new InitResponse());\r
+ dataObjects.put("auth", new AuthResponse());\r
+ dataObjects.put("categories", new CategoriesResponse());\r
}\r
\r
- public InitResponse getInit () {\r
- logger.info("Request to show init response from " + Utils.objectId(this));\r
+ public InitResponse getInit () { \r
return ((InitResponse) dataObjects.get("init"));\r
}\r
-\r
+ \r
public ShowResponse getShow () {\r
return ((ShowResponse) dataObjects.get("show"));\r
}\r
public TermListsResponse getTermLists () {\r
return ((TermListsResponse) dataObjects.get("termlist"));\r
}\r
- \r
+ \r
public List<TermResponse> getFacetTerms (String facet, int count) {\r
return (getTermLists().getTermList(facet).getTerms(count));\r
}\r
return ((ByTarget) dataObjects.get("bytarget"));\r
}\r
\r
+ // Service Proxy extras \r
+ public AuthResponse getAuth () {\r
+ return ((AuthResponse) dataObjects.get("auth"));\r
+ }\r
+\r
+ public CategoriesResponse getCategories() {\r
+ return ((CategoriesResponse) dataObjects.get("categories"));\r
+ }\r
+ // Service Proxy extras\r
+ \r
+\r
public ResponseDataObject getResponseObject (String name) {\r
return dataObjects.get(name);\r
}\r
}\r
\r
public String getActiveClients() { \r
- if (getShow()!=null) {\r
+ if (getShow()!=null && getShow().getActiveClients().length()>0) {\r
logger.debug("Active clients: "+getShow().getActiveClients());\r
- return getShow().getActiveClients();\r
+ return String.valueOf(\r
+ Math.max(Integer.parseInt(getShow().getActiveClients()),\r
+ getStat().getActiveClients()));\r
} else {\r
return "";\r
}\r
}\r
\r
- public SpResponses getSp() {\r
- // TODO:\r
- return null;\r
- }\r
-\r
public void download(String commandName) throws UnsupportedEncodingException, IOException {\r
logger.info(Utils.objectId(this) + " got a download request for "\r
+ commandName);\r
+ ResponseDataObject object = dataObjects.get(commandName); \r
FacesContext facesContext = FacesContext.getCurrentInstance();\r
ExternalContext externalContext = facesContext.getExternalContext();\r
- externalContext.setResponseHeader("Content-Type","application/xml; charset=\"utf-8\"");\r
- externalContext.setResponseHeader("Content-Length",String.valueOf(dataObjects.get(commandName).getXml().getBytes("UTF-8").length));\r
- externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + commandName + ".xml\"");\r
- externalContext.getResponseOutputStream().write(dataObjects.get(commandName).getXml().getBytes("UTF-8"));\r
+ if (object.getIsBinary()) {\r
+ externalContext.setResponseHeader("Content-Type","application/octet-stream");\r
+ externalContext.setResponseHeader("Content-Length",String.valueOf(object.getBinary().length));\r
+ externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + commandName + ".data\"");\r
+ externalContext.getResponseOutputStream().write(object.getBinary()); \r
+ } else {\r
+ externalContext.setResponseHeader("Content-Type","application/xml; charset=\"utf-8\"");\r
+ externalContext.setResponseHeader("Content-Length",String.valueOf(dataObjects.get(commandName).getXml().getBytes("UTF-8").length));\r
+ externalContext.setResponseHeader("Content-Disposition","attachment;filename=\"" + commandName + ".xml\"");\r
+ externalContext.getResponseOutputStream().write(dataObjects.get(commandName).getXml().getBytes("UTF-8"));\r
+ }\r
facesContext.responseComplete();\r
}\r
+ \r
}
\ No newline at end of file