VIVO-617 Adjust the client code to use the new file upload tools.
This commit is contained in:
parent
4b90951b35
commit
03548ae64c
1 changed files with 20 additions and 13 deletions
|
@ -20,13 +20,11 @@ import java.util.Set;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.UnavailableException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
import org.apache.commons.fileupload.FileItem;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -44,7 +42,6 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Exc
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
|
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServletRequest;
|
|
||||||
|
|
||||||
public class FileHarvestController extends FreemarkerHttpServlet {
|
public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
|
@ -130,6 +127,18 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public long maximumMultipartFileSize() {
|
||||||
|
return 1024 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stashFileSizeException() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
try {
|
try {
|
||||||
cleanUpOldSessions();
|
cleanUpOldSessions();
|
||||||
|
@ -259,7 +268,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
|
boolean isMultipart = new VitroRequest(request).isMultipart();
|
||||||
String mode = request.getParameter(PARAMETER_MODE);
|
String mode = request.getParameter(PARAMETER_MODE);
|
||||||
if(isMultipart)
|
if(isMultipart)
|
||||||
doFileUploadPost(request, response);
|
doFileUploadPost(request, response);
|
||||||
|
@ -292,16 +301,14 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
try {
|
try {
|
||||||
VitroRequest vreq = new VitroRequest(request);
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
|
|
||||||
//parse request for uploaded file
|
//check that the parsing was successful
|
||||||
int maxFileSize = 1024 * 1024;
|
if(vreq.hasFileSizeException()) {
|
||||||
FileUploadServletRequest req = FileUploadServletRequest.parseRequest(vreq, maxFileSize);
|
Exception e = vreq.getFileSizeException();
|
||||||
if(req.hasFileUploadException()) {
|
throw new ExceptionVisibleToUser(e);
|
||||||
Exception e = req.getFileUploadException();
|
|
||||||
new ExceptionVisibleToUser(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the job parameter
|
//get the job parameter
|
||||||
String jobParameter = req.getParameter(PARAMETER_JOB);
|
String jobParameter = vreq.getParameter(PARAMETER_JOB);
|
||||||
|
|
||||||
//get the location where we want to save the files (it will end in a slash), then create a File object out of it
|
//get the location where we want to save the files (it will end in a slash), then create a File object out of it
|
||||||
String path = getUploadPath(vreq);
|
String path = getUploadPath(vreq);
|
||||||
|
@ -311,7 +318,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
// still have the same session ID and therefore the upload directory is unchanged. Thus we must clear the
|
// still have the same session ID and therefore the upload directory is unchanged. Thus we must clear the
|
||||||
// upload directory if it exists (a "first upload" parameter, initialized to "true" but which gets set to
|
// upload directory if it exists (a "first upload" parameter, initialized to "true" but which gets set to
|
||||||
// "false" once the user starts uploading stuff is used for this).
|
// "false" once the user starts uploading stuff is used for this).
|
||||||
String firstUpload = req.getParameter(PARAMETER_FIRST_UPLOAD); //clear directory on first upload
|
String firstUpload = vreq.getParameter(PARAMETER_FIRST_UPLOAD); //clear directory on first upload
|
||||||
if(firstUpload.toLowerCase().equals("true")) {
|
if(firstUpload.toLowerCase().equals("true")) {
|
||||||
if(directory.exists()) {
|
if(directory.exists()) {
|
||||||
File[] children = directory.listFiles();
|
File[] children = directory.listFiles();
|
||||||
|
@ -329,7 +336,7 @@ public class FileHarvestController extends FreemarkerHttpServlet {
|
||||||
FileHarvestJob job = getJob(vreq, jobParameter);
|
FileHarvestJob job = getJob(vreq, jobParameter);
|
||||||
|
|
||||||
//get the files out of the parsed request (there should only be one)
|
//get the files out of the parsed request (there should only be one)
|
||||||
Map<String, List<FileItem>> fileStreams = req.getFiles();
|
Map<String, List<FileItem>> fileStreams = vreq.getFiles();
|
||||||
if(fileStreams.get(PARAMETER_UPLOADED_FILE) != null && fileStreams.get(PARAMETER_UPLOADED_FILE).size() > 0) {
|
if(fileStreams.get(PARAMETER_UPLOADED_FILE) != null && fileStreams.get(PARAMETER_UPLOADED_FILE).size() > 0) {
|
||||||
|
|
||||||
//get the individual file data from the request
|
//get the individual file data from the request
|
||||||
|
|
Loading…
Add table
Reference in a new issue