tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filip Hanik - Dev Lists <devli...@hanik.com>
Subject Re: reading POST body fails on 6.0.16, works on 6.0.14
Date Thu, 26 Jun 2008 18:03:27 GMT
yes, its a bug, and will be fixed in 6.0.17, I think its bug 44494

https://issues.apache.org/bugzilla/show_bug.cgi?id=44494

Filip

John Cartwright wrote:
> Hello All,
>
> I have a very simple doPost method that reads the body of a POST 
> request.  Seems to work fine on 6.0.14 but consistently fails to read 
> the body correctly in 6.0.16.  Can someone help me with what's wrong 
> here?
>
> Thanks!
>
> -- john
>
>  protected void doPost(HttpServletRequest request,
>         HttpServletResponse response) throws ServletException, 
> IOException {
>
>      // read POST body
>      StringBuffer sb = new StringBuffer();
>      try {
>         BufferedReader reader = request.getReader();
>         String inputLine;
>         while ((inputLine = reader.readLine()) != null) {
>            sb.append(inputLine);
>         }
>      } catch (IOException e) {
>         throw new IllegalStateException("Error reading request body");
>      }
>      String content = sb.toString();
>      log.debug("read "+content.length()+" characters from POST body");
>      if (content.length() != request.getContentLength()) {
>         log.warn("Expected content length of 
> "+request.getContentLength()+" but only read "+content.length()+" 
> characters");
>      }
>          //write out read content to file
>      PrintStream os = new PrintStream(new 
> FileOutputStream("/tmp/post_body.txt"));
>      os.println(content);
>      os.close();
>
>      PrintWriter out = response.getWriter();
>      response.setContentType("text/plain");
>      out.println("Content Type: " + request.getContentType());
>      out.println("POST body contained " + request.getContentLength() + 
> " characters");
>      out.println("read " + content.length() + " characters from POST 
> body");
>      out.flush();
>      out.close();
>   }
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message