|
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.
|
|
42 | 42 | import org.springframework.mock.web.MockHttpServletRequest;
|
43 | 43 | import org.springframework.mock.web.MockHttpServletResponse;
|
44 | 44 | import org.springframework.mock.web.MockRequestDispatcher;
|
| 45 | +import org.springframework.web.bind.MissingServletRequestParameterException; |
45 | 46 | import org.springframework.web.context.request.async.DeferredResult;
|
46 | 47 | import org.springframework.web.context.request.async.StandardServletAsyncWebRequest;
|
47 | 48 | import org.springframework.web.context.request.async.WebAsyncManager;
|
@@ -388,6 +389,30 @@ public void nestedServletExceptionIsUnwrapped() throws Exception {
|
388 | 389 | assertThat(this.response.getForwardedUrl()).isEqualTo("/500");
|
389 | 390 | }
|
390 | 391 |
|
| 392 | + @Test |
| 393 | + public void nestedServletExceptionWithNoCause() throws Exception { |
| 394 | + this.filter.addErrorPages(new ErrorPage(MissingServletRequestParameterException.class, "/500")); |
| 395 | + this.chain = new TestFilterChain((request, response, chain) -> { |
| 396 | + chain.call(); |
| 397 | + throw new MissingServletRequestParameterException("test", "string"); |
| 398 | + }); |
| 399 | + this.filter.doFilter(this.request, this.response, this.chain); |
| 400 | + assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus()).isEqualTo(500); |
| 401 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE)).isEqualTo(500); |
| 402 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_MESSAGE)) |
| 403 | + .isEqualTo("Required string parameter 'test' is not present"); |
| 404 | + Map<String, Object> requestAttributes = getAttributesForDispatch("/500"); |
| 405 | + assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION_TYPE)) |
| 406 | + .isEqualTo(MissingServletRequestParameterException.class); |
| 407 | + assertThat(requestAttributes.get(RequestDispatcher.ERROR_EXCEPTION)) |
| 408 | + .isInstanceOf(MissingServletRequestParameterException.class); |
| 409 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE)).isNull(); |
| 410 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)).isNull(); |
| 411 | + assertThat(this.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)).isEqualTo("/test/path"); |
| 412 | + assertThat(this.response.isCommitted()).isTrue(); |
| 413 | + assertThat(this.response.getForwardedUrl()).isEqualTo("/500"); |
| 414 | + } |
| 415 | + |
391 | 416 | @Test
|
392 | 417 | public void whenErrorIsSentAndWriterIsFlushedErrorIsSentToTheClient() throws Exception {
|
393 | 418 | this.chain = new TestFilterChain((request, response, chain) -> {
|
|
0 commit comments