Spring Boot 2.1.0: Cannot call getReader() after getInputStream()
I'm facing a similar issue to the guy here: https://stackoverflow.com/questions/53818075/mockmvc-error-when-validating-resultmatcher-for-swagger-2-on-spring-boot-2-1-0
While trying to migrate Spring Boot from 2.0.6 to 2.1.2 a lot of tests fail with
java.lang.IllegalStateException: Cannot call getReader() after getInputStream() has already been called for the current request
at org.springframework.mock.web.MockHttpServletRequest.getReader(MockHttpServletRequest.java:716)
at com.atlassian.oai.validator.mockmvc.MockMvcRequest.getReader(MockMvcRequest.java:119)
at com.atlassian.oai.validator.mockmvc.MockMvcRequest.getBody(MockMvcRequest.java:100)
at com.atlassian.oai.validator.mockmvc.MockMvcRequest.of(MockMvcRequest.java:91)
at com.atlassian.oai.validator.mockmvc.OpenApiMatchers.lambda$isValid$0(OpenApiMatchers.java:56)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:195)
BTW Some tests still pass, so it seems to depend on whether something within Spring has called getInputStream() or not.
Comments (4)
-
-
Account Deactivated reporter Well, it seems to have the same root cause as
#181, however this one is essentially preventing anybody who is using the library to migrate to newer version of Spring Boot, which the other one is about supportingRestAssuredMockMvc
-
- changed status to resolved
The PR for
#181(https://bitbucket.org/atlassian/swagger-request-validator/pull-requests/121/issue-181/diff) should fix the issue.Available in
v2.2.0
Note that if you are using Spring Boot < 2.1 (Spring < 5.1) you will need to change your dependency to
swagger-request-validator-spring-mockmvc-legacy
.If the problem persists please feel free to re-open the issue.
-
Account Deactivated reporter @jnavin Thanks a lot! Switching to 2.2.1 has indeed allowed me to migrate to Spring Boot 2.1
As a side note, a few of my tests ran into: https://github.com/spring-projects/spring-framework/blob/master/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java#L455 So I had to set
characterEncoding
on those requests. - Log in to comment
Isn't this the same problem as in:
#181