java.lang.IllegalArgumentException: No InputStream specified

Spring JIRA | Gena Makhomed | 3 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Yet another filter, and unit test failed with exception {noformat} 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) {noformat} Filter code fragment: {code} 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; } } // ... } {code} {{HttpRequestWrapper}} code fragment: {code} 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 } // ... } {code} 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}}.

    Spring JIRA | 3 years ago | Gena Makhomed
    java.lang.IllegalArgumentException: No InputStream specified
  2. 0

    Yet another filter, and unit test failed with exception {noformat} 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) {noformat} Filter code fragment: {code} 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; } } // ... } {code} {{HttpRequestWrapper}} code fragment: {code} 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 } // ... } {code} 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}}.

    Spring JIRA | 3 years ago | Gena Makhomed
    java.lang.IllegalArgumentException: No InputStream specified
  3. 0

    swagger-ui not working when deployed in servlet container

    GitHub | 8 months ago | sarnowski
    java.lang.IllegalArgumentException: No InputStream specified
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      No InputStream specified

      at org.springframework.util.Assert.notNull()
    2. Spring Core
      StreamUtils.copyToByteArray
      1. org.springframework.util.Assert.notNull(Assert.java:112)
      2. org.springframework.util.StreamUtils.copy(StreamUtils.java:118)
      3. org.springframework.util.StreamUtils.copyToByteArray(StreamUtils.java:56)
      3 frames
    3. com.pb.ivrcgate
      HttpDumperFilter.doFilterInternal
      1. com.pb.ivrcgate.util.filter.HttpRequestWrapper.<init>(HttpRequestWrapper.java:27)
      2. com.pb.ivrcgate.util.filter.HttpDumperFilter.doFilterInternal(HttpDumperFilter.java:25)
      2 frames
    4. Spring
      OncePerRequestFilter.doFilter
      1. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      1 frame
    5. Spring TestContext
      MockMvc.perform
      1. org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:137)
      2. org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:141)
      2 frames
    6. com.pb.ivrcgate
      GateControllerTest.badUri
      1. com.pb.ivrcgate.controller.GateControllerTest.badUri(GateControllerTest.java:40)
      1 frame