本文整理汇总了Java中org.springframework.web.multipart.MaxUploadSizeExceededException类的典型用法代码示例。如果您正苦于以下问题:Java MaxUploadSizeExceededException类的具体用法?Java MaxUploadSizeExceededException怎么用?Java MaxUploadSizeExceededException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MaxUploadSizeExceededException类属于org.springframework.web.multipart包,在下文中一共展示了MaxUploadSizeExceededException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveException
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Override
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception ex) {
if (ex instanceof MaxUploadSizeExceededException) {
WebUtils.writeJson(httpServletResponse, "长传的文件大小超过" + ((MaxUploadSizeExceededException) ex).getMaxUploadSize() + "字节限制,上传失败!");
return null;
}
ModelAndView view = new ModelAndView();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ex.printStackTrace(new PrintStream(byteArrayOutputStream));
String exception = byteArrayOutputStream.toString();
view.getModel().put("error", "URL:" + WebUtils.getWebUrlPath(httpServletRequest) + httpServletRequest.getRequestURI() + "\r\n\r\nERROR:" + exception);
logger.error("[opencron]error:{}", ex.getLocalizedMessage());
view.setViewName("/error/500");
return view;
}
示例2: handleMaxSizeException
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@ExceptionHandler({MultipartException.class})
public ModelAndView handleMaxSizeException(Exception excptn, HttpServletRequest request) {
ModelAndView model = new ModelAndView("sessionexpired");
if (excptn instanceof MultipartException) {
MultipartException mEx = (MultipartException) excptn;
if (excptn instanceof MaxUploadSizeExceededException) {
log.info("MaxUploadSizeExceededException for file : ");
model.addObject("ERROR_MESSAGE_HEADER", "File Size exceeded Limit");
model.addObject("ERROR_MESSAGE_BODY", "Please upload files under the stipulated size limit.");
} else {
model.addObject("ERROR_MESSAGE_HEADER", "Internal Server Error");
model.addObject("errors", "Unexpected error: " + excptn.getMessage());
}
} else {
model.addObject("ERROR_MESSAGE_HEADER", "Internal Server Error");
model.addObject("errors", "Unexpected error: " + excptn.getMessage());
}
return model;
}
示例3: resolveException
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
Exception ex) {
FResult<String> result = null;
if (ex instanceof HttpRequestMethodNotSupportedException) {
HttpRequestMethodNotSupportedException newExp = (HttpRequestMethodNotSupportedException) ex;
result = FResult.newFailure(HttpResponseCode.CLIENT_PARAM_INVALID, newExp.getMessage());
} else if (ex instanceof MaxUploadSizeExceededException) {
result = FResult.newFailure(HttpResponseCode.CLIENT_PARAM_INVALID, "上传文件大小超出限制");
} else if (ex instanceof SizeLimitExceededException) {
result = FResult.newFailure(HttpResponseCode.CLIENT_PARAM_INVALID, "上传文件大小超出限制");
} else {
result = FResult.newFailure(HttpResponseCode.SERVER_ERROR, ex.getMessage());
}
ServletUtil.responseOutWithJson(response, result);
return null;
}
示例4: resolveMultipart
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Override
public MultipartActionRequest resolveMultipart(ActionRequest request) throws MultipartException {
if (request.getAttribute("fail") != null) {
throw new MaxUploadSizeExceededException(1000);
}
if (request instanceof MultipartActionRequest) {
throw new IllegalStateException("Already a multipart request");
}
if (request.getAttribute("resolved") != null) {
throw new IllegalStateException("Already resolved");
}
request.setAttribute("resolved", Boolean.TRUE);
MultiValueMap<String, MultipartFile> files = new LinkedMultiValueMap<String, MultipartFile>();
files.set("someFile", new MockMultipartFile("someFile", "someContent".getBytes()));
Map<String, String[]> params = new HashMap<String, String[]>();
params.put("someParam", new String[] {"someParam"});
return new DefaultMultipartActionRequest(request, files, params, Collections.<String, String>emptyMap());
}
示例5: resolveException
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
/**
* Implementation of the exception resolving method which will only handle the
* {@link MaxUploadSizeExceededException}.
*
* @param request
* the current HTTP request
* @param response
* the response
* @param handler
* the executed handler, which is null in case of an MaxUploadSizeExceededException
* @param ex
* the exception that got thrown
* @return the model and view or null if the exception is not a MaxUploadSizeExceededException
* or no view is defined
*/
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) {
if (ex instanceof MaxUploadSizeExceededException) {
String errorMessage = MessageHelper.getText(request,
"error.blogpost.upload.filesize.limit",
new Object[] { getHumanReadableUploadSizeLimit() });
String targetPath = ClientUrlHelper.removeIds(request.getServletPath()
+ request.getPathInfo());
String view = null;
if (requestMappings != null) {
view = requestMappings.get(targetPath);
}
if (view != null) {
MessageHelper.saveErrorMessage(request, errorMessage);
MessageHelper.setMessageTarget(request, targetPath);
return new ModelAndView(ControllerHelper.replaceModuleInViewName(view));
}
return prepareAjaxModelAndView(request, response, errorMessage);
}
return null;
}
示例6: maxUploadSizeException
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@ExceptionHandler(MaxUploadSizeExceededException.class)
public ModelAndView maxUploadSizeException(Exception ex) {
ModelAndView view = new ModelAndView("views/file/error");
postExecute(view.getModel(), new PostAction() {
@Override
public void invoke(PostResult r) {
MaxUploadSizeExceededException e = (MaxUploadSizeExceededException) ex;
r.setError("上传的文件超过最大限制 %d 。", e.getMaxUploadSize());
}
});
return view;
}
示例7: doFilterInternal
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
try {
super.doFilterInternal(request, response, filterChain);
} catch (MaxUploadSizeExceededException e) {
String msg = "文件超过限制:"+LangUtils.getCauseServiceException(e).getMessage();
logger.error(msg);
if(RequestUtils.getResponseType(request)==ResponseType.JSON){
DataResult<?> dataResult = DataResults.error(msg).build();
ResponseUtils.renderObjectAsJson(response, dataResult);
}else{
response.getWriter().print(msg);
}
}
}
示例8: checkFileTypes
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
protected void checkFileTypes(List<MultipartFile> fileItems, UploadFileValidator validator){
List<String> allowed = validator!=null?Arrays.asList(validator.allowedPostfix()):Arrays.asList(DEFAULT_ALLOW_FILE_TYPES);
for(MultipartFile item : fileItems){
String postfix = FileUtils.getExtendName(item.getOriginalFilename().toLowerCase());
if(validator==null){
if(!allowed.contains(postfix))
throw new ServiceException("It's not allowed file type. file: " + item.getOriginalFilename(), UplaodErrorCode.NOT_ALLOW_FILE);
}else{
if(!allowed.contains(postfix))
throw new ServiceException(validator.allowedPostfixErrorMessage() + " file: " + item.getOriginalFilename(), UplaodErrorCode.NOT_ALLOW_FILE);
if(item.getSize()>validator.maxUploadSize())
throw new MaxUploadSizeExceededException(validator.maxUploadSize());
}
// throw new MaxUploadSizeExceededException(validator.maxUploadSize());
}
}
示例9: resolveException
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Override
public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex) {
// the stacktrace will be printed by spring's DispatcherServlet
// we are only logging the request url and headeres here
logger.warn("An exception occurred when invoking the following URL: "
+ request.getRequestURL() + " . Requester IP is "
+ request.getRemoteAddr() + ", User-Agent: "
+ request.getHeader("User-Agent"));
if (ex instanceof MaxUploadSizeExceededException) {
return new ModelAndView("error/maxFileSizeExceeded");
}
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return null;
}
示例10: UploadEntityImp
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
/**
* 带文件大小限制的构造
*
* @param file
* MultipartFile
* @param maxSize2KB
* 限制文件大小
* @throws IOException
*/
public UploadEntityImp(MultipartFile file, long maxSizeByKB) throws MaxUploadSizeExceededException {
this.file = file;
if (file == null) {
throw new NullPointerException("MultipartFil 不能为空!");
}
fileSizeByKB = file.getSize() / 1024;
if (fileSizeByKB > maxSizeByKB) {
throw new MaxUploadSizeExceededException(maxSizeByKB * 1024);
}
// 获取该文件的文件名
originalFilename = file.getOriginalFilename();
// 获取文件后缀
fileSuffix = UploadUtil.getFileSuffix(originalFilename);
if (fileSuffix == null || fileSuffix.length() == 0) {
// 通过Mime类型获取文件类型
fileSuffix = ContentTypeUtil.getFileTypeByMimeType(file.getContentType());
}
// 创建文件名
filename = UploadUtil.getFileName();
}
示例11: parseRequest
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Override
protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
try {
return super.parseRequest(request);
} catch (MaxUploadSizeExceededException e) {
request.setAttribute(MAX_UPLOAD_SIZE_EXCEEDED_KEY, e);
return parseFileItems(Collections.<FileItem> emptyList(), null);
}
}
示例12: multipartResolutionFailed
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Test
public void multipartResolutionFailed() throws Exception {
MockActionRequest request = new MockActionRequest();
MockActionResponse response = new MockActionResponse();
request.setPortletMode(PortletMode.EDIT);
request.addUserRole("role1");
request.setAttribute("fail", Boolean.TRUE);
complexDispatcherPortlet.processAction(request, response);
String exception = response.getRenderParameter(DispatcherPortlet.ACTION_EXCEPTION_RENDER_PARAMETER);
assertTrue(exception.startsWith(MaxUploadSizeExceededException.class.getName()));
}
示例13: multipartResolutionFailed
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Test
public void multipartResolutionFailed() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def");
request.addPreferredLocale(Locale.CANADA);
request.addUserRole("role1");
request.setAttribute("fail", Boolean.TRUE);
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertTrue("forwarded to failed", "failed0.jsp".equals(response.getForwardedUrl()));
assertEquals(200, response.getStatus());
assertTrue("correct exception", request.getAttribute(
SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE) instanceof MaxUploadSizeExceededException);
}
示例14: doResolveException
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) {
if (returnJson) {//json返回
String callback = request.getParameter(callbackKey);
if(ex instanceof NoLoginException){
logger.warn(ex.getMessage(), ex);
writeJson(response, callback,
BaseResponse.newInstance(String.valueOf(ResponseCode.NO_LOGIN.getCode()),
ResponseCode.NO_LOGIN.getMsg()).setToken(""));
}else if (ex instanceof BizException) {
logger.warn(ex.getMessage(), ex);
writeJson(response, callback,
BaseResponse.newInstance(String.valueOf(ResponseCode.BIZ_ERROR.getCode()),
ex.getMessage()));
}else if (ex instanceof MaxUploadSizeExceededException) {
writeScript(response, "alert('上传文件过大')");
response.setStatus(413);
}else{
logger.error(ex.getMessage(), ex);
writeJson(response, callback,
BaseResponse.newInstance(String.valueOf(ResponseCode.EXCEPTION.getCode()),
ResponseCode.EXCEPTION.getMsg()));
}
return new ModelAndView();
} else {//普通返回
return super.doResolveException(request, response, handler, ex);
}
}
示例15: doResolveException
import org.springframework.web.multipart.MaxUploadSizeExceededException; //导入依赖的package包/类
@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception ex) {
if (returnJson) {//json返回
String callback = request.getParameter(callbackKey);
if(ex instanceof NoLoginException){
logger.warn(ex.getMessage(), ex);
writeJson(response, callback,
BaseResponse.newInstance(String.valueOf(ResponseCode.NO_LOGIN.getCode()),
ResponseCode.NO_LOGIN.getMsg()));
}else if (ex instanceof BizException) {
logger.warn(ex.getMessage(), ex);
writeJson(response, callback,
BaseResponse.newInstance(String.valueOf(ResponseCode.FAILURE.getCode()),
ex.getMessage()));
}else if (ex instanceof MaxUploadSizeExceededException) {
writeScript(response, "alert('上传文件过大')");
response.setStatus(413);
}else{
logger.error(ex.getMessage(), ex);
writeJson(response, callback,
BaseResponse.newInstance(String.valueOf(ResponseCode.EXCEPTION.getCode()),
ResponseCode.EXCEPTION.getMsg()));
}
return new ModelAndView();
} else {//普通返回
return super.doResolveException(request, response, handler, ex);
}
}