use of org.springframework.web.multipart.MultipartException in project spring-framework by spring-projects.
the class CommonsMultipartResolver method parseRequest.
/**
* Parse the given servlet request, resolving its multipart elements.
* @param request the request to parse
* @return the parsing result
* @throws MultipartException if multipart resolution failed.
*/
protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
String encoding = determineEncoding(request);
FileUpload fileUpload = prepareFileUpload(encoding);
try {
List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
return parseFileItems(fileItems, encoding);
} catch (FileUploadBase.SizeLimitExceededException ex) {
throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex);
} catch (FileUploadBase.FileSizeLimitExceededException ex) {
throw new MaxUploadSizeExceededException(fileUpload.getFileSizeMax(), ex);
} catch (FileUploadException ex) {
throw new MultipartException("Failed to parse multipart servlet request", ex);
}
}
use of org.springframework.web.multipart.MultipartException in project com.revolsys.open by revolsys.
the class RsExceptionResolver method resolveException.
@Override
public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception exception) {
try {
if (exception instanceof PageNotFoundException) {
final PageNotFoundException pageNotFound = (PageNotFoundException) exception;
response.sendError(HttpServletResponse.SC_NOT_FOUND, pageNotFound.getMessage());
return new ModelAndView();
} else if (exception instanceof IllegalArgumentException) {
final IllegalArgumentException illegalArgument = (IllegalArgumentException) exception;
response.sendError(HttpServletResponse.SC_BAD_REQUEST, illegalArgument.getMessage());
return new ModelAndView();
} else if (exception instanceof RedirectException) {
final RedirectException redirect = (RedirectException) exception;
response.sendRedirect(redirect.getUrl());
return new ModelAndView();
} else if (exception instanceof MultipartException) {
final MultipartException multiPartException = (MultipartException) exception;
Throwable cause = multiPartException.getCause();
if (cause == null) {
cause = exception;
}
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid HTTP multi-part request: " + cause.getMessage());
return new ModelAndView();
}
} catch (final IOException e) {
}
return null;
}
use of org.springframework.web.multipart.MultipartException in project mecaworks by KadarH.
the class ErrorHandler method handle.
@ExceptionHandler(value = { ApplicationException.class, MultipartException.class })
public ModelAndView handle(HttpServletRequest request, Exception e) {
/*if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null)
throw e;*/
ModelAndView mav = new ModelAndView();
if (e instanceof MultipartException) {
mav.addObject("exception", new Exception("Image upload échouée, vérifier la taille du fichier (max = 5MB)", e));
} else {
mav.addObject("exception", e);
}
mav.setViewName("error/exception");
log.warn("Application exception thrown - url : [" + request.getMethod() + "]" + request.getRequestURI(), e);
return mav;
}
use of org.springframework.web.multipart.MultipartException in project ngtesting-platform by aaronchen2k.
the class PJCommonsMultipartResolver method parseRequest.
@Override
public MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
String encoding = "utf-8";
FileUpload fileUpload = prepareFileUpload(encoding);
PJProgressListener uploadProgressListener = new PJProgressListener(request);
fileUpload.setProgressListener(uploadProgressListener);
try {
List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
return parseFileItems(fileItems, encoding);
} catch (FileUploadBase.SizeLimitExceededException ex) {
throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex);
} catch (FileUploadException ex) {
throw new MultipartException("Could not parse multipart servlet request", ex);
}
}
use of org.springframework.web.multipart.MultipartException in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolver method resolveArgument.
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception {
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
Assert.state(servletRequest != null, "No HttpServletRequest");
RequestPart requestPart = parameter.getParameterAnnotation(RequestPart.class);
boolean isRequired = ((requestPart == null || requestPart.required()) && !parameter.isOptional());
String name = getPartName(parameter, requestPart);
parameter = parameter.nestedIfOptional();
Object arg = null;
Object mpArg = MultipartResolutionDelegate.resolveMultipartArgument(name, parameter, servletRequest);
if (mpArg != MultipartResolutionDelegate.UNRESOLVABLE) {
arg = mpArg;
} else {
try {
HttpInputMessage inputMessage = new RequestPartServletServerHttpRequest(servletRequest, name);
arg = readWithMessageConverters(inputMessage, parameter, parameter.getNestedGenericParameterType());
if (binderFactory != null) {
WebDataBinder binder = binderFactory.createBinder(request, arg, name);
if (arg != null) {
validateIfApplicable(binder, parameter);
if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
throw new MethodArgumentNotValidException(parameter, binder.getBindingResult());
}
}
if (mavContainer != null) {
mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());
}
}
} catch (MissingServletRequestPartException | MultipartException ex) {
if (isRequired) {
throw ex;
}
}
}
if (arg == null && isRequired) {
if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
throw new MultipartException("Current request is not a multipart request");
} else {
throw new MissingServletRequestPartException(name);
}
}
return adaptArgumentIfNecessary(arg, parameter);
}
Aggregations