Search in sources :

Example 1 with MissingServletRequestParameterException

use of org.springframework.web.bind.MissingServletRequestParameterException in project spring-framework by spring-projects.

the class ResponseEntityExceptionHandlerTests method missingServletRequestParameter.

@Test
public void missingServletRequestParameter() {
    Exception ex = new MissingServletRequestParameterException("param", "type");
    testException(ex);
}
Also used : MissingServletRequestParameterException(org.springframework.web.bind.MissingServletRequestParameterException) MissingPathVariableException(org.springframework.web.bind.MissingPathVariableException) HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) NoHandlerFoundException(org.springframework.web.servlet.NoHandlerFoundException) MissingServletRequestPartException(org.springframework.web.multipart.support.MissingServletRequestPartException) BindException(org.springframework.validation.BindException) ConversionNotSupportedException(org.springframework.beans.ConversionNotSupportedException) AsyncRequestTimeoutException(org.springframework.web.context.request.async.AsyncRequestTimeoutException) MissingServletRequestParameterException(org.springframework.web.bind.MissingServletRequestParameterException) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException) TypeMismatchException(org.springframework.beans.TypeMismatchException) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) HttpMediaTypeNotSupportedException(org.springframework.web.HttpMediaTypeNotSupportedException) HttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException) HttpMediaTypeNotAcceptableException(org.springframework.web.HttpMediaTypeNotAcceptableException) Test(org.junit.Test)

Example 2 with MissingServletRequestParameterException

use of org.springframework.web.bind.MissingServletRequestParameterException in project disconf by knightliao.

the class MyExceptionHandler method resolveException.

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) {
    LOG.warn(request.getRequestURI() + " ExceptionHandler FOUND. " + e.toString() + "\t" + e.getCause());
    // PathVariable 出错
    if (e instanceof TypeMismatchException) {
        return getParamErrors((TypeMismatchException) e);
    // Bean 参数无法映射错误
    } else if (e instanceof InvalidPropertyException) {
        return getParamErrors((InvalidPropertyException) e);
    // @Valid 出错
    } else if (e instanceof BindException) {
        return ParamValidateUtils.getParamErrors((BindException) e);
    // 业务校验处理
    } else if (e instanceof FieldException) {
        return getParamErrors((FieldException) e);
    } else if (e instanceof DocumentNotFoundException) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        try {
            FileUtils.closeWriter(response.getWriter());
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return null;
    // 用户没有请求方法的访问权限
    } else if (e instanceof AccessDeniedException) {
        LOG.warn("details: " + ((AccessDeniedException) e).getErrorMessage());
        return buildError("auth.access.denied", ErrorCode.ACCESS_NOAUTH_ERROR);
    } else if (e instanceof HttpRequestMethodNotSupportedException) {
        return buildError("syserror.httpmethod", ErrorCode.HttpRequestMethodNotSupportedException);
    } else if (e instanceof MissingServletRequestParameterException) {
        return buildError("syserror.param.miss", ErrorCode.MissingServletRequestParameterException);
    } else if (e instanceof GlobalExceptionAware) {
        LOG.error("details: ", e);
        GlobalExceptionAware g = (GlobalExceptionAware) e;
        return buildError(g.getErrorMessage(), g.getErrorCode());
    } else {
        LOG.warn("details: ", e);
        return buildError("syserror.inner", ErrorCode.GLOBAL_ERROR);
    }
}
Also used : AccessDeniedException(com.baidu.dsp.common.exception.AccessDeniedException) FieldException(com.baidu.dsp.common.exception.FieldException) DocumentNotFoundException(com.baidu.dsp.common.exception.DocumentNotFoundException) GlobalExceptionAware(com.baidu.dsp.common.exception.base.GlobalExceptionAware) TypeMismatchException(org.springframework.beans.TypeMismatchException) InvalidPropertyException(org.springframework.beans.InvalidPropertyException) BindException(org.springframework.validation.BindException) IOException(java.io.IOException) MissingServletRequestParameterException(org.springframework.web.bind.MissingServletRequestParameterException) HttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException)

Example 3 with MissingServletRequestParameterException

use of org.springframework.web.bind.MissingServletRequestParameterException in project spring-framework by spring-projects.

the class DefaultHandlerExceptionResolverTests method handleMissingServletRequestParameter.

@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());
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) MissingServletRequestParameterException(org.springframework.web.bind.MissingServletRequestParameterException) Test(org.junit.Test)

Aggregations

MissingServletRequestParameterException (org.springframework.web.bind.MissingServletRequestParameterException)3 Test (org.junit.Test)2 TypeMismatchException (org.springframework.beans.TypeMismatchException)2 BindException (org.springframework.validation.BindException)2 HttpRequestMethodNotSupportedException (org.springframework.web.HttpRequestMethodNotSupportedException)2 AccessDeniedException (com.baidu.dsp.common.exception.AccessDeniedException)1 DocumentNotFoundException (com.baidu.dsp.common.exception.DocumentNotFoundException)1 FieldException (com.baidu.dsp.common.exception.FieldException)1 GlobalExceptionAware (com.baidu.dsp.common.exception.base.GlobalExceptionAware)1 IOException (java.io.IOException)1 ConversionNotSupportedException (org.springframework.beans.ConversionNotSupportedException)1 InvalidPropertyException (org.springframework.beans.InvalidPropertyException)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1 HttpMediaTypeNotAcceptableException (org.springframework.web.HttpMediaTypeNotAcceptableException)1 HttpMediaTypeNotSupportedException (org.springframework.web.HttpMediaTypeNotSupportedException)1 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)1 MissingPathVariableException (org.springframework.web.bind.MissingPathVariableException)1 ServletRequestBindingException (org.springframework.web.bind.ServletRequestBindingException)1 AsyncRequestTimeoutException (org.springframework.web.context.request.async.AsyncRequestTimeoutException)1