|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
43 | 43 | import org.springframework.mock.web.MockHttpServletRequest;
|
44 | 44 | import org.springframework.mock.web.MockHttpServletResponse;
|
45 | 45 | import org.springframework.mock.web.MockRequestDispatcher;
|
| 46 | +import org.springframework.web.bind.MissingServletRequestParameterException; |
46 | 47 | import org.springframework.web.context.request.async.DeferredResult;
|
47 | 48 | import org.springframework.web.context.request.async.StandardServletAsyncWebRequest;
|
48 | 49 | import org.springframework.web.context.request.async.WebAsyncManager;
|
@@ -387,6 +388,30 @@ void nestedServletExceptionIsUnwrapped() throws Exception {
|
387 | 388 | assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
|
388 | 389 | }
|
389 | 390 |
|
| 391 | + @Test |
| 392 | + void nestedServletExceptionWithNoCause() throws Exception { |
| 393 | + this.filter.addErrorPages(new ErrorPage(MissingServletRequestParameterException.class, "/500")); |
| 394 | + this.chain = new TestFilterChain((request, response, chain) -> { |
| 395 | + chain.call(); |
| 396 | + throw new MissingServletRequestParameterException("test", "string"); |
| 397 | + }); |
| 398 | + this.filter.doFilter(this.request, this.response, this.chain); |
| 399 | + assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()).isEqualTo(500); |
| 400 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE)).isEqualTo(500); |
| 401 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE)) |
| 402 | + .isEqualTo("Required string parameter 'test' is not present"); |
| 403 | + Map<String, Object> requestAttributes = getAttributesForDispatch("/500"); |
| 404 | + assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION_TYPE)) |
| 405 | + .isEqualTo(MissingServletRequestParameterException.class); |
| 406 | + assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION)) |
| 407 | + .isInstanceOf(MissingServletRequestParameterException.class); |
| 408 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isNull(); |
| 409 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)).isNull(); |
| 410 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)).isEqualTo("/test/path"); |
| 411 | + assertThat(this.response.isCommitted()).isTrue(); |
| 412 | + assertThat(this.response.getForwardedUrl()).isEqualTo("/500"); |
| 413 | + } |
| 414 | + |
390 | 415 | @Test
|
391 | 416 | void whenErrorIsSentAndWriterIsFlushedErrorIsSentToTheClient() throws Exception {
|
392 | 417 | this.chain = new TestFilterChain((request, response, chain) -> {
|
|
0 commit comments