本文整理汇总了Java中org.springframework.web.multipart.support.MissingServletRequestPartException类的典型用法代码示例。如果您正苦于以下问题:Java MissingServletRequestPartException类的具体用法?Java MissingServletRequestPartException怎么用?Java MissingServletRequestPartException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MissingServletRequestPartException类属于org.springframework.web.multipart.support包,在下文中一共展示了MissingServletRequestPartException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMissingValue
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的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());
}
}
示例2: handleMissingAndMalformedParametersValues
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@ExceptionHandler({
InvalidArgumentException.class,
MalformedTemplateException.class,
MissingServletRequestParameterException.class,
MissingServletRequestPartException.class,
ServletRequestBindingException.class })
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
@ResponseBody
public void handleMissingAndMalformedParametersValues(Exception exception) {
log.error("Input parameters were missing/malformed:", exception);
}
示例3: resolveArgument
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
//取出存入的用户ID
String currentUserId = (String) webRequest.getAttribute(Constant.CURRENT_USER_ID, RequestAttributes.SCOPE_REQUEST);
if (currentUserId != null) {
return userDao.findById(currentUserId);
}
return new MissingServletRequestPartException(Constant.CURRENT_USER_ID);
}
示例4: handleMissingServletRequestPart
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleMissingServletRequestPart(final MissingServletRequestPartException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = ex.getRequestPartName() + " part is missing";
final ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
示例5: handleMissingServletRequestPart
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleMissingServletRequestPart(final MissingServletRequestPartException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
logger.info(ex.getClass().getName());
//
final String error = ex.getRequestPartName() + " part is missing";
final AitException AitException = new AitException(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
return handleExceptionInternal(ex, AitException, headers, AitException.getStatus(), request);
}
示例6: handleMissingServletRequestPartException
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@Test
public void handleMissingServletRequestPartException() throws Exception {
MissingServletRequestPartException ex = new MissingServletRequestPartException("name");
ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
assertNotNull("No ModelAndView returned", mav);
assertTrue("No Empty ModelAndView returned", mav.isEmpty());
assertEquals("Invalid status code", 400, response.getStatus());
assertEquals("Required request part 'name' is not present.", response.getErrorMessage());
}
示例7: resolveRequestPartRequired
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@Test
public void resolveRequestPartRequired() throws Exception {
try {
testResolveArgument(null, paramValidRequestPart);
fail("Expected exception");
}
catch (MissingServletRequestPartException ex) {
assertEquals("requestPart", ex.getRequestPartName());
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:RequestPartMethodArgumentResolverTests.java
示例8: handleMissingServletRequestPart
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@Override
protected ResponseEntity<Object> handleMissingServletRequestPart( MissingServletRequestPartException ex, HttpHeaders headers, HttpStatus status, WebRequest request )
{
headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
return new ResponseEntity<>( MessageUtils.jsonMessage(
Integer.toString( status.value() ), ex.getMessage() ), status );
}
示例9: resolveRequestPartRequired
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@Test
public void resolveRequestPartRequired() throws Exception {
try {
testResolveArgument(null, paramValidRequestPart);
fail("Expected exception");
} catch (MissingServletRequestPartException e) {
assertEquals("requestPart", e.getRequestPartName());
}
}
示例10: handle
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
/**
* {@link MissingServletRequestPartException}をハンドリングします。
* @param e {@link MissingServletRequestPartException}
* @return {@link ErrorMessage}
* HTTPステータス 400 でレスポンスを返却します。
*/
@ExceptionHandler(MissingServletRequestPartException.class)
@ResponseBody
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@Override
public ErrorMessage handle(MissingServletRequestPartException e) {
if (L.isDebugEnabled()) {
L.debug(R.getString("D-SPRINGMVC-REST-HANDLER#0011"), e);
}
ErrorMessage error = createClientErrorMessage(HttpStatus.BAD_REQUEST);
warn(error, e);
return error;
}
示例11: MissingServletRequestPartException
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@Test
public void MissingServletRequestPartExceptionをハンドリングできる() {
MissingServletRequestPartException ex = new MissingServletRequestPartException("partName");
ErrorMessage message = this.exceptionHandlerSupport.handle(ex);
assertThat(message, notNullValue());
assertThat(message.getStatus(), is(400));
assertThat(message.getMessage(), is("不正なリクエストです。"));
}
示例12: handleMissingServletRequestPart
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
/**
* 파라미터 검증 실패.
*
* multipart/form-data 에서 key가 file이 아닐때.
*/
@Override
protected ResponseEntity<Object> handleMissingServletRequestPart(MissingServletRequestPartException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
ServiceError serviceError = ServiceError.FORM_VALIDATION_FAILED;
RestErrorResponse restErrorResponse = new RestErrorResponse(serviceError);
try {
log.warn(ObjectMapperUtils.writeValueAsString(restErrorResponse), ex);
} catch (JsonProcessingException ignore) {
log.warn(ex.getLocalizedMessage(), ex);
}
return new ResponseEntity<>(restErrorResponse, HttpStatus.valueOf(serviceError.getHttpStatus()));
}
示例13: getDefaultHandlers
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
private Map<Class, RestExceptionHandler> getDefaultHandlers() {
Map<Class, RestExceptionHandler> map = new HashMap<>();
map.put( NoSuchRequestHandlingMethodException.class, new NoSuchRequestHandlingMethodExceptionHandler() );
map.put( HttpRequestMethodNotSupportedException.class, new HttpRequestMethodNotSupportedExceptionHandler() );
map.put( HttpMediaTypeNotSupportedException.class, new HttpMediaTypeNotSupportedExceptionHandler() );
map.put( MethodArgumentNotValidException.class, new MethodArgumentNotValidExceptionHandler() );
if (ClassUtils.isPresent("javax.validation.ConstraintViolationException", getClass().getClassLoader())) {
map.put( ConstraintViolationException.class, new ConstraintViolationExceptionHandler() );
}
addHandlerTo( map, HttpMediaTypeNotAcceptableException.class, NOT_ACCEPTABLE );
addHandlerTo( map, MissingServletRequestParameterException.class, BAD_REQUEST );
addHandlerTo( map, ServletRequestBindingException.class, BAD_REQUEST );
addHandlerTo( map, ConversionNotSupportedException.class, INTERNAL_SERVER_ERROR );
addHandlerTo( map, TypeMismatchException.class, BAD_REQUEST );
addHandlerTo( map, HttpMessageNotReadableException.class, UNPROCESSABLE_ENTITY );
addHandlerTo( map, HttpMessageNotWritableException.class, INTERNAL_SERVER_ERROR );
addHandlerTo( map, MissingServletRequestPartException.class, BAD_REQUEST );
addHandlerTo(map, Exception.class, INTERNAL_SERVER_ERROR);
// this class didn't exist before Spring 4.0
try {
Class clazz = Class.forName("org.springframework.web.servlet.NoHandlerFoundException");
addHandlerTo(map, clazz, NOT_FOUND);
} catch (ClassNotFoundException ex) {
// ignore
}
return map;
}
开发者ID:jirutka,项目名称:spring-rest-exception-handler,代码行数:33,代码来源:RestHandlerExceptionResolverBuilder.java
示例14: missingServletRequestPartException
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
@GetMapping("/test/missing-servlet-request-part")
public void missingServletRequestPartException() throws Exception {
throw new MissingServletRequestPartException("missing Servlet request part");
}
示例15: getErrorDataProvider
import org.springframework.web.multipart.support.MissingServletRequestPartException; //导入依赖的package包/类
public <T extends Throwable> ErrorDataProvider getErrorDataProvider(T ex) {
if (ex instanceof ApplicationException) {
return new ApplicationErrorDataProvider(errorestProperties);
}
if (ex instanceof ExternalHttpRequestException) {
return new ExternalHttpRequestErrorDataProvider(errorestProperties);
}
if (ex instanceof BindException) {
return new BindExceptionErrorDataProvider(errorestProperties);
}
if (ex instanceof MethodArgumentNotValidException) {
return new MethodArgumentNotValidErrorDataProvider(errorestProperties);
}
if (ex instanceof HttpMediaTypeNotAcceptableException) {
return new MediaTypeNotAcceptableErrorDataProvider(errorestProperties);
}
if (ex instanceof HttpMediaTypeNotSupportedException) {
return new MediaTypeNotSupportedErrorDataProvider(errorestProperties);
}
if (ex instanceof HttpRequestMethodNotSupportedException) {
return new RequestMethodNotSupportedErrorDataProvider(errorestProperties);
}
if (ex instanceof MissingServletRequestParameterException) {
return new MissingServletRequestParameterErrorDataProvider(errorestProperties);
}
if (ex instanceof HttpMessageNotReadableException) {
return new MessageNotReadableErrorDataProvider(errorestProperties);
}
if (ex instanceof MissingServletRequestPartException) {
return new MissingServletRequestPartErrorDataProvider(errorestProperties);
}
if (ex instanceof NoHandlerFoundException) {
return new NoHandlerFoundErrorDataProvider(errorestProperties);
}
if (ex instanceof ServletRequestBindingException) {
return new ServletRequestBindingErrorDataProvider(errorestProperties);
}
if (ex instanceof TypeMismatchException) {
return new TypeMismatchErrorDataProvider(errorestProperties);
}
return new ThrowableErrorDataProvider(errorestProperties);
}