org.springframework.web.bind.MissingServletRequestParameterException Java Examples

The following examples show how to use org.springframework.web.bind.MissingServletRequestParameterException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WxArgumentResolver.java    From FastBootWeixin with Apache License 2.0 8 votes vote down vote up
@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());
    }
}
 
Example #2
Source File: RequestParamMethodArgumentResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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());
	}
}
 
Example #3
Source File: RestControllerAdvice.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
/**
 * Client did not formulate a correct request.
 * Log the exception message at warn level and stack trace as trace level.
 * Return response status HttpStatus.BAD_REQUEST (400).
 */
@ExceptionHandler({
	MissingServletRequestParameterException.class,
	MethodArgumentTypeMismatchException.class,
	InvalidStreamDefinitionException.class
})
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public VndErrors onClientGenericBadRequest(Exception e) {
	String logref = logWarnLevelExceptionMessage(e);
	if (logger.isTraceEnabled()) {
		logTraceLevelStrackTrace(e);
	}
	String msg = getExceptionMessage(e);
	return new VndErrors(logref, msg);
}
 
Example #4
Source File: RestRequest.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
public String getParameter(String paramName, String defaultValue) throws ServletException {
  String paramValue = request.getParameter(paramName);
  if (StringUtils.isEmpty(paramValue)) {
    if (defaultValue == null) {
      throw new MissingServletRequestParameterException(paramName, "String");
    } else {
      return defaultValue;
    }
  } else {
    return paramValue;
  }
}
 
Example #5
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex
) {

	List<String> errors = new ArrayList<>();
	String error = ex.getParameterName() + ", " + ex.getMessage();
	errors.add(error);
	ErrorMessage errorMessage = new ErrorMessage(errors);
	return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST);
}
 
Example #6
Source File: GlobalExceptionHandler.java    From ywh-frame with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 400错误拦截
 * @param ex 异常信息
 * @return 返回前端异常信息
 */
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Result request400(MissingServletRequestParameterException ex){
    log.error("错误详情:" + ex.getMessage(),ex);
    return Result.errorJson(BaseEnum.BAD_REQUEST.getMsg() + "   找不到传入的参数",BaseEnum.BAD_REQUEST.getIndex());
}
 
Example #7
Source File: ServiceBrokerWebMvcExceptionHandler.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a {@link MissingServletRequestParameterException}
 *
 * @param ex the exception
 * @return an error message
 */
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorMessage handleException(MissingServletRequestParameterException ex) {
	LOG.error(UNPROCESSABLE_REQUEST, ex);
	return getErrorResponse(ex.getMessage());
}
 
Example #8
Source File: GlobalExceptionHand.java    From spring-boot-shiro with Apache License 2.0 5 votes vote down vote up
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public Response handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
    String msg = "缺少请求参数!";
    log.error(msg, e);
    return new Response().failure(msg);
}
 
Example #9
Source File: ExceptionHandlingController.java    From voj with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 处理MissingServletRequestParameterException异常的方法.
 * @param request - HttpRequest对象
 * @param response - HttpResponse对象
 * @return 返回一个包含异常信息的ModelAndView对象
 */
