* Upgrade to commons-fileupload 1.1
* Move check for multipart content inside try statement
This commit is contained in:
parent
66016004d1
commit
ad9da0be95
1 changed files with 25 additions and 23 deletions
|
@ -27,10 +27,11 @@ import java.util.*;
|
||||||
import javax.servlet.*;
|
import javax.servlet.*;
|
||||||
import javax.servlet.http.*;
|
import javax.servlet.http.*;
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileUpload;
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
import org.apache.commons.fileupload.FileItem;
|
||||||
import org.apache.commons.fileupload.DiskFileUpload;
|
|
||||||
import org.apache.commons.fileupload.FileUploadBase;
|
import org.apache.commons.fileupload.FileUploadBase;
|
||||||
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
|
import org.apache.commons.fileupload.servlet.ServletRequestContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is an abstract Hop servlet adapter. This class communicates with hop applications
|
* This is an abstract Hop servlet adapter. This class communicates with hop applications
|
||||||
|
@ -162,10 +163,11 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FileUpload.isMultipartContent(request)) {
|
try {
|
||||||
// File Upload
|
ServletRequestContext reqcx = new ServletRequestContext(request);
|
||||||
try {
|
if (ServletFileUpload.isMultipartContent(reqcx)) {
|
||||||
DiskFileUpload upload = new DiskFileUpload();
|
// File Upload
|
||||||
|
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
|
||||||
|
|
||||||
upload.setSizeMax(uploadLimit * 1024);
|
upload.setSizeMax(uploadLimit * 1024);
|
||||||
upload.setHeaderEncoding(encoding);
|
upload.setHeaderEncoding(encoding);
|
||||||
|
@ -194,23 +196,23 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception upx) {
|
}
|
||||||
System.err.println("Error in file upload: " + upx);
|
} catch (Exception upx) {
|
||||||
if (uploadSoftfail) {
|
System.err.println("Error in file upload: " + upx);
|
||||||
String msg = upx.getMessage();
|
if (uploadSoftfail) {
|
||||||
if (msg == null || msg.length() == 0) {
|
String msg = upx.getMessage();
|
||||||
msg = upx.toString();
|
if (msg == null || msg.length() == 0) {
|
||||||
}
|
msg = upx.toString();
|
||||||
reqtrans.set("helma_upload_error", msg);
|
|
||||||
} else if (upx instanceof FileUploadBase.SizeLimitExceededException) {
|
|
||||||
sendError(response, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE,
|
|
||||||
"File upload size exceeds limit of " + uploadLimit + "kB");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
|
||||||
"Error in file upload: " + upx);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
reqtrans.set("helma_upload_error", msg);
|
||||||
|
} else if (upx instanceof FileUploadBase.SizeLimitExceededException) {
|
||||||
|
sendError(response, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE,
|
||||||
|
"File upload size exceeds limit of " + uploadLimit + "kB");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||||
|
"Error in file upload: " + upx);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -816,7 +818,7 @@ public abstract class AbstractServletClient extends HttpServlet {
|
||||||
|
|
||||||
pathbuffer.append(UrlEncoded.decode(token, encoding));
|
pathbuffer.append(UrlEncoded.decode(token, encoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
// append trailing "/" if it is contained in original URI
|
// append trailing "/" if it is contained in original URI
|
||||||
if (uri.endsWith("/"))
|
if (uri.endsWith("/"))
|
||||||
pathbuffer.append('/');
|
pathbuffer.append('/');
|
||||||
|
|
Loading…
Add table
Reference in a new issue