Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@jakarta.apache.org Received: (qmail 71701 invoked by uid 500); 1 Oct 2001 17:32:53 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: tomcat-dev@jakarta.apache.org Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 71618 invoked from network); 1 Oct 2001 17:32:53 -0000 Date: 1 Oct 2001 17:32:56 -0000 Message-ID: <20011001173256.6327.qmail@nagoya.betaversion.org> From: bugzilla@apache.org To: tomcat-dev@jakarta.apache.org Cc: Subject: DO NOT REPLY [Bug 3905] New: - request.getIntputStream()/Reader.close() problem. X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT . ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3905 request.getIntputStream()/Reader.close() problem. Summary: request.getIntputStream()/Reader.close() problem. Product: Tomcat 3 Version: 3.3 Release Candidate 1 Platform: Other OS/Version: Linux Status: NEW Severity: Normal Priority: Other Component: Servlet AssignedTo: tomcat-dev@jakarta.apache.org ReportedBy: tom@58k.com In trying to write code that sends an xml packet to a servlet in the content of the request, it appears that the tomcat server is not handling the getInputStream() code correctly. What seems to happen is that the first close on the handle of the input stream - closes the stream permanently. This means that the same exact request repeated 20 times will work the first time, but not the second or any futher beyond the first request. This problem shows up both in 3.3 m4 and 3.3 rc1. The message that shows up the second time is "stream closed" My code on the servlet side looks like: public class processjdist { public String contents =""; public processjdist() { } public init(HttpServletRequest req, HttpServletResponse resp) { out = resp.getOutputStream(); try { if (req.getContentLength() > 0) { Reader r = req.getInputStream(); BufferedReader bufReader = new BufferedReader(r); /// PROBLEM SHOWS UP HERE!!! Second time code is called /// on the server /// error is "Stream closed" while ((line = bufReader.readLine()) != null) { contents += line; } r.close(); } } catch (IOException ioe) { } } public doPost(HttpServletRequest req, HttpServletResponse resp) { init(req,resp); } } The client side looks like public class jdistclient { StringBuffer outputBuffer = new StringBuffer(); public jdistclient() { String urlString ="http://www.netmech.com/customer/apprequest/get"; outputBuffer.append("foo"); try { log.debug("fetch from urlFetch"); // Send request to web server. URL appreq = new URL(urlString); URLConnection c = appreq.openConnection(); log.debug("fetch 1"); c.setDoOutput(true); c.setDoInput(true); //c.setDoInput(true); DataOutputStream dout = new DataOutputStream(c.getOutputStream()); log.debug("fetch 1.5"); log.debug("fetch 2"); dout.writeBytes(outputbuffer.toString()); log.debug("fetch 3"); dout.close(); InputStream is = c.getInputStream(); log.debug("fetch 3.1"); log.debug("fetch 3.1.5"); InputStreamReader r = new InputStreamReader(is); log.debug("fetch 3.2"); BufferedReader in = new BufferedReader(r); log.debug("fetch 3.5"); String inputLine; log.debug("fetch 4"); while ((inputLine = in.readLine()) != null) { log.debug(inputLine); buffer.append(inputLine); buffer.append("\n"); } is.close(); in.close(); log.debug("fetch 5"); } catch (IOException ioe) { log.error("Error:"+ioe.getMessage()); String s = ioe.getMessage(); System.out.println("Error:"+s); System.out.println(ioe.getLocalizedMessage()); System.out.println(ioe.toString()); } } public static void main(String [] args) { for (int i=0; i < 20; i++) { jdistclient j = new jdistclient(); } } }