title: As a body HttpServletRequest always returns CoyoteInputStream and not actual body
body: <p>I'm trying to write a method that checks user credentials and if these are correct parses sent JSON. It is working fine but I cannot access JSON. In my code there is a command <code>InputStream inputStream = request.getInputStream();</code> that should read JSON but every time it returns <code>org.apache.catalina.connector.CoyoteInputStream@3f1e9348</code>. Please have a look at my code:</p>
  
  <pre><code>@POST
  @Path("auth")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.TEXT_HTML)
  public String controller(@Context HttpServletRequest request) {
  
  
      String authorization = request.getHeader("Authorization");
      if (authorization == null) {
          authorization = request.getHeader("authorization");
      }
  
      String basicHeader = "basic";
      if (authorization != null &amp;&amp; authorization.toLowerCase().startsWith(basicHeader)) {
          String base64Credentials = authorization.substring(basicHeader.length()).trim();
          String credentials = new String(Base64.getDecoder().decode(base64Credentials),
                  Charset.forName("UTF-8"));
          String[] values = credentials.split(":", 2);
      }
  
      try {
          InputStream inputStream = request.getInputStream();
          System.out.println(inputStream);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>When I try to use <code>request.getReader()</code> I get the infamous <code>IllegalStateException: getInputStream() has already been called for this request</code> exception. Please see the relevant piece of code:</p>
  
  <pre><code>if ("POST".equalsIgnoreCase(request.getMethod()))
          {
              try {
                  String req = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  </code></pre>
  
  <p>I use curl to send <code>POST</code>:</p>
  
  <pre><code>curl -u myusername:mypasswor -H "Content-Type: application/json"
  -X POST -d '{"username":"xyz","password":"xyz"}' localhost
  </code></pre>