committed by
Oleg Zhurakousky
parent
3930cad5df
commit
5f767f65e0
@@ -77,6 +77,7 @@ public class ServerlessHttpServletRequest implements HttpServletRequest {
|
|||||||
|
|
||||||
private static final BufferedReader EMPTY_BUFFERED_READER = new BufferedReader(new StringReader(""));
|
private static final BufferedReader EMPTY_BUFFERED_READER = new BufferedReader(new StringReader(""));
|
||||||
|
|
||||||
|
private static final InputStream EMPTY_INPUT_STREAM = new ByteArrayInputStream(new byte[0]);
|
||||||
/**
|
/**
|
||||||
* Date formats as specified in the HTTP RFC.
|
* Date formats as specified in the HTTP RFC.
|
||||||
*
|
*
|
||||||
@@ -283,7 +284,15 @@ public class ServerlessHttpServletRequest implements HttpServletRequest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServletInputStream getInputStream() {
|
public ServletInputStream getInputStream() {
|
||||||
InputStream stream = new ByteArrayInputStream(this.content);
|
|
||||||
|
InputStream stream;
|
||||||
|
if (this.content == null) {
|
||||||
|
stream = EMPTY_INPUT_STREAM;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
stream = new ByteArrayInputStream(this.content);
|
||||||
|
}
|
||||||
|
|
||||||
return new ServletInputStream() {
|
return new ServletInputStream() {
|
||||||
|
|
||||||
boolean finished = false;
|
boolean finished = false;
|
||||||
|
|||||||
@@ -149,6 +149,21 @@ public class RequestResponseTests {
|
|||||||
assertThat(pet.getName()).isNotEmpty();
|
assertThat(pet.getName()).isNotEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validatePostWithoutBody() throws Exception {
|
||||||
|
ServerlessHttpServletRequest request = new ServerlessHttpServletRequest(null, "POST", "/pets/");
|
||||||
|
request.setContentType("application/json");
|
||||||
|
ServerlessHttpServletResponse response = new ServerlessHttpServletResponse();
|
||||||
|
try {
|
||||||
|
mvc.service(request, response);
|
||||||
|
}
|
||||||
|
catch (jakarta.servlet.ServletException e) {
|
||||||
|
assertThat(e.getCause()).isNotInstanceOf(NullPointerException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(response.getStatus()).isEqualTo(400); // application fail because the pet is empty ;)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validatePostAsyncWithBody() throws Exception {
|
public void validatePostAsyncWithBody() throws Exception {
|
||||||
// System.setProperty("spring.main.banner-mode", "off");
|
// System.setProperty("spring.main.banner-mode", "off");
|
||||||
|
|||||||
Reference in New Issue
Block a user