Search in sources :

Example 1 with MissingRequestParameterException

use of cn.taketoday.web.bind.MissingRequestParameterException in project today-framework by TAKETODAY.

the class ResponseEntityExceptionHandlerTests method missingServletRequestParameter.

@Test
public void missingServletRequestParameter() {
    Exception ex = new MissingRequestParameterException("param", "type");
    testException(ex);
}
Also used : MissingRequestParameterException(cn.taketoday.web.bind.MissingRequestParameterException) MissingRequestPartException(cn.taketoday.web.bind.resolver.MissingRequestPartException) MissingPathVariableException(cn.taketoday.web.bind.MissingPathVariableException) ServletException(jakarta.servlet.ServletException) HttpRequestMethodNotSupportedException(cn.taketoday.web.HttpRequestMethodNotSupportedException) MissingRequestParameterException(cn.taketoday.web.bind.MissingRequestParameterException) RequestBindingException(cn.taketoday.web.bind.RequestBindingException) ConversionNotSupportedException(cn.taketoday.beans.ConversionNotSupportedException) HttpMessageNotReadableException(cn.taketoday.http.converter.HttpMessageNotReadableException) TypeMismatchException(cn.taketoday.beans.TypeMismatchException) HttpMediaTypeNotSupportedException(cn.taketoday.web.HttpMediaTypeNotSupportedException) HttpMediaTypeNotAcceptableException(cn.taketoday.web.HttpMediaTypeNotAcceptableException) BindException(cn.taketoday.validation.BindException) AsyncRequestTimeoutException(cn.taketoday.web.context.async.AsyncRequestTimeoutException) HttpMessageNotWritableException(cn.taketoday.http.converter.HttpMessageNotWritableException) MethodArgumentNotValidException(cn.taketoday.web.bind.MethodArgumentNotValidException) Test(org.junit.jupiter.api.Test)

Example 2 with MissingRequestParameterException

use of cn.taketoday.web.bind.MissingRequestParameterException in project today-framework by TAKETODAY.

the class ErrorPageFilterTests method nestedServletExceptionWithNoCause.

@Test
void nestedServletExceptionWithNoCause() throws Exception {
    this.filter.addErrorPages(new ErrorPage(MissingRequestParameterException.class, "/500"));
    this.chain = new TestFilterChain((request, response, chain) -> {
        chain.call();
        throw new MissingRequestParameterException("test", "string");
    });
    this.filter.doFilter(this.request, this.response, this.chain);
    assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()).isEqualTo(500);
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE)).isEqualTo(500);
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE)).isEqualTo("Required request parameter 'test' for method parameter type string is not present");
    Map<String, Object> requestAttributes = getAttributesForDispatch("/500");
    assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isEqualTo(MissingRequestParameterException.class);
    assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION)).isInstanceOf(MissingRequestParameterException.class);
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isNull();
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)).isNull();
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)).isEqualTo("/test/path");
    assertThat(this.response.isCommitted()).isTrue();
    assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
}
Also used : MockFilterConfig(cn.taketoday.mock.web.MockFilterConfig) RequestDispatcher(jakarta.servlet.RequestDispatcher) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Enumeration(java.util.Enumeration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) MockRequestDispatcher(cn.taketoday.mock.web.MockRequestDispatcher) ClientAbortException(org.apache.catalina.connector.ClientAbortException) DeferredResult(cn.taketoday.web.context.async.DeferredResult) ServletException(jakarta.servlet.ServletException) MockFilterChain(cn.taketoday.mock.web.MockFilterChain) OutputCaptureExtension(cn.taketoday.framework.test.system.OutputCaptureExtension) MockHttpServletRequest(cn.taketoday.mock.web.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) ErrorPageFilter(cn.taketoday.framework.web.servlet.support.ErrorPageFilter) NestedServletException(cn.taketoday.web.servlet.NestedServletException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BDDMockito.given(org.mockito.BDDMockito.given) MissingRequestParameterException(cn.taketoday.web.bind.MissingRequestParameterException) Map(java.util.Map) WebAsyncManager(cn.taketoday.web.context.async.WebAsyncManager) WebAsyncUtils(cn.taketoday.web.context.async.WebAsyncUtils) ServletRequest(jakarta.servlet.ServletRequest) BDDMockito.then(org.mockito.BDDMockito.then) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) ErrorPage(cn.taketoday.framework.web.server.ErrorPage) HttpServletResponseWrapper(jakarta.servlet.http.HttpServletResponseWrapper) Mockito.never(org.mockito.Mockito.never) StandardServletAsyncWebRequest(cn.taketoday.web.context.async.StandardServletAsyncWebRequest) ServletResponse(jakarta.servlet.ServletResponse) CapturedOutput(cn.taketoday.framework.test.system.CapturedOutput) HttpStatus(cn.taketoday.http.HttpStatus) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) MockHttpServletResponse(cn.taketoday.mock.web.MockHttpServletResponse) Mockito.mock(org.mockito.Mockito.mock) ErrorPage(cn.taketoday.framework.web.server.ErrorPage) MissingRequestParameterException(cn.taketoday.web.bind.MissingRequestParameterException) HttpServletResponseWrapper(jakarta.servlet.http.HttpServletResponseWrapper) Test(org.junit.jupiter.api.Test)

