Refinements related to a committed response

1. setComplete checks the isCommitted flag to avoid an unnecessary
debug message. This method is meant to be safe to call many times.

2. setStatusCode lowers log message to TRACE, since the return value
communicates the outcome it's arguably much less critical.

3. Add comment and test case for ResponseStatusExceptionHandler.
A ResponseStatusException is clearly meant to be handled by this
handler so don't let it pass through even if the respones is
committed.

Issue: SPR-16231
This commit is contained in:
Rossen Stoyanchev
2017-11-27 16:31:49 -05:00
parent e30f1fbe89
commit dc3d834026
3 changed files with 18 additions and 8 deletions

View File

@@ -32,7 +32,6 @@ import static org.junit.Assert.assertSame;
/**
* Unit tests for {@link ResponseStatusExceptionHandler}.
*
* @author Rossen Stoyanchev
*/
public class ResponseStatusExceptionHandlerTests {
@@ -56,4 +55,14 @@ public class ResponseStatusExceptionHandlerTests {
StepVerifier.create(mono).consumeErrorWith(actual -> assertSame(expected, actual)).verify();
}
@Test // SPR-16231
public void responseCommitted() throws Exception {
Throwable ex = new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Oops");
this.exchange.getResponse().setStatusCode(HttpStatus.CREATED);
this.exchange.getResponse().setComplete()
.then(this.handler.handle(this.exchange, ex))
.block(Duration.ofSeconds(5));
assertEquals(HttpStatus.CREATED, this.exchange.getResponse().getStatusCode());
}
}