-
Couldn't load subscription status.
- Fork 38.8k
Closed
Labels
in: testIssues in the test moduleIssues in the test moduletype: enhancementA general enhancementA general enhancement
Milestone
Description
Gena Makhomed opened SPR-11764 and commented
Yet another filter, and unit test failed with exception
java.lang.IllegalArgumentException: No InputStream specified
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.util.StreamUtils.copy(StreamUtils.java:118)
at org.springframework.util.StreamUtils.copyToByteArray(StreamUtils.java:56)
at com.pb.ivrcgate.util.filter.HttpRequestWrapper.<init>(HttpRequestWrapper.java:27)
at com.pb.ivrcgate.util.filter.HttpDumperFilter.doFilterInternal(HttpDumperFilter.java:25)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:137)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:141)
at com.pb.ivrcgate.controller.GateControllerTest.badUri(GateControllerTest.java:40)
Filter code fragment:
public class HttpDumperFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
try {
HttpRequestWrapper request = new HttpRequestWrapper(httpServletRequest);
HttpResponseWrapper response = new HttpResponseWrapper(httpServletResponse);
filterChain.doFilter(request, response);
// ...
} catch (Exception ex) {
logger.error("", ex);
throw ex;
}
}
// ...
}
HttpRequestWrapper code fragment:
public class HttpRequestWrapper extends HttpServletRequestWrapper {
private final byte[] content;
public HttpRequestWrapper(HttpServletRequest request) throws IOException {
super(request);
this.content = StreamUtils.copyToByteArray(request.getInputStream()); // line #27
}
// ...
}
In compliance with Servlet API and documentation - MockMvc must return object of class ServletInputStream, and can't return null.
For example, tomcat return ServletInputStream object even for GET requests, and never return null from getInputStream() method.
Looks like this is bug in MockMvc.
Affects: 4.0.4
Issue Links:
- MockMvc ignores HTTP status code overridden by filter [SPR-11760] #16382 MockMvc ignores HTTP status code overridden by filter
- MockHttpServletRequest.getReader() returns null in case of no content [SPR-15215] #19780 MockHttpServletRequest.getReader() returns null in case of no content
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test moduletype: enhancementA general enhancementA general enhancement