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 javax.servlet.http.HttpServletRequestWrapper;
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
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.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.disk.DiskFileItemFactory;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -188,7 +189,7 @@ public class MultipartRequestWrapper extends HttpServletRequestWrapper {
|
||||||
ParsingStrategy strategy) throws IOException {
|
ParsingStrategy strategy) throws IOException {
|
||||||
try {
|
try {
|
||||||
return upload.parseRequest(req);
|
return upload.parseRequest(req);
|
||||||
} catch (FileSizeLimitExceededException e) {
|
} catch (FileSizeLimitExceededException | SizeLimitExceededException e) {
|
||||||
if (strategy.stashFileSizeException()) {
|
if (strategy.stashFileSizeException()) {
|
||||||
req.setAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION, e);
|
req.setAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION, e);
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
|
@ -16,7 +16,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequestWrapper;
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -285,10 +285,14 @@ public class VitroRequest extends HttpServletRequestWrapper {
|
||||||
return getFileSizeException() != null;
|
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);
|
Object e = getAttribute(ATTRIBUTE_FILE_SIZE_EXCEPTION);
|
||||||
if (e instanceof FileSizeLimitExceededException) {
|
if (e instanceof FileUploadException) {
|
||||||
return (FileSizeLimitExceededException) e;
|
return (FileUploadException) e;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,12 +188,13 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
Individual entity = null;
|
||||||
try {
|
try {
|
||||||
|
entity = validateEntityUri(vreq);
|
||||||
|
|
||||||
checkForFileTooBigException(vreq);
|
checkForFileTooBigException(vreq);
|
||||||
|
|
||||||
String action = vreq.getParameter(PARAMETER_ACTION);
|
String action = vreq.getParameter(PARAMETER_ACTION);
|
||||||
|
|
||||||
Individual entity = validateEntityUri(vreq);
|
|
||||||
if (ACTION_UPLOAD.equals(action)) {
|
if (ACTION_UPLOAD.equals(action)) {
|
||||||
return doUploadImage(vreq, entity);
|
return doUploadImage(vreq, entity);
|
||||||
} else if (ACTION_SAVE.equals(action)) {
|
} else if (ACTION_SAVE.equals(action)) {
|
||||||
|
@ -208,8 +209,8 @@ public class ImageUploadController extends FreemarkerHttpServlet {
|
||||||
return doIntroScreen(vreq, entity);
|
return doIntroScreen(vreq, entity);
|
||||||
}
|
}
|
||||||
} catch (UserMistakeException e) {
|
} catch (UserMistakeException e) {
|
||||||
// Can't find the entity? Complain.
|
// Can't find the entity? Image too large? Complain.
|
||||||
return showAddImagePageWithError(vreq, null, e.formatMessage(vreq));
|
return showAddImagePageWithError(vreq, entity, e.formatMessage(vreq));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// We weren't expecting this - log it, and apologize to the user.
|
// We weren't expecting this - log it, and apologize to the user.
|
||||||
return new ExceptionResponseValues(e);
|
return new ExceptionResponseValues(e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue