<groupId>org.apache.httpcomponents</groupId>\r
<artifactId>httpclient</artifactId>\r
<version>4.2.3</version>\r
- </dependency> \r
+ </dependency>\r
+ <!-- File upload -->\r
+ <dependency>\r
+ <groupId>org.apache.myfaces.tomahawk</groupId>\r
+ <artifactId>tomahawk20</artifactId>\r
+ <version>1.1.10</version>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>commons-io</groupId>\r
+ <artifactId>commons-io</artifactId>\r
+ <version>2.1</version>\r
+ </dependency>\r
+ \r
\r
<dependency>\r
<groupId>com.indexdata</groupId>\r
public int getStatusCode();\r
public String getContentType();\r
public String getResponseString();\r
- public byte[] getBinaryResponse();\r
+ public byte[] getBytes();\r
public boolean isBinary();\r
}\r
}\r
\r
@Override\r
- public byte[] getBinaryResponse() {\r
+ public byte[] getBytes() {\r
return content;\r
}\r
\r
\r
import com.indexdata.mkjsf.config.ConfigurationReader;\r
import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyClient;\r
+import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyCommandResponse;\r
import com.indexdata.mkjsf.pazpar2.sp.ServiceProxyInterface;\r
import com.indexdata.mkjsf.pazpar2.sp.auth.ServiceProxyUser;\r
import com.indexdata.mkjsf.utils.Utils;\r
}\r
\r
@Override\r
- public String postInit() throws UnsupportedEncodingException, IOException { \r
+ public ServiceProxyCommandResponse postInit() throws UnsupportedEncodingException, IOException { \r
String initDocPath = ((ServiceProxyClient)searchClient).getInitDocPaths().get(0);\r
logger.info("Paths: " + ((ServiceProxyClient)searchClient).getInitDocPaths());\r
logger.info("Path: " + initDocPath);\r
pzresp.reset();\r
- byte[] response = ((ServiceProxyClient)searchClient).postInitDoc(initDocPath + getInitFileName());\r
- initDocResponse = new String(response,"UTF-8");\r
- return initDocResponse;\r
+ ServiceProxyCommandResponse response = ((ServiceProxyClient)searchClient).postInitDoc(initDocPath + getInitFileName()); \r
+ return response;\r
}\r
\r
@Override\r
- public String postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { \r
+ public ServiceProxyCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException { \r
pzresp.reset();\r
- byte[] response = ((ServiceProxyClient)searchClient).postInitDoc(initDoc,includeDebug);\r
- initDocResponse = new String(response,"UTF-8");\r
- return initDocResponse;\r
+ ServiceProxyCommandResponse response = ((ServiceProxyClient)searchClient).postInitDoc(initDoc,includeDebug); \r
+ return response;\r
}\r
\r
@Override\r
--- /dev/null
+package com.indexdata.mkjsf.pazpar2.commands.sp;\r
+\r
+import java.io.IOException;\r
+\r
+import javax.enterprise.context.SessionScoped;\r
+import javax.inject.Inject;\r
+import javax.inject.Named;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.mkjsf.pazpar2.Pz2ProxyBean;\r
+import com.indexdata.mkjsf.utils.FileUpload;\r
+import com.indexdata.mkjsf.utils.Utils;\r
+\r
+@Named\r
+@SessionScoped\r
+public class InitDocUpload extends FileUpload {\r
+\r
+ private static Logger logger = Logger.getLogger(InitDocUpload.class);\r
+ private static final long serialVersionUID = 1846749236304941323L;\r
+ @Inject Pz2ProxyBean spBean;\r
+ private boolean includeDebug = false;\r
+\r
+ public String submit() throws IOException {\r
+ logger.info(Utils.objectId(this) + " submitting");\r
+ //String fileName = FilenameUtils.getName(uploadedFile.getName());\r
+ //String contentType = uploadedFile.getContentType();\r
+ byte[] bytes = uploadedFile.getBytes();\r
+ response = spBean.postInit(bytes, includeDebug);\r
+ return "";\r
+ }\r
+\r
+ public void setIncludeDebug(boolean bool) {\r
+ logger.info(Utils.objectId(this) + " setting debug to " + bool);\r
+ includeDebug = bool;\r
+ }\r
+\r
+ public boolean getIncludeDebug() {\r
+ return includeDebug;\r
+ }\r
+\r
+}\r
\r
import com.indexdata.mkjsf.errors.ErrorHelper;\r
import com.indexdata.mkjsf.errors.ErrorInterface;\r
+import com.indexdata.mkjsf.pazpar2.data.sp.SpResponses;\r
\r
@Named("pzresp") @SessionScoped\r
public class Pazpar2Responses implements Serializable {\r
}\r
}\r
\r
+ public SpResponses getSp() {\r
+ // TODO:\r
+ return null;\r
+ }\r
\r
}\r
--- /dev/null
+package com.indexdata.mkjsf.pazpar2.data.sp;\r
+\r
+public class SpResponses {\r
+\r
+ public SpResponses() {\r
+ // TODO Auto-generated constructor stub\r
+ }\r
+\r
+}\r
logger.info(Utils.objectId(this) + " is configuring using the provided " + Utils.objectId(configReader));\r
try {\r
config = configReader.getConfiguration(this); \r
- serviceUrls = getMultiProperty(config.get(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
+ this.initDocPaths = getMultiProperty(config.get(SP_INIT_DOC_PATHS),",");\r
checkAuth = new AuthCommand(null);\r
checkAuth.setParameterInState(new CommandParameter("action","=","check"));\r
ipAuth = new AuthCommand(null);\r
} \r
}\r
\r
- private List<String> getMultiProperty(String prop) {\r
+ private List<String> getMultiProperty(String prop, String separator) {\r
List<String> props = new ArrayList<String>();\r
if (prop != null) { \r
- StringTokenizer tokenizer = new StringTokenizer(prop,",");\r
+ StringTokenizer tokenizer = new StringTokenizer(prop,separator);\r
while (tokenizer.hasMoreElements()) {\r
props.add(tokenizer.nextToken());\r
} \r
return null;\r
}\r
\r
- public byte[] postInitDoc (String filePath) throws IOException {\r
+ public ServiceProxyCommandResponse postInitDoc (String filePath) throws IOException {\r
logger.info("Looking to post the file in : [" + filePath +"]");\r
HttpPost post = new HttpPost(selectedServiceUrl+"?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.debug("Response on POST was: " + new String(response,"UTF-8")); \r
- return response;\r
+ return new ServiceProxyCommandResponse(handler.getStatusCode(),response,handler.getContentType()); \r
}\r
\r
public List<String> getInitDocPaths () {\r
return initDocPaths;\r
}\r
\r
- public byte[] postInitDoc(byte[] initDoc, boolean includeDebug) throws IOException {\r
+ public ServiceProxyCommandResponse postInitDoc(byte[] initDoc, boolean includeDebug) throws IOException {\r
HttpPost post = new HttpPost(selectedServiceUrl+"?command=init" + (includeDebug? "&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
- return response;\r
+ return new ServiceProxyCommandResponse(handler.getStatusCode(),response,handler.getContentType()); \r
}\r
\r
public void setServiceProxyUrl (String url) {\r
}\r
\r
@Override\r
- public byte[] getBinaryResponse() { \r
+ public byte[] getBytes() { \r
return content;\r
}\r
\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 postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException;\r
+ public ServiceProxyCommandResponse postInit() throws UnsupportedEncodingException, IOException;\r
+ public ServiceProxyCommandResponse postInit(byte[] initDoc, boolean includeDebug) throws UnsupportedEncodingException, IOException;\r
public String getInitResponse();\r
public void setServiceProxyUrl(String url);\r
public String getServiceProxyUrl();\r
--- /dev/null
+package com.indexdata.mkjsf.utils;\r
+\r
+import java.io.IOException;\r
+import java.io.Serializable;\r
+\r
+import javax.faces.context.ExternalContext;\r
+import javax.faces.context.FacesContext;\r
+\r
+import org.apache.commons.io.FilenameUtils;\r
+import org.apache.log4j.Logger;\r
+import org.apache.myfaces.custom.fileupload.UploadedFile;\r
+\r
+import com.indexdata.mkjsf.pazpar2.CommandResponse;\r
+\r
+public abstract class FileUpload implements Serializable {\r
+\r
+ protected UploadedFile uploadedFile;\r
+ protected CommandResponse response;\r
+ private static Logger logger = Logger.getLogger(FileUpload.class);\r
+ private static final long serialVersionUID = 748784638056392862L;\r
+\r
+ public FileUpload() {\r
+ }\r
+\r
+ public abstract String submit() throws IOException;\r
+ \r
+ public UploadedFile getUploadedFile() {\r
+ return uploadedFile;\r
+ }\r
+\r
+ public void setUploadedFile(UploadedFile uploadedFile) {\r
+ logger.info(Utils.objectId(this) + " received an uploaded file [" + Utils.objectId(uploadedFile) + "]");\r
+ this.uploadedFile = uploadedFile;\r
+ }\r
+ \r
+ public void downloadDoc() throws IOException {\r
+ logger.info(Utils.objectId(this) + " got a download request");\r
+ FacesContext facesContext = FacesContext.getCurrentInstance();\r
+ ExternalContext externalContext = facesContext.getExternalContext();\r
+ externalContext.setResponseHeader("Content-Type", uploadedFile.getContentType());\r
+ externalContext.setResponseHeader("Content-Length", String.valueOf((uploadedFile.getBytes().length)));\r
+ externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"" + FilenameUtils.getBaseName(uploadedFile.getName()) + "\"");\r
+ externalContext.getResponseOutputStream().write(uploadedFile.getBytes());\r
+ facesContext.responseComplete();\r
+ }\r
+ \r
+ public void downloadResponse () throws IOException {\r
+ logger.info(Utils.objectId(this) + " got a download request");\r
+ FacesContext facesContext = FacesContext.getCurrentInstance();\r
+ ExternalContext externalContext = facesContext.getExternalContext();\r
+ externalContext.setResponseHeader("Content-Type", response.getContentType());\r
+ externalContext.setResponseHeader("Content-Length", String.valueOf((response.getBytes().length)));\r
+ externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"initresponse.xml\"");\r
+ externalContext.getResponseOutputStream().write(response.getBytes());\r
+ facesContext.responseComplete();\r
+ }\r
+\r
+\r
+\r
+}\r