Mark, I tried just writing to the PrintWriter. I do not see the chunking in the response. Can you spot any obvious mistake here?
private HttpServletResponse connection; // Set in constructor PrintWriter writer = connection.getWriter(); for (int j = 0; j < pendingEvents.length; j++) { String eventString = converter.convert(pendingEvents[j]); eventString = eventString + "\r\n"; writer.print(eventString); writer.flush(); } Thanks, Sudeep -----Original Message----- From: Mark Thomas [mailto:ma...@apache.org] Sent: Monday, July 25, 2011 12:37 PM To: Tomcat Users List Subject: Re: Comet: How to send *Chunked* response On 25/07/2011 19:23, Sudeep Pradhan wrote: > Hi, > > I am using CometProcessor to stream event notifications from server to > client. The events are generated at random. I want to send the notification > with Transfer Encoding as chunked so that I can use Apache's > ChunkedInputStream to parse the output. > > I get the PrintWriter from the ServletResponse using the getWriter() and I > write the event notification on this writer. I want this to be in chunk > format of length-payload. Currently I do the following: > > PrintWriter writer = connection.getWriter(); > for (int j = 0; j < pendingEvents.length; j++) { > String eventString = > converter.convert(pendingEvents[j]); > eventString.concat("\r\n"); > final String length = > Integer.toHexString(eventString.length()); > writer.print("\r\n" + length + "\r\n"); > writer.print(eventString); > //logger.info("Writing:" + eventString); > } > > But this generates a Bad Chunk size exception on client. Just write and flush the content. Tomcat will handle the chunking for you. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org