Revision 8748
Added by ben leinfelder about 10 years ago
MetacatHandler.java | ||
---|---|---|
67 | 67 |
import javax.servlet.http.HttpServletResponse; |
68 | 68 |
import javax.servlet.http.HttpSession; |
69 | 69 |
|
70 |
import org.apache.commons.fileupload.FileItem; |
|
71 |
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
72 |
import org.apache.commons.fileupload.servlet.ServletFileUpload; |
|
70 | 73 |
import org.apache.commons.io.IOUtils; |
71 | 74 |
import org.apache.commons.io.input.XmlStreamReader; |
72 | 75 |
import org.apache.log4j.Logger; |
... | ... | |
79 | 82 |
|
80 | 83 |
import au.com.bytecode.opencsv.CSVWriter; |
81 | 84 |
|
82 |
import com.oreilly.servlet.multipart.FilePart; |
|
83 |
import com.oreilly.servlet.multipart.MultipartParser; |
|
84 |
import com.oreilly.servlet.multipart.ParamPart; |
|
85 |
import com.oreilly.servlet.multipart.Part; |
|
86 |
|
|
87 | 85 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException; |
88 | 86 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile; |
89 | 87 |
import edu.ucsb.nceas.utilities.access.AccessControlInterface; |
... | ... | |
94 | 92 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
95 | 93 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
96 | 94 |
import edu.ucsb.nceas.metacat.dataone.D1NodeService; |
97 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
|
98 | 95 |
import edu.ucsb.nceas.metacat.dataone.SyncAccessPolicy; |
99 | 96 |
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory; |
100 | 97 |
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService; |
... | ... | |
2867 | 2864 |
Hashtable<String,String[]> params = new Hashtable<String,String[]>(); |
2868 | 2865 |
Hashtable<String,String> fileList = new Hashtable<String,String>(); |
2869 | 2866 |
int sizeLimit = 1000; |
2867 |
String tmpDir = "/tmp"; |
|
2870 | 2868 |
try { |
2871 | 2869 |
sizeLimit = |
2872 | 2870 |
(new Integer(PropertyService.getProperty("replication.datafilesizelimit"))).intValue(); |
... | ... | |
2876 | 2874 |
pnfe.getMessage()); |
2877 | 2875 |
pnfe.printStackTrace(System.out); |
2878 | 2876 |
} |
2877 |
try { |
|
2878 |
tmpDir = PropertyService.getProperty("application.tempDir"); |
|
2879 |
} catch (PropertyNotFoundException pnfe) { |
|
2880 |
logMetacat.error("MetacatHandler.handleMultipartForm - " + |
|
2881 |
"Could not determine temp dir, using default. " + |
|
2882 |
pnfe.getMessage()); |
|
2883 |
pnfe.printStackTrace(System.out); |
|
2884 |
} |
|
2879 | 2885 |
logMetacat.debug("MetacatHandler.handleMultipartForm - " + |
2880 | 2886 |
"The size limit of uploaded data files is: " + |
2881 | 2887 |
sizeLimit); |
2882 | 2888 |
|
2883 | 2889 |
try { |
2884 |
MultipartParser mp = new MultipartParser(request, |
|
2885 |
sizeLimit * 1024 * 1024); |
|
2886 |
Part part; |
|
2887 |
|
|
2888 |
while ((part = mp.readNextPart()) != null) { |
|
2889 |
String name = part.getName(); |
|
2890 |
|
|
2891 |
if (part.isParam()) { |
|
2890 |
boolean isMultipart = ServletFileUpload.isMultipartContent(request); |
|
2891 |
// Create a factory for disk-based file items |
|
2892 |
DiskFileItemFactory factory = new DiskFileItemFactory(); |
|
2893 |
|
|
2894 |
// Configure a repository (to ensure a secure temp location is used) |
|
2895 |
File repository = new File(tmpDir); |
|
2896 |
factory.setRepository(repository); |
|
2897 |
|
|
2898 |
// Create a new file upload handler |
|
2899 |
ServletFileUpload upload = new ServletFileUpload(factory); |
|
2900 |
|
|
2901 |
// Parse the request |
|
2902 |
List<FileItem> items = upload.parseRequest(request); |
|
2903 |
|
|
2904 |
Iterator<FileItem> iter = items.iterator(); |
|
2905 |
while (iter.hasNext()) { |
|
2906 |
FileItem item = iter.next(); |
|
2907 |
String name = item.getFieldName(); |
|
2908 |
|
|
2909 |
if (item.isFormField()) { |
|
2910 |
|
|
2892 | 2911 |
// it's a parameter part |
2893 |
ParamPart paramPart = (ParamPart) part; |
|
2894 | 2912 |
String[] values = new String[1]; |
2895 |
values[0] = paramPart.getStringValue();
|
|
2913 |
values[0] = item.getString();
|
|
2896 | 2914 |
params.put(name, values); |
2897 | 2915 |
if (name.equals("action")) { |
2898 | 2916 |
action = values[0]; |
2899 | 2917 |
} |
2900 |
} else if (part.isFile()) {
|
|
2918 |
} else { |
|
2901 | 2919 |
// it's a file part |
2902 |
FilePart filePart = (FilePart) part; |
|
2903 |
String fileName = filePart.getFileName(); |
|
2904 |
|
|
2905 |
// the filePart will be clobbered on the next loop, save to disk |
|
2906 |
tempFile = MetacatUtil.writeTempUploadFile(filePart, fileName); |
|
2920 |
String fileName = item.getName(); |
|
2921 |
|
|
2922 |
// write to disk |
|
2923 |
tempFile = MetacatUtil.writeTempUploadFile(item, fileName); |
|
2907 | 2924 |
fileList.put(name, tempFile.getAbsolutePath()); |
2908 | 2925 |
fileList.put("filename", fileName); |
2909 | 2926 |
fileList.put("name", tempFile.getAbsolutePath()); |
2910 |
} else { |
|
2911 |
logMetacat.info("MetacatHandler.handleMultipartForm - " + |
|
2912 |
"Upload name '" + name + "' was empty."); |
|
2913 | 2927 |
} |
2914 | 2928 |
} |
2915 |
} catch (IOException ioe) {
|
|
2929 |
} catch (Exception ioe) { |
|
2916 | 2930 |
try { |
2917 | 2931 |
out = response.getWriter(); |
2918 | 2932 |
} catch (IOException ioe2) { |
Also available in: Unified diff
switch to use FIleUpload instead of O'Reilly COS library for handling chunked file uploads. https://projects.ecoinformatics.org/ecoinfo/issues/6517