fixed 'FileUploadException Stream ended unexpectedly'

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5044 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
danielr 17 years ago
parent 8422ee5ec4
commit bb6a6fc233

@ -873,7 +873,8 @@ public final class httpd implements serverHandler, Cloneable {
* *
* @author danielr * @author danielr
* @since 07.08.2008 * @since 07.08.2008
* @param header hier muss ARGC gesetzt werden! * @param header
* hier muss ARGC gesetzt werden!
* @param args * @param args
* @param in * @param in
* @param length * @param length
@ -881,46 +882,52 @@ public final class httpd implements serverHandler, Cloneable {
* @throws IOException * @throws IOException
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static HashMap<String, byte[]> parseMultipart(final httpHeader header, final serverObjects args, final InputStream in, final int length) throws IOException { public static HashMap<String, byte[]> parseMultipart(final httpHeader header, final serverObjects args, final InputStream in, final int length)
RequestContext request = new yacyContextRequest(header, in); throws IOException {
// read all data from network in memory
if(!FileUploadBase.isMultipartContent(request)) { byte[] buffer = serverFileUtils.read(in);
throw new IOException("the request is not a multipart-message!"); // parse data in memory
} RequestContext request = new yacyContextRequest(header, new ByteArrayInputStream(buffer));
FileItemFactory factory = new DiskFileItemFactory(); // check information
FileUpload upload = new FileUpload(factory); if (!FileUploadBase.isMultipartContent(request)) {
List<FileItem> items; throw new IOException("the request is not a multipart-message!");
try { }
items = upload.parseRequest(request);
} catch (FileUploadException e) { // format information for further usage
throw new IOException("FileUploadException "+e.getMessage()); FileItemFactory factory = new DiskFileItemFactory();
} FileUpload upload = new FileUpload(factory);
List<FileItem> items;
final HashMap<String, byte[]> files = new HashMap<String, byte[]>(); try {
int formFieldCount = 0; items = upload.parseRequest(request);
for(FileItem item: items) { } catch (FileUploadException e) {
if(item.isFormField()) { throw new IOException("FileUploadException " + e.getMessage());
// simple text }
if(item.getContentType() == null || !item.getContentType().contains("charset")) {
// old yacy clients use their local default charset, on most systems UTF-8 (I hope ;) final HashMap<String, byte[]> files = new HashMap<String, byte[]>();
args.put(item.getFieldName(), item.getString("UTF-8")); int formFieldCount = 0;
} else { for (FileItem item : items) {
// use default encoding (given as header or ISO-8859-1) if (item.isFormField()) {
args.put(item.getFieldName(), item.getString()); // simple text
} if (item.getContentType() == null || !item.getContentType().contains("charset")) {
formFieldCount++; // old yacy clients use their local default charset, on most systems UTF-8 (I hope ;)
} else { args.put(item.getFieldName(), item.getString("UTF-8"));
// file } else {
args.put(item.getFieldName(), item.getName()); // use default encoding (given as header or ISO-8859-1)
final byte[] fileContent = serverFileUtils.read(item.getInputStream()); args.put(item.getFieldName(), item.getString());
item.getInputStream().close(); }
files.put(item.getFieldName(), fileContent); formFieldCount++;
} } else {
} // file
header.put("ARGC", String.valueOf(items.size())); // store argument count args.put(item.getFieldName(), item.getName());
final byte[] fileContent = serverFileUtils.read(item.getInputStream());
return files; item.getInputStream().close();
files.put(item.getFieldName(), fileContent);
}
}
header.put("ARGC", String.valueOf(items.size())); // store argument count
return files;
} }
// // FIXME this is a quick hack using a previously coded parseMultipart based on a buffer // // FIXME this is a quick hack using a previously coded parseMultipart based on a buffer
// // should be replaced sometime by a 'right' implementation // // should be replaced sometime by a 'right' implementation

Loading…
Cancel
Save