当前位置: 首页>>代码示例>>Java>>正文


Java MultipartException类代码示例

本文整理汇总了Java中org.springframework.web.multipart.MultipartException的典型用法代码示例。如果您正苦于以下问题:Java MultipartException类的具体用法?Java MultipartException怎么用?Java MultipartException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MultipartException类属于org.springframework.web.multipart包,在下文中一共展示了MultipartException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBody

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@Override
public InputStream getBody() throws IOException {
	if (this.multipartRequest instanceof StandardMultipartHttpServletRequest) {
		try {
			return this.multipartRequest.getPart(this.partName).getInputStream();
		}
		catch (Exception ex) {
			throw new MultipartException("Could not parse multipart servlet request", ex);
		}
	}
	else {
		MultipartFile file = this.multipartRequest.getFile(this.partName);
		if (file != null) {
			return file.getInputStream();
		}
		else {
			String paramValue = this.multipartRequest.getParameter(this.partName);
			return new ByteArrayInputStream(paramValue.getBytes(FORM_CHARSET));
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:RequestPartServletServerHttpRequest.java

示例2: parseRequest

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
private void parseRequest(HttpServletRequest request) {
	try {
		Collection<Part> parts = request.getParts();
		this.multipartParameterNames = new LinkedHashSet<String>(parts.size());
		MultiValueMap<String, MultipartFile> files = new LinkedMultiValueMap<String, MultipartFile>(parts.size());
		for (Part part : parts) {
			String filename = extractFilename(part.getHeader(CONTENT_DISPOSITION));
			if (filename != null) {
				files.add(part.getName(), new StandardMultipartFile(part, filename));
			}
			else {
				this.multipartParameterNames.add(part.getName());
			}
		}
		setMultipartFiles(files);
	}
	catch (Exception ex) {
		throw new MultipartException("Could not parse multipart servlet request", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:StandardMultipartHttpServletRequest.java

示例3: handleMultipartError

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@ExceptionHandler(MultipartException.class)
@ResponseStatus(HttpStatus.PAYLOAD_TOO_LARGE)
public ModelAndView handleMultipartError(HttpServletRequest req, MultipartException exception)
    throws Exception {
    ModelAndView mav = new ModelAndView();
    mav.addObject("page", new Page("mzTabValidator", versionNumber, gaId));
    mav.addObject("error", exception);
    mav.addObject("url", req.getRequestURL());
    mav.addObject("timestamp", new Date().toString());
    mav.addObject("status", 413);
    mav.setViewName("error");
    return mav;
}
 
开发者ID:nilshoffmann,项目名称:jmzTab-m,代码行数:14,代码来源:ValidationController.java

示例4: handleMaxSizeException

import org.springframework.web.multipart.MultipartException; //导入依赖的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;
}
 
开发者ID:Mahidharmullapudi,项目名称:timesheet-upload,代码行数:20,代码来源:GlobalExceptionHandler.java

示例5: getMultipartHeaders

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@Override
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
	try {
		Part part = getPart(paramOrFileName);
		if (part != null) {
			HttpHeaders headers = new HttpHeaders();
			for (String headerName : part.getHeaderNames()) {
				headers.put(headerName, new ArrayList<String>(part.getHeaders(headerName)));
			}
			return headers;
		}
		else {
			return null;
		}
	}
	catch (Exception ex) {
		throw new MultipartException("Could not access multipart servlet request", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:StandardMultipartHttpServletRequest.java

示例6: handleMissingValue

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@Override
protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request)
        throws Exception {

    HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
    if (MultipartResolutionDelegate.isMultipartArgument(parameter)) {
        if (!MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
            throw new MultipartException("Current request is not a multipart request");
        } else {
            throw new MissingServletRequestPartException(name);
        }
    } else {
        throw new MissingServletRequestParameterException(name,
                parameter.getNestedParameterType().getSimpleName());
    }
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:17,代码来源:WxArgumentResolver.java

示例7: resolveMultipart

import org.springframework.web.multipart.MultipartException; //导入依赖的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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ComplexPortletApplicationContext.java

示例8: checkMultipart

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
/**
 * Convert the request into a multipart request, and make multipart resolver available.
 * <p>If no multipart resolver is set, simply use the existing request.
 * @param request current HTTP request
 * @return the processed request (multipart wrapper if necessary)
 * @see MultipartResolver#resolveMultipart
 */
protected HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException {
	if (this.multipartResolver != null && this.multipartResolver.isMultipart(request)) {
		if (WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class) != null) {
			logger.debug("Request is already a MultipartHttpServletRequest - if not in a forward, " +
					"this typically results from an additional MultipartFilter in web.xml");
		}
		else if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) instanceof MultipartException) {
			logger.debug("Multipart resolution failed for current request before - " +
					"skipping re-resolution for undisturbed error rendering");
		}
		else {
			return this.multipartResolver.resolveMultipart(request);
		}
	}
	// If not returned before: return original request.
	return request;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:DispatcherServlet.java

示例9: getBody

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@Override
public InputStream getBody() throws IOException {
	if (this.multipartRequest instanceof StandardMultipartHttpServletRequest) {
		try {
			return this.multipartRequest.getPart(this.partName).getInputStream();
		}
		catch (Exception ex) {
			throw new MultipartException("Could not parse multipart servlet request", ex);
		}
	}
	else {
		MultipartFile file = this.multipartRequest.getFile(this.partName);
		if (file != null) {
			return file.getInputStream();
		}
		else {
			String paramValue = this.multipartRequest.getParameter(this.partName);
			return new ByteArrayInputStream(paramValue.getBytes(determineEncoding()));
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:RequestPartServletServerHttpRequest.java

示例10: parseRequest

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
private void parseRequest(HttpServletRequest request) {
	try {
		Collection<Part> parts = request.getParts();
		this.multipartParameterNames = new LinkedHashSet<String>(parts.size());
		MultiValueMap<String, MultipartFile> files = new LinkedMultiValueMap<String, MultipartFile>(parts.size());
		for (Part part : parts) {
			String disposition = part.getHeader(CONTENT_DISPOSITION);
			String filename = extractFilename(disposition);
			if (filename == null) {
				filename = extractFilenameWithCharset(disposition);
			}
			if (filename != null) {
				files.add(part.getName(), new StandardMultipartFile(part, filename));
			}
			else {
				this.multipartParameterNames.add(part.getName());
			}
		}
		setMultipartFiles(files);
	}
	catch (Exception ex) {
		throw new MultipartException("Could not parse multipart servlet request", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:StandardMultipartHttpServletRequest.java

示例11: getMultipartHeaders

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
	try {
		Part part = getPart(paramOrFileName);
		if (part != null) {
			HttpHeaders headers = new HttpHeaders();
			for (String headerName : part.getHeaderNames()) {
				headers.put(headerName, new ArrayList<String>(part.getHeaders(headerName)));
			}
			return headers;
		}
		else {
			return null;
		}
	}
	catch (Exception ex) {
		throw new MultipartException("Could not access multipart servlet request", ex);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:StandardMultipartHttpServletRequest.java

示例12: resolveException

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@Override
  public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

if(ex instanceof AccessDeniedException) {
	return this.deniedHandler(request, response);
}

      String ip = request.getRemoteAddr();	
if(ex instanceof MultipartException) {
	log.warn("MultipartException with this client " + ip + ". We can assume that the client has canceled his request (because of a double-click / double-submit of the form for example).", ex);
} else {	
	log.error("Uncaught exception  with this client " + ip, ex);
}

// hack for logging uploads failed 
if(request.getServletPath().matches("/postecandidatures/[0-9]*/addFile")) {
	String posteCandidatureId = request.getServletPath().replaceAll("/postecandidatures/([0-9]*)/addFile", "$1");
	PosteCandidature posteCandidature = PosteCandidature.findPosteCandidature(Long.valueOf(posteCandidatureId));
	logService.logActionFile(LogService.UPLOAD_FAILED_ACTION, posteCandidature, null, request, new Date());
}

  	//response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      ModelAndView modelAndview = new ModelAndView("uncaughtException");
      modelAndview.addObject("exception", ex);
      return modelAndview;
  }
 
开发者ID:EsupPortail,项目名称:esup-dematec,代码行数:27,代码来源:ExceptionController.java

示例13: should_find_cause_from_exception_and_return_appropriate_code

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@Test
public void should_find_cause_from_exception_and_return_appropriate_code() {
    final FileUploadBase.FileSizeLimitExceededException fileSizeLimitExceededException =
            new FileUploadBase.FileSizeLimitExceededException("Too Big", 1234, 1024);
    final MultipartException multipartException =
            new MultipartException("Limit exceeded", fileSizeLimitExceededException);

    final ErrorStatusCodeAndMessage statusCodeAndMessage =
            resolver.resolveStatusCodeAndMessage(multipartException, "It broke", 500);

    assertThat(statusCodeAndMessage.getStatusCode(), equalTo(413));
}
 
开发者ID:hmcts,项目名称:document-management-store-app,代码行数:13,代码来源:ExceptionStatusCodeAndMessageResolverTest.java

示例14: getMultipartContentType

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@Override
public String getMultipartContentType(String paramOrFileName) {
	try {
		Part part = getPart(paramOrFileName);
		return (part != null ? part.getContentType() : null);
	}
	catch (Exception ex) {
		throw new MultipartException("Could not access multipart servlet request", ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:StandardMultipartHttpServletRequest.java

示例15: handleMultipartException

import org.springframework.web.multipart.MultipartException; //导入依赖的package包/类
@ExceptionHandler(MultipartException.class)
public ResponseEntity<UploadImagesDTO> handleMultipartException(Exception e){
    UploadImagesDTO dto = new UploadImagesDTO("", false);

    if(e.getCause() instanceof IllegalStateException && e.getCause().getCause() instanceof FileUploadBase.SizeLimitExceededException) {
        return ResponseEntity
                .status(HttpStatus.PAYLOAD_TOO_LARGE)
                .body(dto);
    } else {
        e.printStackTrace();
        return ResponseEntity
                .status(HttpStatus.INTERNAL_SERVER_ERROR)
                .body(dto);
    }
}
 
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:16,代码来源:CustomResponseEntityExceptionHandler.java


注:本文中的org.springframework.web.multipart.MultipartException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。