Example 3 with MissingRequestParameterException

use of cn.taketoday.web.bind.MissingRequestParameterException in project today-infrastructure by TAKETODAY.

the class ErrorPageFilterTests method nestedServletExceptionWithNoCause.

@Test
void nestedServletExceptionWithNoCause() throws Exception {
    this.filter.addErrorPages(new ErrorPage(MissingRequestParameterException.class, "/500"));
    this.chain = new TestFilterChain((request, response, chain) -> {
        chain.call();
        throw new MissingRequestParameterException("test", "string");
    });
    this.filter.doFilter(this.request, this.response, this.chain);
    assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()).isEqualTo(500);
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE)).isEqualTo(500);
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE)).isEqualTo("Required request parameter 'test' for method parameter type string is not present");
    Map<String, Object> requestAttributes = getAttributesForDispatch("/500");
    assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isEqualTo(MissingRequestParameterException.class);
    assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION)).isInstanceOf(MissingRequestParameterException.class);
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isNull();
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)).isNull();
    assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)).isEqualTo("/test/path");
    assertThat(this.response.isCommitted()).isTrue();
    assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
}
Also used : MockFilterConfig(cn.taketoday.mock.web.MockFilterConfig) RequestDispatcher(jakarta.servlet.RequestDispatcher) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Enumeration(java.util.Enumeration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) MockRequestDispatcher(cn.taketoday.mock.web.MockRequestDispatcher) ClientAbortException(org.apache.catalina.connector.ClientAbortException) DeferredResult(cn.taketoday.web.context.async.DeferredResult) ServletException(jakarta.servlet.ServletException) MockFilterChain(cn.taketoday.mock.web.MockFilterChain) OutputCaptureExtension(cn.taketoday.framework.test.system.OutputCaptureExtension) MockHttpServletRequest(cn.taketoday.mock.web.MockHttpServletRequest) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) ErrorPageFilter(cn.taketoday.framework.web.servlet.support.ErrorPageFilter) NestedServletException(cn.taketoday.web.servlet.NestedServletException) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BDDMockito.given(org.mockito.BDDMockito.given) MissingRequestParameterException(cn.taketoday.web.bind.MissingRequestParameterException) Map(java.util.Map) WebAsyncManager(cn.taketoday.web.context.async.WebAsyncManager) WebAsyncUtils(cn.taketoday.web.context.async.WebAsyncUtils) ServletRequest(jakarta.servlet.ServletRequest) BDDMockito.then(org.mockito.BDDMockito.then) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) ErrorPage(cn.taketoday.framework.web.server.ErrorPage) HttpServletResponseWrapper(jakarta.servlet.http.HttpServletResponseWrapper) Mockito.never(org.mockito.Mockito.never) StandardServletAsyncWebRequest(cn.taketoday.web.context.async.StandardServletAsyncWebRequest) ServletResponse(jakarta.servlet.ServletResponse) CapturedOutput(cn.taketoday.framework.test.system.CapturedOutput) HttpStatus(cn.taketoday.http.HttpStatus) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) MockHttpServletResponse(cn.taketoday.mock.web.MockHttpServletResponse) Mockito.mock(org.mockito.Mockito.mock) ErrorPage(cn.taketoday.framework.web.server.ErrorPage) MissingRequestParameterException(cn.taketoday.web.bind.MissingRequestParameterException) HttpServletResponseWrapper(jakarta.servlet.http.HttpServletResponseWrapper) Test(org.junit.jupiter.api.Test)

Aggregations

MissingRequestParameterException (cn.taketoday.web.bind.MissingRequestParameterException)3 ServletException (jakarta.servlet.ServletException)3 Test (org.junit.jupiter.api.Test)3 CapturedOutput (cn.taketoday.framework.test.system.CapturedOutput)2 OutputCaptureExtension (cn.taketoday.framework.test.system.OutputCaptureExtension)2 ErrorPage (cn.taketoday.framework.web.server.ErrorPage)2 ErrorPageFilter (cn.taketoday.framework.web.servlet.support.ErrorPageFilter)2 HttpStatus (cn.taketoday.http.HttpStatus)2 MockFilterChain (cn.taketoday.mock.web.MockFilterChain)2 MockFilterConfig (cn.taketoday.mock.web.MockFilterConfig)2 MockHttpServletRequest (cn.taketoday.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (cn.taketoday.mock.web.MockHttpServletResponse)2 MockRequestDispatcher (cn.taketoday.mock.web.MockRequestDispatcher)2 DeferredResult (cn.taketoday.web.context.async.DeferredResult)2 StandardServletAsyncWebRequest (cn.taketoday.web.context.async.StandardServletAsyncWebRequest)2 WebAsyncManager (cn.taketoday.web.context.async.WebAsyncManager)2 WebAsyncUtils (cn.taketoday.web.context.async.WebAsyncUtils)2 NestedServletException (cn.taketoday.web.servlet.NestedServletException)2 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)2 RequestDispatcher (jakarta.servlet.RequestDispatcher)2