@ResponseStatus(value=HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public ModelAndView badRequestView(
		HttpServletRequest request, HttpServletResponse response) {
	ModelAndView view = new ModelAndView("errors/404");
	return view;
}
 
Example #10
Source File: RestDefaultExceptionHandlerTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Test
public void MissingServletRequestParameterExceptionをハンドリングできる() {
    MissingServletRequestParameterException ex = new MissingServletRequestParameterException("name", "type");
    ErrorMessage message = this.exceptionHandlerSupport.handle(ex);
    assertThat(message, notNullValue());
    assertThat(message.getStatus(), is(400));
    assertThat(message.getMessage(), is("不正なリクエストです。"));
}
 
Example #11
Source File: GlobalExceptionHandler.java    From SENS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public String handleMissingServletRequestParameterException(MissingServletRequestParameterException e, Model model) {
    log.error("缺少请求参数", e);
    String message = "【缺少请求参数】" + e.getMessage();
    model.addAttribute("message", message);
    model.addAttribute("code", 400);
    return viewName;
}
 
Example #12
Source File: GlobalExceptionTranslator.java    From staffjoy with MIT License 5 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
public BaseResponse handleError(MissingServletRequestParameterException e) {
    logger.warn("Missing Request Parameter", e);
    String message = String.format("Missing Request Parameter: %s", e.getParameterName());
    return BaseResponse
            .builder()
            .code(ResultCode.PARAM_MISS)
            .message(message)
            .build();
}
 
Example #13
Source File: CustomRestExceptionHandler.java    From xxproject with Apache License 2.0 5 votes vote down vote up
@Override
protected ResponseEntity<Object> handleMissingServletRequestParameter(final MissingServletRequestParameterException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
    logger.info(ex.getClass().getName());
    //
    final String error = ex.getParameterName() + " parameter is missing";
    final ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST, ex.getLocalizedMessage(), error);
    return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
 
Example #14
Source File: RestControllerExceptionTranslator.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
/**
 * 请求方法的的参数缺失
 */
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
ResponseMessage handleException(MissingServletRequestParameterException exception) {
    return ResponseMessage
            .error(HttpStatus.BAD_REQUEST.value(), "参数[" + exception.getParameterName() + "]不能为空");
}
 
Example #15
Source File: GlobalExceptionHandler.java    From Spring-Boot-Book with Apache License 2.0 5 votes vote down vote up
/**
 * 400 - Bad Request
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public Map<String, Object> handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
    logger.error("缺少请求参数", e);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("rspCode", 400);
    map.put("rspMsg", e.getMessage());
    //发生异常进行日志记录,写入数据库或者其他处理,此处省略
    return map;
}
 
Example #16
Source File: ExceptionAdviser.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler({
    MethodArgumentNotValidException.class,
    MissingServletRequestParameterException.class
})
public ResponseMessage<Object> inputArgumentException(Exception e) {
    return new ResponseMessage<>(ErrorCode.INVALID_ARGUMENT, e.getMessage(), null);
}
 
Example #17
Source File: GenericExceptionHandlingControllerAdvice.java    From omh-dsu-ri with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public void handleMissingServletRequestParameterException(MissingServletRequestParameterException e,
        HttpServletRequest request) {

    log.debug("A {} request for '{}' failed because parameter '{}' is missing.",
            request.getMethod(), request.getPathInfo(), e.getParameterName(), e);
}
 
Example #18
Source File: GlobalControllerAdvice.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public ResponseEntity<ErrorMessage> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex
) {

	List<String> errors = new ArrayList<>();
	String error = ex.getParameterName() + ", " + ex.getMessage();
	errors.add(error);
	ErrorMessage errorMessage = new ErrorMessage(errors);
	return new ResponseEntity(errorMessage, HttpStatus.BAD_REQUEST);
}
 
Example #19
Source File: BladeRestExceptionTranslator.java    From blade-tool with GNU Lesser General Public License v3.0 5 votes vote down vote up
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public R handleError(MissingServletRequestParameterException e) {
	log.warn("缺少请求参数", e.getMessage());
	String message = String.format("缺少必要的请求参数: %s", e.getParameterName());
	return R.fail(ResultCode.PARAM_MISS, message);
}
 
Example #20
Source File: DefaultHandlerExceptionResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void handleMissingServletRequestParameter() {
	MissingServletRequestParameterException ex = new MissingServletRequestParameterException("foo", "bar");
	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 bar parameter 'foo' is not present", response.getErrorMessage());
}
 
Example #21
Source File: ControllerAdviceHandler.java    From common-project with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Object handle(Exception exception) {
    logger.error("错误信息  ====  "+exception.getMessage());
    if (exception instanceof BindException) {
        BindException bindException = (BindException) exception;
        List<FieldError> fieldErrors = bindException.getFieldErrors();
        for (FieldError fieldError : fieldErrors) {
            return ResponseMessage.error(10010,fieldError.getField() + fieldError.getDefaultMessage());
        }
    }

    if (exception instanceof ConstraintViolationException) {
        ConstraintViolationException exs = (ConstraintViolationException) exception;

        Set<ConstraintViolation<?>> violations = exs.getConstraintViolations();
        for (ConstraintViolation<?> violation : violations) {
            return ResponseMessage.error(10010,violation.getPropertyPath() + violation.getMessage());
        }
    }
    if (exception instanceof HandlerException) {
        HandlerException handlerException = (HandlerException) exception;
        return new ResponseMessage(handlerException.getCode(), handlerException.getErrorInfo());
    }
    if (exception instanceof MissingServletRequestParameterException) {
        MissingServletRequestParameterException missingServletRequestParameterException = (MissingServletRequestParameterException) exception;
        return ResponseMessage.error(10010, "请求参数" + missingServletRequestParameterException.getParameterName() + "不能为空");
    }
    if (exception instanceof FileUploadException) {
        FileUploadException fileUploadException = (FileUploadException) exception;
        return ResponseMessage.error(10010, fileUploadException.getMessage());
    }

    return ResponseMessage.error(0, "服务异常");
}
 
Example #22
Source File: RestExceptionHandler.java    From plumemo with Apache License 2.0 5 votes vote down vote up
/**
 * 400错误
 */
@ExceptionHandler({MissingServletRequestParameterException.class})
@ResponseBody
public Result requestMissingServletRequest(MissingServletRequestParameterException ex) {
    log.error("异常类 MissingServletRequestParameterException {},", ex.getMessage());
    return Result.createWithErrorMessage(ErrorEnum.PARAM_INCORRECT);
}
 
Example #23
Source File: ServletWebErrorHandlerTest.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
private Object[] provideParamsForCanHandle() {
    return p(
        p(null, false),
        p(new RuntimeException(), false),
        p(new NoHandlerFoundException(null, null, null), true),
        p(new HttpMessageNotReadableException("", mock(HttpInputMessage.class)), true),
        p(new MissingServletRequestParameterException("name", "String"), true),
        p(new HttpMediaTypeNotAcceptableException(""), true),
        p(new HttpMediaTypeNotSupportedException(""), true),
        p(new HttpRequestMethodNotSupportedException(""), true),
        p(new MissingServletRequestPartException("file"), true)
    );
}
 
Example #24
Source File: ServletWebErrorHandler.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Only handles {@link ServletException}s and {@link HttpMessageNotReadableException}s.
 *
 * @param exception The exception to examine.
 * @return {@code true} when can handle the {@code exception}, {@code false} otherwise.
 */
@Override
public boolean canHandle(Throwable exception) {
    return exception instanceof HttpMediaTypeNotAcceptableException ||
        exception instanceof HttpMediaTypeNotSupportedException ||
        exception instanceof HttpRequestMethodNotSupportedException ||
        exception instanceof MissingServletRequestParameterException ||
        exception instanceof MissingServletRequestPartException ||
        exception instanceof NoHandlerFoundException ||
        exception instanceof HttpMessageNotReadableException;
}
 
Example #25
Source File: DefaultHandlerExceptionResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void handleMissingServletRequestParameter() {
	MissingServletRequestParameterException ex = new MissingServletRequestParameterException("foo", "bar");
	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 bar parameter 'foo' is not present", response.getErrorMessage());
}
 
Example #26
Source File: BaseController.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
@ExceptionHandler({ServletRequestBindingException.class,
        HttpMediaTypeNotAcceptableException.class,
        HttpMediaTypeNotSupportedException.class,
        HttpMessageNotReadableException.class,
        HttpRequestMethodNotSupportedException.class,
        MissingServletRequestParameterException.class,
        MissingServletRequestPartException.class,
        TypeMismatchException.class
})
@ResponseBody
public ApiResponse ServletRequestBindingExHandler(Exception ex) {
    return createExResult(new ValidationException(ex));
}
 
Example #27
Source File: GlobalExceptionHandler.java    From dk-foundation with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExceptionHandler({MissingServletRequestParameterException.class})
public @ResponseBody
StandResponse exception(MissingServletRequestParameterException e, HttpServletResponse response) {
    logger.error("#######ERROR#######", e);
    StandResponse standResponse = new StandResponse();
    standResponse.setCode(StandResponse.ARGUMENT_MISSING);
    standResponse.setSuccess(false);
    standResponse.setMsg("缺少参数:" + e.getParameterName());
    return standResponse;
}
 
Example #28
Source File: GlobalExceptionHandler.java    From cola-cloud with MIT License 5 votes vote down vote up
@ResponseBody
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.OK)
public Result handleMissingServletRequestParameterException(
        MissingServletRequestParameterException e) {
    log.error(ErrorStatus.MISSING_ARGUMENT.getMessage() + ":" + e.getMessage());
    return failure(ErrorStatus.MISSING_ARGUMENT,e);
}
 
Example #29
Source File: GlobalHandlerExceptionResolver.java    From fast-family-master with Apache License 2.0 5 votes vote down vote up
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public Response handleMissingServletRequestParameterException(
        MissingServletRequestParameterException e) {
    logError("missingServletRequestParameterException", e.getMessage(), e);
    return Response
            .fail(400,
                    String.format("参数%s未传", e.getParameterName()));
}
 
Example #30
Source File: ExceptionAdviser.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@ResponseStatus(HttpStatus.OK)
@ExceptionHandler({
    MethodArgumentNotValidException.class,
    MissingServletRequestParameterException.class
})
public ResponseMessage<Object> inputArgumentException(Exception e) {
    return new ResponseMessage<>(ErrorCode.INVALID_ARGUMENT, e.getMessage(), null);
}