VIVO-797 Handle both types of file size exceptions.
Could be either FileSizeLimitExceededException or SizeLimitExceededException.
This commit is contained in:
parent
b6ac3fcd16
commit
7e514f3cfd
3 changed files with 16 additions and 10 deletions
|
@ -18,8 +18,9 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.FileUploadBase.FileSizeLimitExceededException;
|
||||
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -188,7 +189,7 @@ public class MultipartRequestWrapper extends HttpServletRequestWrapper {
|
|||
ParsingStrategy strategy) throws IOException {
|
||||
try {
|
||||
return upload.parseRequest(req);
|
||||
} catch (FileSizeLimitExceededException e) {
|
||||
} catch (FileSizeLimitExceededException | SizeLimitExceededException e) {
|
||||
if (strategy.stashFileSizeException()) {
|
||||
req.setAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION, e);
|
||||
return Collections.emptyList();
|
||||
|
|
|
@ -16,7 +16,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileUploadBase.FileSizeLimitExceededException;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
|
@ -285,10 +285,14 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
|||
return getFileSizeException() != null;
|
||||
}
|
||||
|
||||
public FileSizeLimitExceededException getFileSizeException() {
|
||||
/**
|
||||
* Could be either FileSizeLimitExceededException or
|
||||
* SizeLimitExceededException, so return their common ancestor.
|
||||
*/
|
||||
public FileUploadException getFileSizeException() {
|
||||
Object e = getAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION);
|
||||
if (e instanceof FileSizeLimitExceededException) {
|
||||
return (FileSizeLimitExceededException) e;
|
||||
if (e instanceof FileUploadException) {
|
||||
return (FileUploadException) e;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -188,12 +188,13 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
*/
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
Individual entity = null;
|
||||
try {
|
||||
entity = validateEntityUri(vreq);
|
||||
|
||||
checkForFileTooBigException(vreq);
|
||||
|
||||
String action = vreq.getParameter(PARAMETER_ACTION);
|
||||
|
||||
Individual entity = validateEntityUri(vreq);
|
||||
if (ACTION_UPLOAD.equals(action)) {
|
||||
return doUploadImage(vreq, entity);
|
||||
} else if (ACTION_SAVE.equals(action)) {
|
||||
|
@ -208,8 +209,8 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
|||
return doIntroScreen(vreq, entity);
|
||||
}
|
||||
} catch (UserMistakeException e) {
|
||||
// Can't find the entity? Complain.
|
||||
return showAddImagePageWithError(vreq, null, e.formatMessage(vreq));
|
||||
// Can't find the entity? Image too large? Complain.
|
||||
return showAddImagePageWithError(vreq, entity, e.formatMessage(vreq));
|
||||
} catch (Exception e) {
|
||||
// We weren't expecting this - log it, and apologize to the user.
|
||||
return new ExceptionResponseValues(e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue