Thanks a lot Olaf for the response. Yes , i have taken care of that condition
Please find the full code below protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String param = request.getParameter("size"); if (param != null) { int kByte = Integer.parseInt(param); response.setContentType("application/octet-stream"); long length = kByte * 1024; if (length <= Integer.MAX_VALUE) { response.setContentLength((int)length); } else { response.addHeader("Content-Length", Long.toString(length)); } // response.setContentLength(kByte * 1024); ServletOutputStream outputStream = response.getOutputStream(); byte[] buffer = new byte[1024]; Random random = new Random(System.currentTimeMillis()); while (size < kByte) { random.nextBytes(buffer); outputStream.write(buffer); size += 1; } outputStream.flush(); return; } }catch (Exception e) { e.printStackTrace(); response.sendError(500, e.getMessage()); return; } } On Wed, Mar 20, 2019 at 6:26 PM Olaf Kock <tom...@olafkock.de> wrote: > > > On 20.03.19 12:08, Saurav Sarkar wrote: > > Just to add the stack trace. > > > > I am getting ClientAbortException "Connection reset by peer" when i am > > trying to write to the response stream > > > > 2019-03-20T10:32:28.501+0000 [APP/PROC/WEB/0] ERR > > org.apache.catalina.connector.ClientAbortException: java.io.IOException: > > Connection reset by peer > > 2019-03-20T10:32:28.502+0000 [APP/PROC/WEB/0] ERR at > > > org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:364) > ... > > > > > On Wed, Mar 20, 2019 at 3:51 PM Saurav Sarkar <saurav.sark...@gmail.com> > > wrote: > > > >> Hi All > >> > >> I have a very basic test application which serves bytes from memory and > >> gives it back to the client. > >> > >> Whenever i try to send the request for byte size which is of over 2 GB i > >> get a connection reset error in my server code and a 502 error in my > chrome > >> console. Below 2 GB it is working fine. > >> > >> In my client side i execute java script which i execute from the > browser. > >> This basically executes an XMLHTTPRequest , gets the response (stores in > >> browser memory) and asks for a save. > >> > >> I would like to know if there Is there max response size default value > >> which is set in default tomcat configuration. ? or any other hints which > >> you can provide in my use. > >> > >> > >> Thanks and Regards, > >> > >> Saurav > >> > >> Below is the servlet or server side code > >> > >> > >> > >> response.setContentLength((int)length); > >> > >> } > >> > >> else > >> > >> { > >> > >> response.addHeader("Content-Length", Long.toString(length)); > >> > >> } > > You don't include the initial condition in your code, but I'm assuming > that the first line is hit: response.setContentLength((int)length); > > int in Java is defined to be 32 bit, and always signed. That means that > any value larger than 2^31 or Integer.MAX_VALUE can't be expressed in > int as a positive number. In fact, anything between 2^31 and 2^32 will > be interpreted as a negative number, so you're effectively setting the > content length to be negative. > > Note that there's also a setContentLengthLong method > > https://docs.oracle.com/javaee/7/api/javax/servlet/ServletResponse.html#setContentLengthLong-long- > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >